feat(views): Phase 5i slice E — default view-per-page + opt-out banner

Closes the Phase 5i implementation chain. When `views.is_default_for=<page>`
is set, opening that page with a "clean" URL (no chip params, no
?view=) auto-applies the saved filter + view_type. A "Showing default
view: <name> · clear" banner makes the swap visible and gives the user
a one-click out. Adding any chip param to the URL bypasses the default;
?nodefault=1 is the explicit opt-out for "I want the bare default tree".

New web/views.go: applyDefaultView gates on the param-cleanness check
+ Store.DefaultViewFor lookup. Resolution + view_type revalidation
mirror the slice D ?view=<uuid> path so a kanban-default opened on a
route that doesn't allow kanban falls back cleanly.

handleTree wires it into the existing slice D else-branch (no default
when ?view= is set). DefaultBanner field passes the applied view to
the template for the banner.

Test:
- TestDefaultViewAppliedOnCleanURL — seeds a tree default with
  filter_json={tags:[work]} + view_type=card, then asserts: clean GET /
  applies (card grid + banner with the view's name); ?tag=dev bypasses
  (forest, no banner); ?nodefault=1 opt-out (forest, no banner).
This commit is contained in:
mAi
2026-05-26 13:50:42 +02:00
parent bbc7867a35
commit b9161eba17
5 changed files with 117 additions and 0 deletions

View File

@@ -450,6 +450,7 @@ func (s *Server) handleTree(w http.ResponseWriter, r *http.Request) {
filter := ParseTreeFilter(r.URL.Query())
viewSet := PageViewTypes("/")
view := ParseViewType(r.URL.Query(), viewSet)
var defaultBanner *store.View
// Phase 5i Slice D: ?view=<uuid> resolves a saved view's filter +
// view_type into the current request, overriding URL-only chip state.
// Resolution failure (deleted view, malformed payload) is logged and
@@ -462,6 +463,16 @@ func (s *Server) handleTree(w http.ResponseWriter, r *http.Request) {
view = viewSet.Resolve(view)
} else if err != nil {
s.Logger.Warn("applySavedView", "id", r.URL.Query().Get("view"), "err", err)
} else {
// Phase 5i Slice E: no explicit ?view= → check for a page default.
// applyDefaultView returns nil unless the URL is "clean" (no chip
// state) AND a default exists for this page.
if def, err := s.applyDefaultView(r, "tree", &filter, &view); err == nil && def != nil {
view = viewSet.Resolve(view)
defaultBanner = def
} else if err != nil {
s.Logger.Warn("applyDefaultView", "page", "tree", "err", err)
}
}
roots, orphans, total, orphanN, matched := applyTreeFilter(items, filter, linkKinds)
counts := computeChipCounts(items, filter, linkKinds, tags)
@@ -492,6 +503,7 @@ func (s *Server) handleTree(w http.ResponseWriter, r *http.Request) {
"Kanban": kanban,
"GroupBy": groupBy,
"GroupByChips": groupByChips,
"DefaultBanner": defaultBanner,
// ActiveTags kept for backwards-compat with the old template path; removed
// after the template migrates fully.
"ActiveTags": filter.Tags,