Resolve an occurrence back to the rule behind it

The detail sheet looked its record up by the row's id. For an occurrence
that id carries a #date suffix and is not a key in the store, so `own` came
back undefined and the edit and delete buttons vanished on every recurring
row — and a save would have reached editEvent with an id it could not find
and quietly done nothing.

The suffix is deliberate: marks key off the occurrence so each time round
carries its own completion. There is still only one record to edit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Opus 5 committed 2026-08-28 05:04:39 +02:00
1 parent 4f53b7e153
commit 60041134ee
3 files changed
+68 -13

No files matched your search

+19 -1
View File
@@ -1,5 +1,5 @@
import { z } from "zod";
import { comesRoundEarly, Repeat } from "./recurrence.ts";
import { comesRoundEarly, Repeat, ruleIdOf } from "./recurrence.ts";
import type { Occurrence } from "./recurrence.ts";
import { EventType, GachaEvent, Precision, slugify } from "./schema.ts";
@@ -271,3 +271,21 @@ export function asOccurrenceEvent(
endPrecision: occurrence.endPrecision,
};
}
/**
* The stored record a row belongs to, whichever kind of id it carries.
*
* A row may be one occurrence of a rule, whose id carries a `#` suffix and is
* deliberately not a key in the store. Marks, ignores and ticks key off that
* suffixed id — each time round has its own completion — but there is only ever
* one record to edit, and it is the rule.
*
* Total, and safe for a feed id: `ruleIdOf` returns anything without a
* separator unchanged, and a feed id is simply not in this store.
*/
export function recordFor(
events: CustomEvents,
rowId: string,
): CustomEvent | undefined {
return events[ruleIdOf(rowId)];
}