Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Preserve selected options across identity normalization
When a selection is stored under a canonical entity, project it back to each view and merge it with the default options so selected search results remain visible after clearing or reopening.
Bad example
| 1 | type Option = { id: string; label: string }; |
| 2 | type Selection = { entityId: string; option: Option }; |
| 3 |
|
| 4 | const selectedOptions = selections |
| 5 | .filter((selection: Selection) => roster.some(option => option.id === selection.entityId)) |
| 6 | .map(selection => selection.option); |
Explanation (EN)
Canonical entity identifiers are compared with view identifiers, and selections outside the default roster disappear.
Objašnjenje (HR)
Kanonski identifikatori entiteta uspoređuju se s identifikatorima prikaza, a odabiri izvan početnog popisa nestaju.
Good example
| 1 | type Option = { id: string; label: string }; |
| 2 | type Selection = { entityId: string; option: Option }; |
| 3 |
|
| 4 | function visibleOptions(roster: Option[], selections: Selection[]): Option[] { |
| 5 | const byId = new Map(roster.map(option => [option.id, option])); |
| 6 | for (const selection of selections) { |
| 7 | byId.set(selection.option.id, selection.option); |
| 8 | } |
| 9 | return [...byId.values()]; |
| 10 | } |
Explanation (EN)
Each selected entity retains its view projection and is merged even if the initial roster did not contain it. Sorting and grouping remain explicit view policies.
Objašnjenje (HR)
Svaki odabrani entitet zadržava svoj prikaz i uključuje se čak i kad ga početni popis nema. Sortiranje i grupiranje ostaju izričita pravila prikaza.
Notes (EN)
Apply to selection interfaces where a write normalizes aliases, categories or related entities into one canonical stored identity. Keep both authoritative membership and the mapping required by each view. Rebuild the same visible selection after reload, not only through an optimistic local row. Test selecting an item absent from the default roster, clearing search, switching views and reopening the picker.
Bilješke (HR)
Primijeni na sučelja odabira u kojima upis pretvara pseudonime, kategorije ili povezane entitete u jedan kanonski identitet. Očuvaj mjerodavno članstvo i preslikavanje potrebno svakom prikazu. Isti vidljiv odabir obnovi i nakon ponovnog učitavanja, a ne samo preko optimističnog lokalnog retka. Testiraj odabir stavke izvan početnog popisa, brisanje pretrage, promjenu prikaza i ponovno otvaranje birača.
Exceptions / Tradeoffs (EN)
The domain may deliberately display only one representative per canonical entity. Preserve that policy while keeping the selection reachable. Removed or unauthorized entities may need a disabled or tombstone representation instead of an enabled option. Do not merge unrelated entity types by bare numeric ID.
Iznimke / Tradeoffi (HR)
Domena može namjerno prikazivati samo jednog predstavnika kanonskog entiteta. Očuvaj to pravilo uz dostupan prikaz odabira. Uklonjeni ili nedopušteni entiteti mogu trebati onemogućen prikaz umjesto aktivne opcije. Nemoj spajati nepovezane tipove entiteta samo prema brojčanom ID-u.