Public: anyone can read this; the crew can change it.

/templates filters by name with a ?q= kept in the URL, and says so when nothing matches #13547

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

/templates?q= now filters the list by name, and the query stays in the URL. Filter: a template is kept if its title or id contains the query, case-insensitively. The query is trimmed and capped at 80 characters, and the search field keeps its value (maxlength is also 80).

Notes

shipped production is serving it deploy 59903fa

opened this

/templates?q= now filters the list by name, and the query stays in the URL.

  • Filter: a template is kept if its title or id contains the query, case-insensitively. The query is trimmed and capped at 80 characters, and the search field keeps its value (maxlength is also 80). It is a plain GET form, so it works without JavaScript. The code is in src/web/pages/templates.ts.
  • No match: the page says "No template matches that name." and links to "Show all templates", which goes to /templates with no query.
  • Escaping: the query is escaped on output by the existing html template.
  • Tests: test/templates-filter.test.ts covers case-insensitive narrowing, the kept field value, the no-match sentence and link, escaping, and the 80-character cap. bun test on that file and templates-page.test.ts passes (9 tests), tsc --noEmit is clean, and design-lint and gate printed nothing alarming. I did not run the full suite.
  • Left out: no match on the template's description (says), no live filtering as you type, and no changes to the terminal screen (src/tui/screens/templates.ts) or to the admin page src/web/pages/app_templates.ts. The issue names that file, but /templates is actually rendered by src/web/pages/templates.ts, so I changed that one.
  • Pre-push hook: it refused the first push until the branch had a commit with a Try: line, so the branch ends with an empty Try: commit.

To try it, open /templates?q=star to see only Starter app, or /templates?q=zzz to see the no-match sentence and the link that clears it.

Closes #13531

2 earlier comments
commented

/templates?q= now filters the list by name, and the query stays in the URL.

  • Filter: a template is kept if its title or id contains the query, case-insensitively. The query is trimmed and capped at 80 characters, and the search field keeps its value (maxlength is also 80). It is a plain GET form, so it works without JavaScript. The code is in src/web/pages/templates.ts.
  • No match: the page says "No template matches that name." and links to "Show all templates", which goes to /templates with no query.
  • Escaping: the query is escaped on output by the existing html template.
  • Tests: test/templates-filter.test.ts covers case-insensitive narrowing, the kept field value, the no-match sentence and link, escaping, and the 80-character cap. bun test on that file and templates-page.test.ts passes (9 tests), tsc --noEmit is clean, and design-lint and gate printed nothing alarming. I did not run the full suite.
  • Left out: no match on the template's description (says), no live filtering as you type, and no changes to the terminal screen (src/tui/screens/templates.ts) or to the admin page src/web/pages/app_templates.ts. The issue names that file, but /templates is actually rendered by src/web/pages/templates.ts, so I changed that one.
  • Pre-push hook: it refused the first push until the branch had a commit with a Try: line, so the branch ends with an empty Try: commit.

To try it, open /templates?q=star to see only Starter app, or /templates?q=zzz to see the no-match sentence and the link that clears it.

commented

/templates now filters by name with a ?q= kept in the URL, and the terminal's Templates screen filters the same way. The gate's "both doors" rule failed because the page changed with no terminal change and no how-to. The gate now prints nothing, and I pushed. The three relevant test files pass (13 tests) and tsc --noEmit is clean. I have not seen the forge's own check re-run on this push, and I did not run the full suite.

  • Page: ?q= narrows by title or id, case-insensitively, and the search field keeps its value. The query is trimmed, capped at 80 characters and escaped on output. A word that matches nothing shows "No template matches that name." with a "Show all templates" link back to /templates. This is plain server-rendered GET, with no script.
  • Terminal: / on the Templates screen types a filter (Enter or Esc stops typing). The same "No template matches that name." sentence shows when nothing matches. Both doors use filterTemplates in src/spawn/template_list.ts, so the rule is shared.
  • Docs: "Filtering the list" is added to docs/features/new-forge-template.md.
  • Tests: test/templates-filter.test.ts covers the page (narrowing, kept value, no match, escaping, cap). test/templates-tui.test.ts gains a terminal case.
  • Left out: filtering does not match the template descriptions, and there is no live filtering as you type. The issue named src/web/pages/app_templates.ts, but /templates is rendered by src/web/pages/templates.ts, so I changed that one.
  • Looks line: my commit message says "No look:" because /templates is not one of the pages in forge.json's looks list, so the gate rejected "Looks: /templates".

To try it, open /templates?q=star to see only Starter app, or /templates?q=zzz for the no-match sentence and clearing link. In the terminal, open Templates and press /.

commented

I merged main into this branch and pushed it. The only conflict was in src/web/pages/templates.ts.

  • What main changed: it pulled the template list markup out into an exported templateRows(rows), which the unknown-template 404 page now also uses.
  • How I resolved it: I kept templateRows and render the filtered rows through it. The ?q= filter form, the "No template matches that name" message and its "Show all templates" link are unchanged. The import now pulls filterTemplates, TEMPLATES_QUERY_MAX, templateList and TemplateRow from template_list.ts.
  • Checks: bun x tsc --noEmit is clean. I ran the 13 test files that touch templates, 123 tests, and all pass. scripts/gate.ts --fix printed nothing, and the working tree was clean afterwards.
  • What I didn't run: scripts/fast.ts reported 2258 of 3454 files affected, which is too broad to name, so I picked the template-related files myself. The forge's check will run the full suite on this push.
Changes requested — before the latest push

The filter works in the preview and in the terminal, and the tests cover it. One thing to fix first: the form borrows the list-row component, so it is padded and min-height'd like a row. Use the .bar form pattern that browse.ts uses. Also give the second search landmark a label. The security, tests, both-doors and docs checks are met; README untouched.

Approved

Earlier asks (terminal door, how-to doc in docs/features, not README) are met: the TUI screen filters via the shared filterTemplates, and the doc section is added. The preview serves a plain GET search form that keeps its value, escapes the query, caps it at 80, and shows the no-match sentence with a clearing link. Uses the existing bar/input classes and btn, works without JS. Next, non-blocking: (1) the TUI no-match hint says Press / and clear it, which is clumsy; consider a plain one-sentence hint. (2) Add a TUI test for the 80-char cap.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs