fix(web): commit event duplicates immediately instead of opening the form - #2755
Merged
Conversation
…form Duplicating an event previously created an identical-time draft stacked invisibly on the source and force-opened the edit form, even though every field was already filled in. Duplication now commits straight through the existing create mutation and focuses the new card, so it's immediately visible (saved events participate in the deck overlap layout) and repositionable with Shift+Arrow; Mod+Z still undoes the whole thing.
…ly behavior CI caught a second existing test (useWeekShortcutOwner.test.tsx) asserting the old open-the-form behavior; the day-view equivalent was updated in the prior commit but this one was missed.
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.
Summary
Duplicating an event (Mod+D on a focused grid event, right-click > Duplicate, or the event form's action menu) previously created a grid draft with an identical time slot to the source and force-opened the edit form — even though every field was already filled in. Two problems followed: the draft rendered directly on top of the source with no visual distinction, and the form was an unwanted extra step.
Duplication now commits the copy immediately as a real saved event through the existing optimistic
createmutation, skips the draft/form entirely, and focuses the new card so Shift+Arrow can reposition it right away. It's undoable via the existing Mod+Z stack. Saved events already participate in the app's overlap "deck" layout (grid/layout/timed-deck.layout.ts), so the duplicate and original become visually distinguishable as a side effect of no longer being drafts — no new layout code needed.Falls back to the old draft/form path only when no writable calendar can be resolved for the copy (duplicating from a read-only calendar with no default target calendar set).
Simplicity
commitDuplicateEventinevents/mutations/duplicate-event.ts) called from both the grid keyboard shortcut and the form/context-menu hook, rather than duplicating the commit sequence.duplicateGridEventDraftadapter,parseGridEventDraft, and thecreatemutation as-is — no new mutation or store.duplicateGridEventDraft's return type toExtract<GridEventDraft, { kind: "create" }> | nullso the new helper doesn't need a redundant runtimekindguard just to satisfy the discriminated union./simplifypass (4 parallel review angles: reuse, simplification, efficiency, altitude) found nothing else worth changing at this diff's scope; a couple of lower-value suggestions (extracting a 3-line calendarId-fallback pattern shared withuseSaveEventForm, and lazily reading the default-target-calendar hook) were skipped as not worth the added abstraction/API surface for a negligible cost.Automated validation
Manually verified in a live browser dev server (
bun dev:web, anon/local session):ERR_CONNECTION_REFUSEDnoise from the backend not running in this dev-only session).Independent review
Two independent read-only review rounds via
feature-dev:code-reviewer, plus a 4-angle/simplifypass:useCloseEventForm's refocus-to-source-event and the new commit's focus-the-new-card call, reachable via the form's own Duplicate action. Fixed by havinguseDuplicateEventdiscard the closed form's draft directly (draftActions.discard()) instead of going throughuseCloseEventForm, since the commit path owns focus itself once it succeeds./simplifyfound and fixed one dead branch (adraft.kind !== "create"runtime check that could never be false) by narrowing the adapter's return type instead; three other findings (a small duplicated calendarId-fallback pattern, an unconditional-hook efficiency nit, and a broaderuseCloseEventFormAPI redesign suggestion) were judged not worth the added scope/risk and skipped with reasoning.draftActions.discard()swap drops no other side effect — no findings.Test plan
bun run type-check— cleanbun run lint— clean (13 pre-existing warnings elsewhere, none in touched files)TZ=UTC NODE_ENV=test bun test src/events/mutations/duplicate-event.test.ts src/views/Day/hooks/shortcuts/useDayEventNudgeShortcuts.test.tsx src/views/Forms/EventForm/EventForm.test.tsx src/components/ContextMenu/ContextMenuItems.test.tsx src/events/grid-event-draft.adapter.test.ts(run frompackages/web) — 107 pass, 0 fail