Skip to content

OpenConceptLab/ocl_issues#3008 | Convert resource-versioned references, showing what each conversion keeps - #111

Open
snyaggarwal wants to merge 4 commits into
mainfrom
issues-3008-convert-references-dialog
Open

snyaggarwal wants to merge 4 commits into
mainfrom
issues-3008-convert-references-dialog

Conversation

@snyaggarwal

@snyaggarwal snyaggarwal commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

The web half of OpenConceptLab/ocl_issues#3008 (epic OpenConceptLab/ocl_issues#2942). It uses the API from OpenConceptLab/oclapi2#1033, so it needs OpenConceptLab/oclapi2#1033 deployed first; until then the dialog's preview call fails and shows the error.

What it adds

A "Convert resource-versioned references" action in the references actions menu. It opens a new dialog (ConvertReferencesDialog):

  • Scope: the selected resource-versioned references, or every one in the collection ("*", fetched page by page).

  • Per reference: what it holds now, and, for each conversion (repo-versioned and unversioned):

    • the new expression;
    • whether it keeps today's members, or how many it adds and removes;
    • whether converting to unversioned would lock the collection to that version.

    References the API can't convert (a filter, a value set) are shown with the reason.

  • Choice per reference: repo-versioned, unversioned, or leave as is. It starts on a conversion that keeps the members, repo-versioned first.

  • Converting everything at once: when every reference keeps its members under one conversion, the dialog says so and offers to set them all to it (the ticket's "convert them all in one step").

  • Converting: one call to references/conversions/, which swaps them in HEAD in one transaction. An alert then says how many were converted and how many were left as they were. A queued run (202) says it's running in the background.

The existing "Transform to non-versioned reference" now leaves resource-versioned references to this dialog, marked "Use Convert resource-versioned references". Its client-side add-then-delete stays only for repo-versioned references.

Translations: en, es, pt-BR and zh, with 30 new keys each.

Checks

🤖 Generated with Claude Code

…s: a dialog shows what each conversion keeps and converts them server side

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 verdict: not ready to merge yet. One important finding and three nits on 3a99323. Fixes follow in this PR.

Checked against OpenConceptLab/oclapi2#1033's reference_conversions.py and views:

  • Request shapes:
    • preview takes {ids: [...]}, at most 500, or {ids: "*", offset}, paged by summary.next_offset;
    • convert takes {conversions: [{id, to}]}.
  • Response fields: supported, reason, members_count, and per conversion keeps_members, added_count, removed_count and creates_lock. The 202 from a queued task and converted, already_present, not_converted and rolled_back are handled too.
  • APIService: success checks response.status, and errors come back as error.response.data with detail shown when there is one.
  • i18n: all 30 keys are in en, es, pt-BR and zh, and those files change only by the new keys.
  • The old transform dialog: it now routes resource-versioned references here. Repo-versioned references still transform client side, with tests.
  • Reachability: the actions menu is disabled outside HEAD, so the dialog only ever works on HEAD, as the API does.
  • Open core: nothing commercial.

The important finding: the preview reloads, and resets the owner's choices, whenever Search re-renders (inline).

…selected ids, names its controls, says when there's nothing to convert, and stays open on a rollback
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

All four round 1 points are fixed in the latest commit.

  1. Preview reloads (important): the preview now loads by a key of the selected resource-versioned ids, sorted and joined (getResourceVersionedIds), not by the array Search passes each render. A re-render no longer reloads the preview or resets the owner's choices.
  2. Accessible names (nit): each row's Select is labelled "Conversion for ", and the scope toggle is labelled "References to convert".
  3. Empty preview (nit): when there's nothing to convert, an info alert says so.
  4. Rolled back (nit): when the API rolls the whole conversion back, the dialog stays open with the reason, built from the results' errors (getRollbackMessages, which reads each shape the add-references errors come in).

The four new keys are in en, es, pt-BR and zh. Three new tests cover the id key, telling a rollback apart, and the rollback messages, so 202 tests in all. They pass, ESLint is clean, and the production build compiles.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2 verdict: ready to merge once OpenConceptLab/oclapi2#1033 is deployed. No findings on f5f5202.

The four round 1 fixes check out:

  • Preview key: the preview loads by a sorted, joined key of the selected resource-versioned ids (getResourceVersionedIds). The effect depends on selectedKey, so a re-render of Search no longer reloads it or resets the choices.
  • Accessible names: each row's Select is labelled with its expression, and the scope toggle has a label.
  • Empty preview: an info alert shows when there's nothing to convert.
  • Rollback: a conversion that changed nothing because it was rolled back keeps the dialog open, with the API's messages from each shape of errors (a string, a list, or an object of description entries). Because the API's swap is all or nothing, changed === 0 && rolled_back > 0 is the right test.

I looked over the rest of the PR again and found nothing else:

  • the request and response shapes match #1033;
  • "*" pages until next_offset is null;
  • a 202 and errors are handled;
  • the four new keys are in all four locales;
  • the old transform routes resource-versioned references here.

CI ("Lint and test") passes. The dialog still hasn't run against live endpoints. That's for staging once #1033 is deployed there.

@snyaggarwal
snyaggarwal requested a review from paynejd November 23, 2026 13:07

@paynejd paynejd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at f5f5202. An independent defect pass (Codex, high effort), with every finding checked against the code and against oclapi2#1033's real response shapes.

Verdict: comment. Jon will look at the dialog in a browser once oclapi2#1033 is on staging. The default never picks a conversion the API says changes members, which is right.

Worth fixing

  1. A failed or empty preview keeps the last scope's choices. The load effect (ConvertReferencesDialog.jsx ~107-123) clears neither preview nor choices. After an error the old table stays under the alert. Going from All to Selected with nothing selected leaves "Convert N" enabled with no table. Suggestion inline: clear both at the start of every load.
  2. Queued conversions never report back. On 202, the dialog calls onConverted({queued: true}), and the task id is dropped. The synchronous wait is about 40 s, and the collections with the most pinned references will mostly queue. Keep the id and poll /tasks/<id>/ as useQueuedTasks does, then show the same outcome or rollback message.
  3. Show what each conversion keeps. repo_version, chosen_by, added and removed come back from the API but aren't shown (ConversionCell, ~48-70). Show the version under each expression. When a conversion doesn't keep members, list what it adds and removes (capped, with counts) in an expandable row. That's the ticket's "showing what each keeps".
  4. Exclusion rows look like inclusions. The API returns item.exclude, but the dialog ignores it. Please label those rows; the API fix is in oclapi2#1033, point 3. That PR's review also adds two reasons, "it has no system" and "it is an exclusion", so add them to REASON_KEYS.
  5. Once oclapi2#1033 accepts an expected repo_version, send the previewed one with each conversion.
  6. Default choice: unversioned first. Pre-select unversioned when it keeps the members; otherwise repo-versioned when it keeps them; otherwise leave the reference as it is. That's the order ocl_issues#2280 sets. When unversioned sets the collection's lock (creates_lock), keep the note that says so. Never pre-select a repo-versioned conversion the API reports with chosen_by: "HEAD": it names /S/HEAD/..., so its member moves with the next edit in HEAD. Offer it, labelled "follows HEAD". The "repo-versioned first" test in referenceConversionUtils.test.js changes with this.

Minor
7. When some references can't be converted, the "every reference keeps its members" banner overstates, and the final alert doesn't count them. Word it as "every reference that can be converted", and say how many couldn't be.

Comment on lines +108 to +111
if(!open || !collectionUrl || (scope === 'selected' && !selectedIds.length)) {
setPreview(null)
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point 1: every load starts from no preview and no choices, so a failed or empty load shows no old table and leaves Convert disabled.

Suggested change
if(!open || !collectionUrl || (scope === 'selected' && !selectedIds.length)) {
setPreview(null)
return
}
setPreview(null)
setChoices({})
if(!open || !collectionUrl || (scope === 'selected' && !selectedIds.length))
return

…sioned, shows each conversion's version and changes, follows queued conversions, and sends back the previewed version
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Thanks, Jon. All seven points are addressed in the latest commit.

  1. Failed or empty loads: every preview load now starts with no preview and no choices. A failed or empty load shows no old table and leaves Convert disabled.

  2. Queued conversions: on 202, the dialog keeps the task id and asks /tasks/<id>/?result=true every 3 s until the task ends. It then reports the outcome or the rollback, as a direct conversion does. Closing the dialog meanwhile leaves the conversion running, and the list says so.

  3. What each conversion keeps: each conversion shows the version it resolves to ("Resolves to …"). When it doesn't keep the members, a "Show changes" toggle lists what it adds and removes, capped with "and N more".

  4. Exclusions and reasons: exclusion rows are labelled "Exclusion". The two new API reasons ("it has no system", "it is an exclusion") are in REASON_KEYS, translated.

  5. The previewed version: each conversion now sends back the repo_version its preview showed. OpenConceptLab/ocl_issues#3008 | preview and convert resource-versioned references (API) oclapi2#1033 refuses it with "changed since the preview" if it now resolves elsewhere.

  6. The default:

    • unversioned when it keeps the members, with the lock note kept;
    • otherwise repo-versioned when it keeps them;
    • otherwise leave as is.

    A repo-versioned conversion that names HEAD (chosen_by: "HEAD") is never pre-selected, and it's offered labelled "Follows HEAD". The "repo-versioned first" test is replaced.

  7. Wording: the banners now say "every reference that can be converted" and add how many can't. The final alert counts them too.

New and changed keys are in en, es, pt-BR and zh. npm test passes, 205 tests; new ones cover the default order, HEAD-named conversions, the payload's previewed version, and reading a queued task's result. ESLint is clean and a production build compiles. The browser check waits for #1033 on staging, as you planned.

@paynejd paynejd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Sunny. Points 1 and 3 to 7 are met.

  • The default order matches the rule exactly.
  • The payload carries repo_version in the shape oclapi2#1033 compares.
  • Tests and lint pass.

Point 2 needs one line changed (suggestion inline). The poll asks /tasks/<id>/?result=true, and the API leaves result out unless it's json or all (TaskDetailSerializer.to_representation). On staging, result=true returns no result key, while verbose=true&result=all does. So every queued conversion ends with "The background conversion failed", successful or not. It also needs oclapi2#1033's fix, so that the result is JSON.

Smaller:

  • APIService never rejects, so a task that keeps returning 404 or 500 is polled every 3 seconds until the dialog closes. Stop after a few failures.
  • A {refusal} result shows the generic failure. Showing the refusal's message would tell the user why.
  • The not-converted reasons, such as "changed since the preview", are only counted, never shown.
  • The scope toggle stays enabled while converting.
  • See oclapi2#1033 on labelling an unversioned conversion that resolves to HEAD.

The browser check on staging follows once #1033 is there.

return
let active = true
let timer = null
const poll = () => APIService.new().overrideURL(`/tasks/${queuedTaskId}/`).get(null, null, { result: true }).then(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asks for the result: result=true leaves it out.

Suggested change
const poll = () => APIService.new().overrideURL(`/tasks/${queuedTaskId}/`).get(null, null, { result: true }).then(
// verbose with result=all returns the task's result; result=true leaves it out
const query = { verbose: true, result: 'all' }
const poll = () => APIService.new().overrideURL(`/tasks/${queuedTaskId}/`).get(null, null, query).then(

… its stored result, stops after repeated failures, shows refusals and why references were left, and labels HEAD targets
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Thanks, Jon. Your Nov 24 review is addressed in 157bb61.

  1. The poll's query (your inline suggestion): the poll now asks /tasks/<id>/ with { verbose: true, result: 'all' } (TASK_RESULT_QUERY), which returns the stored result. getQueuedConversion reads that shape: results, a refusal, or an error. Together with OpenConceptLab/ocl_issues#3008 | preview and convert resource-versioned references (API) oclapi2#1033's 12fa6a97, which stores the result as JSON, a queued conversion now reports its outcome.
  2. A task that keeps failing: since APIService never rejects, a response without a 200 counts as a failure. After 3 in a row, the dialog stops polling and says it couldn't get the conversion's status, so the user should refresh the list. A successful response resets the count.
  3. Refusals: a {refusal} result shows the refusal's own message (its detail, else its first message), not the generic failure.
  4. The not-converted reasons: after converting, the alert lists why references were left, each with how many it applies to. Examples are "changed since the preview", "the collection already has it with another cascade", "resolves to no version you can view", "no version holds its resource version" and "not in this collection". Each is translated where known, with the API's own text as the fallback.
  5. The scope toggle is disabled while converting.
  6. HEAD labels: "Follows HEAD" now comes from #1033's new follows_head flag, falling back to chosen_by: "HEAD". So an unversioned conversion into a source with no release is labelled too. As you said, an unversioned conversion that keeps the members stays the default even when it follows HEAD, and a repo-versioned one that follows HEAD is still never pre-selected.

New keys are in en, es, pt-BR and zh. npm test passes, 210 tests; new ones cover the HEAD flag, the default with a HEAD target, the task query, refusals and the reasons. ESLint is clean and a production build compiles.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants