The real-browser sweep (the gotcha classes' native habitat — CSP refusals
fail SILENTLY at build/test time) found four defects, all in the item
3.3/3.4 surfaces:
- Shared builder rows used Alpine attribute expressions that the CSP
parser rejects outright: backtick template literals in :style, the
?. optional chain in :placeholder/x-if, and an if-STATEMENT in a
@click.outside. Rewritten as string concat plus two component methods
(fieldIsDays, dismissSuggestions). Until this fix every drawer open
threw a wall of "CSP Parser Error" console noise and the days-value
affordance never rendered.
- "2 bookss match": the count noun is interpolated into "<n> <noun>s
match", so callers must pass the SINGULAR ("book"/"item").
- The rules editor page received its fields/tree payloads from the
route as already-JSON-encoded strings and wrapped them in JSONArg
AGAIN — double-encoded, so JSON.parse yields a string and the editor
loaded with NO vocabulary and NO prefill. The route now emits raw
JSON into the data attributes (single encode).
- Apply was silently inert: the hook store round-trip used
window.Alpine?.store (optional-chained, no-op when absent) and the
Cancel/Apply block sat outside the builder island scope for part of
the session. Both fixed via the imported Alpine instance and moving
the buttons inside the island; Apply now PUTs the tree end-to-end
(verified live: prefill → edit → apply → 201 → reload → membership).
Browser-verified clean (no fixes needed): picker scope tabs + episode
grid (?scope=episodes door), selection store across swaps, Add Selected
episode membership, library-switcher partial contract (episodes visible
under All Libraries, correctly filtered out under a book library — and
now never OFFERED as a switcher option), episode cards + reorder arrows
persisting position, collection-chain player (Ep N/M, prev/next carry
?queue=collection:, order control absent in collection mode and present
+ persistent in feed mode both in player and feed page), and the
empty-tree Apply guard (400 — a static collection can never be
promoted by accident).
Notes for the next reader of these lines: the OpenChamber panel's
browser.select sets select.value without dispatching change, so htmx
change-triggers must be exercised by real events (Playwright) rather
than the panel; and one 500 was observed on the player's leave-page
progress PUT — a request whose context the navigating browser cancels
mid-write, pre-existing and benign (the immediately following save
returned 200).
73 lines
3.2 KiB
Templ
73 lines
3.2 KiB
Templ
package templates
|
|
|
|
// CollectionRules is the SMART-collection editor (plan item 3.4): the
|
|
// unified filter builder in the collection's scope. One vocabulary
|
|
// (services.FilterFieldsPayload — the same wire the All-Books builder
|
|
// renders), one engine: Apply writes the tree to the collection and
|
|
// the qf engine drives membership everywhere. Legacy rules arrays
|
|
// preload as their CONVERTED tree (RulesToFilterTree) — the upgrade
|
|
// happens at the first Apply, never silently at load.
|
|
templ CollectionRules(user User, collection CollectionData, fieldsJSON string, treeJSON string, scope string) {
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<title>Smart Collection - { collection.Name } - Bookhoard</title>
|
|
<link href="/static/style.css" rel="stylesheet"/>
|
|
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg"/>
|
|
</head>
|
|
<body
|
|
class={ "theme-" + user.Theme }
|
|
x-data="collectionRules"
|
|
data-collection-name={ collection.Name }
|
|
x-init={ "initCollectionRules('" + collection.ID + "', '" + scope + "')" }
|
|
>
|
|
@Header(user, "/collections")
|
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
|
<div class="mb-6">
|
|
<button @click="backToCollection()" class="btn btn-secondary mb-4">
|
|
@Icon("arrow-left", "h-4 w-4")
|
|
Back to Collection
|
|
</button>
|
|
<div class="flex items-center gap-4">
|
|
<span class="grid place-items-center h-12 w-12 rounded-2xl shrink-0 text-2xl" style={ "background-color: var(--accent-muted); color: " + collection.Color }>{ collection.Icon }</span>
|
|
<div>
|
|
<h1 class="text-3xl font-bold" style="color: var(--text-primary)">{ collection.Name }</h1>
|
|
<p class="flex items-center gap-2" style="color: var(--text-secondary)">
|
|
<span class="badge text-xs" style="background-color: var(--accent-muted); color: var(--accent);">⚡ Smart</span>
|
|
if scope == "episodes" {
|
|
Episodes scope — membership recomputes live from the tree below.
|
|
} else {
|
|
Books scope — membership recomputes live from the tree below.
|
|
}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- The unified builder island: SAME component + vocabulary as
|
|
the All-Books drawer (item 3.3's payload). Apply is
|
|
collection-specific (writes the tree; the engine does the
|
|
rest). The group-mode chips express ANY/ALL — the tree's
|
|
root mode IS the collection's match semantics. -->
|
|
<div
|
|
x-data="filterBuilderExtra"
|
|
data-filter-fields={ fieldsJSON }
|
|
data-scope={ scope }
|
|
data-tree={ treeJSON }
|
|
class="card p-6"
|
|
>
|
|
<div class="flex items-center justify-between mb-3 px-1">
|
|
<h2 class="text-lg font-bold" style="color: var(--text-primary)">Filter tree</h2>
|
|
</div>
|
|
@FilterBuilderRows("item")
|
|
<div class="mt-4 pt-4 border-t flex justify-end gap-2" style="border-color: var(--border);">
|
|
<button type="button" @click="backToCollection()" class="btn btn-secondary">Cancel</button>
|
|
<button type="button" @click="applyCollectionTree()" class="btn btn-primary">Apply to Collection</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
}
|