Skip to content

Add dedicated ERROR_RENAME / ERROR_MOVE keys + RENAME_ERROR / MOVE_ERROR codes (#308)#317

Merged
CarlosNZ merged 3 commits into
v2.0-devfrom
feat/v2.0-error-rename-move-codes
Jun 3, 2026
Merged

Add dedicated ERROR_RENAME / ERROR_MOVE keys + RENAME_ERROR / MOVE_ERROR codes (#308)#317
CarlosNZ merged 3 commits into
v2.0-devfrom
feat/v2.0-error-rename-move-codes

Conversation

@CarlosNZ
Copy link
Copy Markdown
Owner

@CarlosNZ CarlosNZ commented Jun 3, 2026

Closes #308.

Context

PR #303 made handleEdit surface an event-specific rejection message: a generic reject (onUpdate returning false) on an add/delete shows ERROR_ADD / ERROR_DELETE instead of the generic ERROR_UPDATE. The stated invariant (comment in handleEdit) is that the message is event-specific so it matches the onError code the node routes it to.

rename and move became first-class onUpdate events in #297 but were left out: they had no dedicated localisation key (a rejected rename/move showed "Update unsuccessful") and reused the generic UPDATE_ERROR code. add/delete already 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 handleEdit comment promises.

Area Change
src/types.ts Add RENAME_ERROR / MOVE_ERROR to the public JsonEditorErrorCode union (additive)
src/localisation.ts Add ERROR_RENAME: 'Rename unsuccessful' / ERROR_MOVE: 'Move unsuccessful'
src/JsonEditor.tsx Replace the errorKey ternary in handleEdit with a module-scope ERROR_MESSAGE_KEY lookup typed Record<UpdateFunctionProps['event'], keyof LocalisedStrings> — exhaustive over the event union so a future event can't silently fall through
src/hooks/useCommon.ts Rename emits RENAME_ERROR
src/hooks/useDragNDrop.tsx Move emits MOVE_ERROR
README.md Localisation table + onError code list
test/JsonEditor.test.tsx Runnable rename-reject test (asserts both the message and the RENAME_ERROR code); move-reject as test.todo (DnD simulation deferred — #270)

Naming decisions

  • Error codes follow the existing <OP>_ERROR suffix convention: RENAME_ERROR / MOVE_ERROR (consistent with ADD_ERROR / DELETE_ERROR).
  • Localisation keys follow the existing ERROR_<OP> prefix convention: ERROR_RENAME / ERROR_MOVE (consistent with ERROR_ADD / ERROR_DELETE).

The two new codes are additive members of the public union — no internal exhaustive switch consumes it, so nothing breaks. A minor changeset is included.

Verification

  • pnpm compile ✅ — union extension typechecks, keyof LocalisedStrings picks up the new keys, no dead exports
  • pnpm lint ✅ clean
  • pnpm test ✅ 295 passed + 3 todo
  • Regression-first check: temporarily reverted the rename code mapping → the new test failed with the right mode (UPDATE_ERROR instead of RENAME_ERROR), then restored and re-confirmed green

🤖 Generated with Claude Code

…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>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Bundle size impact

json-edit-react

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.

CarlosNZ and others added 2 commits June 4, 2026 10:05
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>
@CarlosNZ CarlosNZ merged commit ee583bc into v2.0-dev Jun 3, 2026
2 checks passed
@CarlosNZ CarlosNZ deleted the feat/v2.0-error-rename-move-codes branch June 3, 2026 22:52
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.

Add dedicated ERROR_RENAME / ERROR_MOVE localisation keys for rejected rename/move

1 participant