Refresh showed raw uuids in id-kind value cells (feed/library/ collection/added_by). Two defects, one story: 1. Only ids persist in filter trees; the client's id→label cache dies with the page. The quiet re-resolution fetch reused the suggest facet, whose rows are MEDIA-CONSTRAINED (INNER JOIN media_items + the tree's sibling rules as a constraint) — so an id whose media doesn't match got no row and no label. Live repro: "feed in [A,B,C] AND title contains Chapter" labeled one feed of three (live-request evidence: 200 with total:1). A label is a property of the entity row, not of what currently matches. Fix: pages that render a tree resolve labels SERVER-SIDE at render and embed the map on the mount (data-id-labels) — the collection editor (stored tree) and the bookshelf (URL qf). New SearchService.FilterTreeLabels reads the entity tables with no media join and no tree constraint; scoping rides the request identity through the scoped handle (podcast_feeds/collections RLS — an invisible id resolves to nothing; pinned), libraries mirror the facet's visibility join. A feed with ZERO episodes resolves its title — pinned; that case was structurally impossible before. 2. The bookshelf drawer never hydrated at page load at all: the only load-time hydrate calls live in the PARENT's x-init (initBookshelf), and Alpine initializes parents before nested components — builderData() was null there, so hydrateFromForm no-oped and a URL-qf refresh left the drawer with an empty seeded rule while the grid stayed filtered. The drawer now hydrates in its OWN init when the mount carries no data-tree; the init-order contract is pinned in vitest (185/185). The quiet suggest fetch remains only as a fallback for trees the SSR never saw; embedded labels make it a no-op on refresh. Interactive menus are untouched (their constrained, count-bearing behavior is correct for choosing). Pins: TestRulesPageEmbedsIdLabels (zero-episode feed labels at render, bookshelf qf library label, hidden library NOT labeled); filter/episode-tree/search-contract/RLS/playlist container slices green; contract_pins entry documents the embed contract.
74 lines
3.2 KiB
Templ
74 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, labelsJSON 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 }
|
|
data-id-labels={ labelsJSON }
|
|
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>
|
|
}
|