Files
bookhoard/templates/collection_rules.templ
T
John O'Keefe a4dc03984c feat(docs): "?" help affordance on every filter mount + docs loader fixes
The filter manual (1ed1602e) was reachable only by knowing /docs
already existed — nothing in the UI pointed at it (the parked manual
plan's open decision). Every filter-builder mount now carries a "?"
in its header linking to the guide (opens in a new tab so drawer and
editor state survive): the All Books drawer and the collection rules
page — the two mounts sharing FilterBuilderRows. The docs home
indexes the manual (guide, cookbook, generated field reference).

Two docs-loader fixes surfaced by pinning this:
- Folder URLs resolve to their index page: /docs/user/filters now
  serves user/filters/index.md (the manual is a folder: guide +
  cookbook + generated reference); previously only root /docs had
  index handling.
- The docs folder path is resolved by walking upward (bounded):
  `go test` runs test binaries from the PACKAGE directory, so the
  relative "docs" path resolved to a folder that didn't exist there
  and every /docs route 404'd in tests while working in prod —
  found by the new pin, fixed so tests exercise the docs routes
  exactly as prod serves them.

Pins: TestFilterHelpAffordance (folder URL serves the guide; drawer
and rules pages carry the link). internal/docs suite + full suite
green (239s).
2026-11-01 16:22:35 -05:00

75 lines
3.4 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>
<a href="/docs/user/filters" target="_blank" rel="noopener" class="icon-btn" aria-label="Filter guide" title="How the filter tree works">?</a>
</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>
}