Add dedicated ERROR_RENAME / ERROR_MOVE keys + RENAME_ERROR / MOVE_ERROR codes (#308)#317
Merged
Merged
Conversation
…codes (#308) A rejected rename/move (`onUpdate` returning `false`) now surfaces an operation-specific message ("Rename unsuccessful" / "Move unsuccessful") and a matching `onError` code (`RENAME_ERROR` / `MOVE_ERROR`), giving these first-class events full parity with add/delete. Previously both reused the generic `ERROR_UPDATE` message and `UPDATE_ERROR` code, breaking the message↔code coherence the `handleEdit` comment promises. - types.ts: add RENAME_ERROR / MOVE_ERROR to the public JsonEditorErrorCode union - localisation.ts: add ERROR_RENAME / ERROR_MOVE message keys - JsonEditor.tsx: replace the errorKey ternary in handleEdit with an exhaustive ERROR_MESSAGE_KEY map (Record over the event union) - useCommon.ts / useDragNDrop.tsx: emit the new codes for rename / move - README.md: localisation table + onError code list - test: rename-reject regression test (message + code); move-reject as test.todo (#270) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bundle size impact
|
| Format | Base raw | PR raw | Δ raw | Base gzip | PR gzip | Δ gzip |
|---|---|---|---|---|---|---|
| esm | 54.70 KB | 54.78 KB | 🔺 +80 B (+0.14%) | 18.95 KB | 19.00 KB | 🔺 +49 B (+0.25%) |
| cjs | 56.18 KB | 56.26 KB | 🔺 +80 B (+0.14%) | 18.97 KB | 19.03 KB | 🔺 +53 B (+0.27%) |
Measured from build/index.{cjs,esm}.js. Gzip at level 9.
So users with a localised `translations` config know to add translations for the new rejected-rename/move messages (additive — untranslated keys fall back to the English defaults). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #308.
Context
PR #303 made
handleEditsurface an event-specific rejection message: a generic reject (onUpdatereturningfalse) on anadd/deleteshowsERROR_ADD/ERROR_DELETEinstead of the genericERROR_UPDATE. The stated invariant (comment inhandleEdit) is that the message is event-specific so it matches theonErrorcode the node routes it to.renameandmovebecame first-classonUpdateevents in #297 but were left out: they had no dedicated localisation key (a rejected rename/move showed "Update unsuccessful") and reused the genericUPDATE_ERRORcode.add/deletealready have both a dedicated message and code, so rename/move were the odd ones out.What this does
Gives rename/move full parity — dedicated messages and dedicated codes — restoring the message↔code coherence the
handleEditcomment promises.src/types.tsRENAME_ERROR/MOVE_ERRORto the publicJsonEditorErrorCodeunion (additive)src/localisation.tsERROR_RENAME: 'Rename unsuccessful'/ERROR_MOVE: 'Move unsuccessful'src/JsonEditor.tsxerrorKeyternary inhandleEditwith a module-scopeERROR_MESSAGE_KEYlookup typedRecord<UpdateFunctionProps['event'], keyof LocalisedStrings>— exhaustive over the event union so a future event can't silently fall throughsrc/hooks/useCommon.tsRENAME_ERRORsrc/hooks/useDragNDrop.tsxMOVE_ERRORREADME.mdonErrorcode listtest/JsonEditor.test.tsxRENAME_ERRORcode); move-reject astest.todo(DnD simulation deferred — #270)Naming decisions
<OP>_ERRORsuffix convention:RENAME_ERROR/MOVE_ERROR(consistent withADD_ERROR/DELETE_ERROR).ERROR_<OP>prefix convention:ERROR_RENAME/ERROR_MOVE(consistent withERROR_ADD/ERROR_DELETE).The two new codes are additive members of the public union — no internal exhaustive switch consumes it, so nothing breaks. A
minorchangeset is included.Verification
pnpm compile✅ — union extension typechecks,keyof LocalisedStringspicks up the new keys, no dead exportspnpm lint✅ cleanpnpm test✅ 295 passed + 3 todoUPDATE_ERRORinstead ofRENAME_ERROR), then restored and re-confirmed green🤖 Generated with Claude Code