feat(localize): leave the editor once the accepted boxes land - #385
Merged
Conversation
Confirming the editor's "Accept boxes" popover settles every remaining frame of the object, so there is nothing left to do on that screen — but the editor stayed open, and the annotator had to press Escape to get back to a cockpit that had already moved on without them. The confirm paths (Enter and the popover's own button) now hand the page a callback, and the page fires it from the mutation's onSuccess. Closing on the write rather than on the gesture is what keeps a failed accept where it belongs: the editor stays open with its error toast still about the object in front of you. The close runs through the editor's own requestClose, so it shrinks back into the grid cell exactly as Escape does. The rail's copy of the same popover passes no callback — there is no editor to close there — and is untouched.
Handing `requestClose` to the page made it reachable long after the gesture that armed it: the write can land once the annotator has already left by another door — browser Back, which keeps the cockpit page and its mutation mounted. The close then ran on an unmounted editor and navigated them back to it. `mountedRef` already guards the exit animation's own finish handler for the same reason; this takes it one step earlier, to the whole request.
…they accepted from
Two things review turned up in the accept-close wiring.
The close handed to the page was frozen at gesture time: `requestClose`
closes over the open frame, and nothing stops an ArrowRight while the
bulk upsert is in flight. The write would land and the editor shrink
into the cell of a frame already left — possibly one scrolled out of
view, so it flew off toward nothing. A ref resolves the callback to the
current close instead, the same trick `clearRef` uses to keep the
keyboard handler from re-binding.
And "stays put when the write never lands" tested nothing: the failure
semantics live in the page's `{ onSuccess }`, so an editor-level test
could only re-assert what the test above it already pins. Swapping that
for `onSettled` — which would close on a FAILED accept and bury the
error toast — left the whole suite green. The guard now sits where the
behavior does, in a page test that rejects the bulk write and asserts
the editor is still on screen; its sibling covers the success close.
Both were watched failing against that mutant first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Confirming the localize editor's Accept boxes popover — with
Enteror its own button — now closes the editor and returns to the object's cockpit page (/localize/:seq/object/:lane).Why
Accepting the remainder settles every frame of the object, so the editor has nothing left to show. It stayed open anyway, and the annotator had to press
Escapeto get back to a cockpit that had already moved on without them.How
LocalizeObjectEditor'sonAcceptRemainingtakes an optionalonAcceptedcallback; both confirm paths pass the editor's own close, so the exit runs the existing shrink-back-into-the-grid animation rather than a hard unmount.LocalizeAlertPagefires that callback from the quick-accept mutation'sonSuccess.Closing on the write rather than on the gesture is deliberate: a failed accept leaves the object unfinished, so the editor stays open with its "Failed to accept boxes" toast still about the object in front of you.
The rail's copy of the same popover passes no callback and is unchanged — there is no editor to close there.
Two holes the first commit opened, and their fixes
Handing a close to the page makes it callable long after the gesture that armed it. Two consequences, each its own commit:
mountedRefalready guards the exit animation's finish handler for this reason; the guard now sits on the whole request.requestClosecloses over the open frame, and nothing stops anArrowRightwhile the bulk upsert is in flight. The editor would shrink into the cell of a frame already left, possibly one scrolled out of view. A ref resolves the callback to the current close instead — the same trickclearRefuses to keep the keyboard handler from re-binding.Testing
Editor level:
Enter-confirm and click-confirm each close once the callback fires; a callback arriving after unmount does nothing; the close targets the frame the annotator is on rather than the one they accepted from.Page level (
LocalizeAlertPage.test.tsx, "accept popover → from the editor"): the editor closes to/localize/101/object/102once the write lands, and stays on screen with its failure toast when the bulk write rejects.That page pair exists because an earlier editor-level "stays put" test was vacuous — the failure semantics live in the page's
{ onSuccess }. Swapping it for{ onSettled }, which would close on a failed accept and bury the error toast, left the entire suite green. Both page tests were watched failing against that mutant before being kept; the redundant editor test is gone.Full frontend suite 1503/1503,
type-check,lintandformat:checkclean.Caveat: jsdom has no Web Animations API, so most editor tests exercise the non-animated fallback; the frame-targeting test drives the suite's existing WAAPI stub. The real animated close was verified by hand in the browser.