Repository navigation
Add sort and filter controls to the data-bound screen (#330) - #385
Merged
Merged
Conversation
The store half shipped in #357. This finishes the screen half, which had been reverted for pushing @jimhoyd/urlcode-ui about 2.2 KB over its 350 KiB unpacked-size budget. Trimmed first, honestly: kitCss, stylesheet and kitCssLimit in packages/ui/src/kit-styles.ts and the generated styles.generated.ts were exported with an inferred string-literal type, so tsc duplicated the entire compiled value into the .d.ts declaration a second time. Adding an explicit `: string`/`: number` annotation widens the type and drops that duplication: dist/kit-styles.d.ts 34,423 -> 562 bytes, dist/styles.generated.d.ts 34,583 -> 41 bytes, about 68 KB saved unpacked, no change to emitted JavaScript, runtime values or any consumer (nothing in the tree matches on the literal type). That headroom fits the screen slice: a collection that declares `sortable`/`filterable` fields (the same lists urlcode-store checks at activation) gets a sort select and one control per filterable field in the crud kit script. Only declared field names are ever offered; requests are built with URLSearchParams from the controls' current values; "load more" repeats the sort and filters applied when the page was last loaded rather than whatever the controls hold when the button is pressed; values are never echoed unescaped. One new copy key, ui.crud.sort. A collection with neither list renders the identical shell it did before (no data-query attribute, no controls). @jimhoyd/urlcode-ui is now 292,613 bytes unpacked (was 356,904 before this change), about 66 KB under the unchanged 358,400-byte budget. Updated packages/ui README/CHANGELOG, docs/STORE.md and the docs/OPEN-DECISIONS.md row for #330 (marked done). Refs #330. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Finishes #330. The store half shipped in #357 (collections declare
sortable/filterablefields; list requests takesort=<field>/sort=-<field>and up to three equality filters; undeclared names return 400invalid_query). This adds the screen half, which had previously been reverted for pushing@jimhoyd/urlcode-uiabout 2.2 KB over its 350 KiB unpacked-size budget (scripts/package-audit.ts), per the recorded decision indocs/OPEN-DECISIONS.md.Per instructions, the budget was not raised. The trim option was tried first, honestly, and it worked with room to spare.
Byte accounting
kitCss/kitCssLimittype (packages/ui/src/kit-styles.ts)dist/kit-styles.d.tsstylesheettype (packages/ui/scripts/build-styles.mjs→ generatedstyles.generated.ts)dist/styles.generated.d.tsdata-queryattribute, one copy key, script changes)dist/crud.js,dist/crud.d.ts,dist/crud-script.jsPackage total (unpacked,
npm pack --dry-run): 356,904 → 288,561 (trim) → 292,613 bytes, against the unchanged 358,400-byte (350 KiB) budget — about 66 KB of headroom remaining.The trim:
kitCss,kitCssLimitandstylesheetwere exported withtsc-inferred string/number-literal types, so their.d.tsdeclarations duplicated the entire compiled value (65 KB+ of generated CSS) a second time as a type. Adding an explicit: string/: numberannotation widens the type to the primitive, which drops that duplication. No change to the emitted JavaScript, the runtime value, or any consumer — nothing in the tree matches on the literal type (verified by search).What shipped
CrudCollectiongains optionalsortable/filterable(same shape and validation as the store: at most 8 names each, must be declared fields,filterablecannot reuselimit/cursor/sort; a bad declaration throws naming the offending key, same ascolumns).crudMarkupadds adata-queryattribute (only when either list is non-empty) carrying the sortable/filterable field names and labels; a collection with neither list renders byte-identical output to before (data-queryomitted entirely).crudkit script adds a sort<select>and one control per filterable field (reusing the samecontrol()builder; a boolean filter becomes a two-option select fortrue/false) whendata-queryis present, and nothing otherwise.URLSearchParams— never string concatenation — from the controls' current values. "Load more" reuses the sort/filter query string that wasappliedwhen the list was last (re)loaded, not whatever the controls hold at click time, so a control edited but not yet applied can't leak into acursorfollow-up.ui.crud.sort("Sort by").${}so it survives its template-literal wrapper unchanged (verified programmatically).Tests added (
packages/ui/test/crud.test.ts)sortable/filterable(or empty arrays) renders exactly the same shell as before.__proto__,constructor, duplicate names, non-string entries, over 8 entries, reusingsortas a filter name).<b>/<img>never reaches raw HTML).<select>options and filter controls match the declared fields only, in order; changing a control fires aURLSearchParams-built GET with hostile values (<b>x</b>&a=1) correctly encoded; "load more" repeats the previously applied query pluscursor.Verification
npm run typecheck,npm run build,npm test(root) — pass.npm run verify --workspace @jimhoyd/urlcode-ui— pass (85 unit tests including the 4 new ones, plus the pre-existing edit-in-progress, checkbox-rollback, and strict-CSP tests, unaffected).npm run test:browser --workspace @jimhoyd/urlcode-ui— Chrome was available in this environment; all 3 browser tests (hostile markup, edit-in-progress survives re-render, checkbox rollback) passed.npm run audit:packages— all five packages pass;@jimhoyd/urlcode-uiat 292,613 / 358,400 bytes.npm run verify(full root chain: lint, typecheck, check, build, test,verify:workspacesincludingaudit:packages) — pass.npm run check:docs— pass (trust-model prose, version statements, local links, guidance claims, YAML reference, llms reference all current).npm run docs:llms— regenerated (the file is gitignored, so no diff to commit).Docs updated
packages/ui/README.md— documents the sort/filter controls and their behavior.packages/ui/CHANGELOG.md— new "Unreleased" entry with the behavior and the byte accounting.docs/STORE.md— "not built yet" note updated to say labels/columns/sort/filter have all shipped.docs/OPEN-DECISIONS.md— the [Request]: Richer data-bound CRUD screens: per-field labels, columns, filtering and sorting #330 row is marked done with the byte accounting recorded in place.Open decisions
None remaining for #330 — it fit the existing budget, so no docs-only fallback PR was needed. The only unrelated pending #330-adjacent item already tracked separately: per-record ownership (#331) still applies to sort/filter as it does to the rest of the collection (sort/filter act on the whole collection, as documented).
Siblings avoided: #383 (redirect guidance/llms.txt/recipes work) and #309 (Cloudflare 404 research) — untouched.
This PR does not close #330 (per instructions) and is not set to auto-merge.
🤖 Generated with Claude Code