Repository navigation
View grouping and column aggregates (IS-85) - #109
Merged
Merged
Conversation
…d MCP Add GroupByInput: direction is optional on the wire and defaults to asc.
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.
Implements #85: saved views can group by a property, and columns carry footer aggregates.
Schema. Migration v2 (
view-grouping) addsgroup_byandaggregatesTEXT columns toview. Existing v1 databases upgrade with their views kept; the upgrade path has its own test.Store.
group_by: {property, direction}(direction optional on the wire, defaults to asc) groups a query result. The group key is the raw stored cell value, dates truncated to the day, checkboxes'true'/'false',multi_selectthe exact stored combination (documented v1 limitation). Responses carrygroups: [{key, count}]with counts over the whole filtered set and the empty bucket last; rows come flat, sectioned by adjacent keys, group key leading the order.aggregates: {property: fn}computes over the whole filtered set:count,count_values,sum,min,max,average(over filled values, null when none).src/lib/group-key.tsmirrors the SQL key expression for the UI, so sectioning and thecollapsedparameter agree with the store. Explicit bad requests fail400(bad_group/bad_aggregate) and change nothing; a dangling saved entry (property deleted, or its type no longer allows the function) is silently ignored at query time.REST. Views POST and query POST accept
group_by/aggregates; rows GET adds?group=prop. An ungrouped response carries nullgroups/aggregates, so the shape stays additive.MCP.
query_collection_rowsaccepts the same payloads; the newsave_collection_viewtool creates a view with everything the UI can save (29 tools total). Views are not revision-tracked, so the tool takes no actor param andnameis required.UI. One collapsible section per group with its count in the header; collapsed keys travel in the
collapsedURL parameter (percent-encoded, comma-joined,__empty__sentinel) and their rows are hidden server-side, so the toggle is a plain link and pagination stays correct. A footer row aggregates every visible column (defaults while grouping without a saved config: sum for numbers, count_values otherwise). A minimal save-view form behind the existing write gate persists name plus current filters/sorts/grouping. Mobile cards get group headings. The filter and sort forms forwardgroupandcollapsed.Tests. +19:
test/collection-groups.test.ts(12 store-level cases: keys per type, whole-set counts, empty bucket, page-split groups, every aggregate fn, type violations, dangling views), REST and MCP grouping intest/collections-mcp.test.ts(that suite is the one isolatingCOLLECTIONS_DBto a temp dir), and the v1→v2 migration upgrade. 503 passed | 1 skipped on this branch (main: 484),svelte-check0 errors, build green. Notes:min/maxare also allowed ontitle(ordered strings liketext); the v2 migration test asserts store fields, so it lands with the tests commit.Verification lever.
scripts/grouping-walk.shreruns the acceptance against a copy of any instance: whole-set group counts (sum equals total, one key recounted row-by-row), the number sum recomputed withjqover all rows, the saved-view round trip over REST (viewsPOST, query through{view: id},viewsGET echo) and MCP (query_collection_rows,save_collection_view), the400refusals, and an isolation proof that the walk's view exists in the copy's database only. Every write stays below the temp dir; a passing run ends withWALK COMPLETE.Evidence, measured 2026-11-15 against a copy of the live instance (Fixkosten, 22 rows, grouped by Status):
The capture shows group counts summing to the total (15 laufend + 3 neu + 4 offen = 22), the laufend count and the Betrag sum (1891.85) both verified against the rows, the saved view echoed by
viewsGET and applied through{view: id}, the identical grouping over MCP, the source database holding zero walk views, and the two400refusals.The UI on desktop (group sections with counts, one collapsed group, aggregate footer 22 / 1.891,85) and at 390px (card group headings, same collapse):
Two review fixes on top of the implementation:
save_collection_viewhadnameoptional in the zod schema (a view without a name is nonsense; now required, test updated), and it accepted anagentparam recorded nowhere since views are not revision-tracked (dropped).