fix(schedule): derive the item editor's selection from the document - #92
Merged
Conversation
The schedule view kept the selected element as a copy in state, and the item editor kept a second copy as a local draft. Every edit path that does not pass through the editor -- a drag or resize on the grid, an arrow-key nudge, an undo, a reload after an Obsidian or agent edit -- updated the document only, leaving both copies behind. The editor's next patch then spread its stale copy back over the document, reverting the earlier edit. Reported case: shorten a bar from 7/5-7/6 to 7/5 by dragging, then switch its kind to arrow in the panel, and the end date jumps back to 7/6. The same revert happened for any panel edit after a grid gesture, not just the kind field. Store only the selected id and look the element up in the document, and render the editor straight from its `item` prop. The panel now also follows external file edits and closes itself when the element is deleted. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Problem
In the Schedule tab, an edit made in the side panel could undo a change made on
the grid.
Reported case: create a
barfor 7/5–7/6, shorten it to 7/5, then change itskind to
arrow— the period jumps back to 7/5–7/6.Root cause
The selected element was held as a copy in two places while
docwas the realsource of truth:
schedule-view.tsx—const [selected, setSelected] = useState<ScheduleItem | null>(null)item-editor.tsx—const [draft, setDraft] = useState(item), re-seeded fromthe prop by a
useEffectEvery edit path that does not run through the side panel updates
docalone andleaves both copies stale: a drag or resize on the grid (
ScheduleGridsuppressesonSelectItemwhen the pointer moved, so the selection is never refreshed), anundo, or a reload after an Obsidian / AI-agent edit.
The editor's
committhen hands{ ...draft, ...patch }— the whole staleelement — to
patchItem, writing the pre-drag values back over the document.The reported case is one instance. The same revert happened for title, colour and
task-link edits after any grid gesture.
Fix
Make the selection a derived value instead of a copy, so the staleness cannot
exist:
schedule-view.tsxstores onlyselectedId; the element is looked up indoc.itemswithuseMemo. All call sites follow (file switch, undo/redo,Escape, Delete, grid selection, editor callbacks, element creation), and the
arrow-key nudges now call
patchItemalone.item-editor.tsxrenders straight from itsitemprop — the local draft stateand its re-seeding effect are gone.
commitbuilds{ ...item, ...patch };the normalisation (start/end inversion guard,
end = startfor point kinds) isunchanged.
.claude/rules/ui-conventions.mdso future side panelsdo not reintroduce it.
Intended side effects: the panel now follows external file edits, and it closes
itself when the selected element is deleted.
Verification
npm run build— passednpm test— 124/124 passed (10 files)No component test added: the repo has no jsdom/testing-library setup, only
node-environment vitest for
src/lib. Manual checks:stays 7/5.
after the reload.
🤖 Generated with Claude Code