fix(plan): edit/add the clicked record + layer-aware add in exception mode
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -198,10 +198,19 @@ export default function PlanWork() {
|
||||
// Null when the modal is closed or in a "create" state with no source cell.
|
||||
const [modalCell, setModalCell] = useState<ReturnType<typeof getCell>>(null);
|
||||
|
||||
// Open the create form for a brand-new record. `source` picks the layer:
|
||||
// "entry" (default) opens the normal create form; "override" opens the
|
||||
// single-day create-override form. The day panel passes "override" when the
|
||||
// day is in exception mode so the new record lands in the same layer that's
|
||||
// showing (otherwise resolveCell would hide a new entry behind the override).
|
||||
const openCreate = useCallback(
|
||||
(userId: number, date: string) => {
|
||||
(userId: number, date: string, source: "entry" | "override" = "entry") => {
|
||||
setModalCell(null);
|
||||
setHookModal({ kind: "create", userId, date });
|
||||
if (source === "override") {
|
||||
setHookModal({ kind: "create-override", userId, date });
|
||||
} else {
|
||||
setHookModal({ kind: "create", userId, date });
|
||||
}
|
||||
},
|
||||
[setHookModal],
|
||||
);
|
||||
@@ -278,11 +287,14 @@ export default function PlanWork() {
|
||||
|
||||
// Switch the modal from "day-in-range" to "edit-range" mode, keeping the
|
||||
// same cell context so the EditForm opens with the range's values.
|
||||
// Uses `modalCell` — the record the user actually clicked in the day panel
|
||||
// (captured by editRecord) — NOT getCell (which returns the PRIMARY record).
|
||||
// On a day with 2+ records these differ; using the primary would edit the
|
||||
// wrong range. modalCell is already set to the clicked record at this point
|
||||
// (editRecord → day-in-range → here).
|
||||
const switchToEditRange = useCallback(
|
||||
(entryId: number, userId: number, date: string) => {
|
||||
const cell = getCell(grid, userId, date);
|
||||
if (!cell) return;
|
||||
setModalCell(cell);
|
||||
if (!modalCell) return;
|
||||
setHookModal({
|
||||
kind: "edit-range",
|
||||
entryId,
|
||||
@@ -290,7 +302,7 @@ export default function PlanWork() {
|
||||
date,
|
||||
});
|
||||
},
|
||||
[grid, setHookModal],
|
||||
[modalCell, setHookModal],
|
||||
);
|
||||
|
||||
// --- Mutation wrappers -----------------------------------------------------
|
||||
@@ -457,11 +469,14 @@ export default function PlanWork() {
|
||||
);
|
||||
|
||||
// "Create override from range" — turn a multi-day entry into a one-day
|
||||
// override for the clicked date. We look up the cell's source entry and
|
||||
// create a new override mirroring its fields, locked to a single date.
|
||||
// override for the clicked date. We mirror the CLICKED record's fields
|
||||
// (modalCell, captured by editRecord) — NOT getCell, which returns the
|
||||
// PRIMARY record. On a day with 2+ records the clicked entry can differ
|
||||
// from the primary; carving from the primary would copy the wrong
|
||||
// project/category/note into the override.
|
||||
const createOverrideFromRange = useCallback(
|
||||
async (entryId: number, userId: number, date: string) => {
|
||||
const cell = getCell(grid, userId, date);
|
||||
const cell = modalCell;
|
||||
if (!cell) {
|
||||
alert.error("Nepodařilo se najít zdrojový záznam");
|
||||
return;
|
||||
@@ -485,7 +500,7 @@ export default function PlanWork() {
|
||||
// symmetry with the modal contract.
|
||||
void entryId;
|
||||
},
|
||||
[grid, createOverride, alert, firePulse, rollbackMutation],
|
||||
[modalCell, createOverride, alert, firePulse, rollbackMutation],
|
||||
);
|
||||
|
||||
// --- Modal key for remount-on-mode-change ----------------------------------
|
||||
@@ -506,6 +521,9 @@ export default function PlanWork() {
|
||||
const modalMode: PlanCellModalMode = useMemo(() => {
|
||||
if (hookModal.kind === "closed") return { kind: "closed" };
|
||||
if (hookModal.kind === "create") return hookModal;
|
||||
// create-override carries the same userId/date payload as create and needs
|
||||
// no merged cell/range — pass it straight through (EditForm handles it).
|
||||
if (hookModal.kind === "create-override") return hookModal;
|
||||
if (hookModal.kind === "view") {
|
||||
if (!modalCell) return { kind: "closed" };
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user