You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/08/30 06:41:25 UTC
(causeway) 01/05: docs(openspec): propose collection sorting and filtering
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch htmx
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 1576f37d8e3c07d380b752f772ce5a4804959446
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sun Aug 30 01:32:43 2026 +0200
docs(openspec): propose collection sorting and filtering
---
.../.openspec.yaml | 2 +
.../add-collection-sorting-and-filtering/design.md | 100 +++++++++++++++++++++
.../proposal.md | 34 +++++++
.../specs/domain-web-components/spec.md | 46 ++++++++++
.../generic-htmx-web-component-viewer/spec.md | 24 +++++
.../rich-graphql-collection-windowing/spec.md | 44 +++++++++
.../specs/vaadin-collection-grid-adapter/spec.md | 36 ++++++++
.../add-collection-sorting-and-filtering/tasks.md | 28 ++++++
8 files changed, 314 insertions(+)
diff --git a/openspec/changes/add-collection-sorting-and-filtering/.openspec.yaml b/openspec/changes/add-collection-sorting-and-filtering/.openspec.yaml
new file mode 100644
index 00000000000..50adc91034f
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/.openspec.yaml
@@ -0,0 +1,2 @@
+schema: spec-driven
+created: 2026-08-29
diff --git a/openspec/changes/add-collection-sorting-and-filtering/design.md b/openspec/changes/add-collection-sorting-and-filtering/design.md
new file mode 100644
index 00000000000..f112d65a3ca
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/design.md
@@ -0,0 +1,100 @@
+## Context
+
+Rich GraphQL collection windows currently materialize the authorized collection, apply an optional configured comparator, and slice by offset and size.
+The web-component range broker therefore has no safe way to apply user sorting or filtering across all windows.
+The existing metamodel `DataTableInteractive` already defines viewer-wide single-column sorting and optional `CollectionFilterService` quick-search semantics over authorized collection rows.
+The pinned Vaadin Grid can host custom column-header renderers, but delegating state to Vaadin sorter or filter elements would create a second state machine and complicate bounded paging and native fallback.
+
+## Goals / Non-Goals
+
+**Goals:**
+
+- Add backward-compatible collection-window criteria that run before slicing.
+- Reuse existing Causeway table sorting and application filtering semantics.
+- Add opt-in, reactive `sortable` and `filterable` collection presentation.
+- Preserve paging, native fallback, authorization, focus, stale-response protection, and bounded requests.
+- Demonstrate both controls in Petclinic.
+
+**Non-Goals:**
+
+- Database-level sorting, filtering, or paging.
+- Multi-column sorting.
+- Per-column filtering.
+- Arbitrary client predicates, regular expressions, or query languages.
+- Exposing Vaadin sorter, filter, data-provider, or item APIs.
+- Persisting sort or filter state across routes.
+
+## Decisions
+
+### Extend `window` with optional Causeway criteria
+
+The additive `window` field will accept optional `sortBy`, `sortDirection`, and `search` arguments while retaining existing offset and size defaults and documents.
+`sortBy` identifies one accepted Causeway table column, `sortDirection` is a bounded enum, and `search` is a bounded string interpreted only by an applicable `CollectionFilterService`.
+The result will advertise accepted sortable member ids, search support, and the bounded search prompt so clients enable only server-supported controls.
+The filtered count becomes `totalCount`, and filtering and sorting run before offset slicing.
+
+This is preferred to browser-only transforms because every page observes the same criteria.
+It is preferred to a new endpoint because the existing window operation already owns bounded collection execution.
+
+### Reuse `DataTableInteractive`
+
+The resolver will create a managed collection table for the visible source object, set the optional search and column sort bindables, and consume its filtered-and-sorted rows.
+This reuses the established column-discovery, configured comparator, `CollectionFilterService`, value comparison, and row authorization behavior used by existing viewers.
+Unsupported sort members, directions, oversized searches, or non-empty searches without an applicable filter service will fail with bounded validation rather than silently degrade.
+
+The resolver still materializes the complete domain collection before filtering, sorting, and slicing.
+Documentation will continue to distinguish response bounds from persistence efficiency.
+
+### Keep all criteria state in `<cw-collection>`
+
+`sortable` and `filterable` will be observed boolean attributes and will default off.
+The host will retain one immutable sort criterion and one bounded search string for its current route generation.
+Changing either criterion will abort current loading, retire the range broker and row contexts, reset offset to zero, and issue one authoritative window request.
+Removing the corresponding attribute will clear its active criterion through the same path.
+
+Paging, refresh, virtual range requests, and bounded range requests will carry the current criteria in their cache identity.
+Criteria are never applied to legacy unbounded `get` responses.
+
+### Render Causeway-owned controls in both presentations
+
+Native table headings and Grid header renderers will use ordinary accessible buttons that cycle one declared sortable member through ascending, descending, and unsorted states.
+The host callback, not Vaadin, changes sorting and reloads data.
+`aria-sort`, visible direction text, and focus restoration remain semantic and toolkit-independent.
+
+Filtering will use one Causeway-owned labelled search field above collection content when the server advertises search support.
+Input will be bounded and debounced, Escape or a clear control will remove it, and active criteria will remain visible during loading and empty states.
+
+This is preferred to importing Vaadin sort/filter elements because it avoids toolkit-owned criteria, page-local array behavior, duplicate data-provider refreshes, additional closure policy, and inconsistent native fallback.
+
+### Demonstrate selected Petclinic controls
+
+The global owner list will opt into both `sortable` and `filterable` while retaining paging.
+Owner pets will opt into sorting, and visit collections will retain their existing behavior unless their row type receives an explicit filtering service.
+A Petclinic `CollectionFilterService` will provide bounded case-insensitive tokens for owner search fields without changing domain persistence or collection membership.
+
+## Risks / Trade-offs
+
+- [Risk] Full collection materialization can be expensive before filtering and sorting.
+ → Mitigation: retain documented materialization semantics, bound only the serialized window, and make the feature opt-in.
+- [Risk] A sort member can expose a property that is unsuitable or unauthorized.
+ → Mitigation: accept only `DataTableInteractive` columns and reuse its managed access and comparison behavior.
+- [Risk] Search implementations can perform expensive or unsafe matching.
+ → Mitigation: accept only bounded plain text and delegate matching solely to registered `CollectionFilterService` implementations.
+- [Risk] Rapid filter input can race paging or virtual range callbacks.
+ → Mitigation: debounce input and reuse host revision, abort controller, request-key, broker teardown, and generation checks.
+- [Risk] Grid and native controls can drift visually or semantically.
+ → Mitigation: use the same host criterion and accessible button/search contracts in both presentations and test responsive transitions.
+
+## Migration Plan
+
+1. Add and test the backward-compatible GraphQL arguments and capability metadata.
+2. Thread criteria through targeted introspection, operation generation, object-context caching, and range brokering.
+3. Add host-owned sorting and filtering controls to native and Grid presentation.
+4. Add Petclinic filtering tokens, markup, integration assertions, and browser journeys.
+5. Run GraphQL, foundation, Petclinic, browser, RAT, strict OpenSpec, and diff validation.
+
+Rollback removes the optional arguments and public attributes; existing offset-and-size documents and unopted collections require no migration.
+
+## Open Questions
+
+None.
diff --git a/openspec/changes/add-collection-sorting-and-filtering/proposal.md b/openspec/changes/add-collection-sorting-and-filtering/proposal.md
new file mode 100644
index 00000000000..d33adaa77ea
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/proposal.md
@@ -0,0 +1,34 @@
+## Why
+
+`<cw-collection>` can page, resize, and reorder qualified Grid presentations, but it cannot safely sort or filter because the current GraphQL window accepts only offset and size.
+Enabling toolkit-only controls would affect one loaded window while appearing to affect the complete collection, so collection-wide server semantics are required first.
+
+## What Changes
+
+- Extend rich GraphQL collection windows with bounded, discoverable search and single-column sort criteria applied before slicing.
+- Reuse Causeway's existing interactive table filtering and sorting semantics so authorization, configured ordering, application `CollectionFilterService`, and supported columns remain authoritative.
+- Add opt-in `sortable` and `filterable` attributes to `<cw-collection>` with reactive offset-zero reload, stale-request retirement, and native fallback behavior.
+- Render Causeway-owned sortable header affordances through both native tables and the private Vaadin Grid adapter while keeping toolkit events and data-provider hints internal.
+- Render one Causeway-owned collection quick-search control for filtering rather than pretending that page-local or unsupported per-column filters are collection-wide.
+- Keep the pinned Grid closure unchanged because sorting and filtering state remains Causeway-owned rather than delegated to toolkit sorter or filter elements.
+- Demonstrate sorting and filtering selectively on Petclinic collections and add application filtering tokens for the demonstrated row types.
+- Replace the prior sorting/filtering exclusion requirements with the new end-to-end contract.
+
+## Capabilities
+
+### New Capabilities
+
+None.
+
+### Modified Capabilities
+
+- `rich-graphql-collection-windowing`: Add bounded search and single-column sort arguments, capability metadata, validation, and pre-slice semantics.
+- `domain-web-components`: Add public sortable and filterable collection behavior without permitting page-local approximation.
+- `vaadin-collection-grid-adapter`: Map server-backed sorting through the private adapter and retain Causeway-owned filtering and state.
+- `generic-htmx-web-component-viewer`: Demonstrate and verify selected sortable and filterable Petclinic collections.
+
+## Impact
+
+The change affects the rich GraphQL model and tests, web-component collection operation generation and state, the private Grid adapter, foundation documentation and tests, and Petclinic resources, filtering service, integration tests, and Playwright coverage.
+The existing unargumented collection `get` field and offset-and-size-only window documents remain schema-compatible.
+Applications that do not opt into `sortable` or `filterable` retain existing loading and presentation behavior.
diff --git a/openspec/changes/add-collection-sorting-and-filtering/specs/domain-web-components/spec.md b/openspec/changes/add-collection-sorting-and-filtering/specs/domain-web-components/spec.md
new file mode 100644
index 00000000000..c8563b816ee
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/specs/domain-web-components/spec.md
@@ -0,0 +1,46 @@
+## ADDED Requirements
+
+### Requirement: Declarative collection sorting and filtering
+`<cw-collection>` SHALL accept optional `sortable` and `filterable` attributes that activate only server-advertised collection-wide criteria.
+Both attributes SHALL default off and MUST NOT transform only the currently loaded rows.
+
+#### Scenario: Sorting is enabled
+- **WHEN** a collection declares `sortable` and its window advertises one or more declared columns as sortable
+- **THEN** accessible column-header controls can select one ascending or descending server criterion
+- **AND** the collection reloads offset zero before paging or virtual ranges continue with that criterion
+
+#### Scenario: Filtering is enabled
+- **WHEN** a collection declares `filterable` and its window advertises quick-search support
+- **THEN** one labelled bounded search control applies the server's collection-wide filtering semantics
+- **AND** filtering resets to offset zero and preserves normalized paging
+
+#### Scenario: Capability is unavailable
+- **WHEN** the server does not advertise sortable declared columns or quick-search support
+- **THEN** the corresponding opt-in attribute does not expose a misleading active control
+- **AND** established collection loading and presentation remain available
+
+#### Scenario: Criteria change reactively
+- **WHEN** sorting, search text, or either opt-in attribute changes
+- **THEN** current loading, row contexts, range cache, focus intent, and paging state are retired or reconciled before offset-zero reload
+- **AND** stale rows, totals, errors, controls, or criteria cannot replace the new state
+
+#### Scenario: Native fallback is active
+- **WHEN** responsive, policy, ordering, capability, or adapter failure selects native presentation
+- **THEN** the same Causeway sorting and filtering criteria remain operable through native semantic controls
+- **AND** no toolkit element or event becomes an application dependency
+
+## MODIFIED Requirements
+
+### Requirement: Collection sorting and filtering remain collection-wide concerns
+The component SHALL expose sorting or filtering only when the collection-window contract can apply the selected criteria across the complete authorized execution-time collection.
+It MUST NOT apply criteria only to loaded rows while presenting them as collection-wide.
+
+#### Scenario: Server contract advertises sort and search inputs
+- **WHEN** the collection window advertises bounded sorting or quick-search capability
+- **THEN** opted-in controls send normalized criteria with every initial, paging, refresh, and virtual-range request
+- **AND** deterministic server results remain authoritative across windows
+
+#### Scenario: Server contract lacks criteria inputs
+- **WHEN** the discovered collection-window operation accepts offset and size but no ordering or search criteria
+- **THEN** the component does not enable sorting or filtering controls
+- **AND** established server ordering remains authoritative across windows
diff --git a/openspec/changes/add-collection-sorting-and-filtering/specs/generic-htmx-web-component-viewer/spec.md b/openspec/changes/add-collection-sorting-and-filtering/specs/generic-htmx-web-component-viewer/spec.md
new file mode 100644
index 00000000000..0349bc933fb
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/specs/generic-htmx-web-component-viewer/spec.md
@@ -0,0 +1,24 @@
+## ADDED Requirements
+
+### Requirement: Selective Petclinic collection sorting and filtering
+Petclinic HTML resource pages SHALL demonstrate server-backed collection sorting and filtering on selected collections without changing domain membership, associated actions, or unselected collection behavior.
+
+#### Scenario: Global owner list renders
+- **WHEN** the Petclinic home page composes the owner list
+- **THEN** its HTML override opts into sortable and filterable collection behavior
+- **AND** owner filtering uses an application `CollectionFilterService` over bounded non-sensitive owner tokens
+
+#### Scenario: Owner sorting is exercised
+- **WHEN** browser automation changes the owner-name sort direction
+- **THEN** the complete filtered owner result is ordered before paging
+- **AND** moving between pages does not duplicate, omit, or locally reshuffle owners
+
+#### Scenario: Owner filtering is exercised
+- **WHEN** browser automation enters a bounded owner search term
+- **THEN** matching owners and filtered paging metadata are returned by the authoritative GraphQL window
+- **AND** clearing search restores the unfiltered owner list from offset zero
+
+#### Scenario: Unselected collections render
+- **WHEN** Petclinic composes a collection without `sortable` or `filterable`
+- **THEN** it retains established paging, ordering, Grid qualification, rows, and associated actions
+- **AND** no sorting or filtering control is introduced solely by another collection's configuration
diff --git a/openspec/changes/add-collection-sorting-and-filtering/specs/rich-graphql-collection-windowing/spec.md b/openspec/changes/add-collection-sorting-and-filtering/specs/rich-graphql-collection-windowing/spec.md
new file mode 100644
index 00000000000..1871b411067
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/specs/rich-graphql-collection-windowing/spec.md
@@ -0,0 +1,44 @@
+## ADDED Requirements
+
+### Requirement: Collection-wide interactive window criteria
+The rich GraphQL collection `window` operation SHALL accept optional bounded search and single-column sort criteria and SHALL apply accepted criteria before offset selection.
+Existing documents that provide only offset and size MUST remain valid.
+
+#### Scenario: Client sorts by an accepted column
+- **WHEN** a client requests an accepted sortable member and ascending or descending direction
+- **THEN** the complete authorized execution-time collection is sorted by that Causeway table column before slicing
+- **AND** every requested offset uses the same accepted criterion
+
+#### Scenario: Client searches a supported collection
+- **WHEN** a non-blank bounded search is supplied for an element type handled by `CollectionFilterService`
+- **THEN** the service's token semantics filter the complete authorized execution-time collection before sorting and slicing
+- **AND** total count and continuation metadata describe the filtered result
+
+#### Scenario: Criteria are absent
+- **WHEN** sort and search criteria are omitted or blank
+- **THEN** the established configured-comparator or encounter-order behavior remains authoritative
+- **AND** existing offset-and-size-only documents retain their response semantics
+
+#### Scenario: Criterion is invalid or unsupported
+- **WHEN** a sort member is not an accepted table column, direction is invalid, search exceeds its bound, or non-blank search has no applicable filter service
+- **THEN** GraphQL returns a bounded validation error
+- **AND** does not silently apply page-local, partial, or unrelated criteria
+
+### Requirement: Discoverable collection criteria capabilities
+A collection window response SHALL advertise the sortable member ids and quick-search capability accepted for that collection execution.
+Capability metadata MUST NOT expose hidden members, row values, filter tokens, or implementation services.
+
+#### Scenario: Sortable members are available
+- **WHEN** the authorized Causeway table model exposes sortable columns
+- **THEN** the window returns their bounded semantic member ids in deterministic order
+- **AND** a client can restrict sort controls to those ids
+
+#### Scenario: Quick search is available
+- **WHEN** an applicable `CollectionFilterService` handles the collection element type
+- **THEN** the window reports search support and a bounded translated prompt
+- **AND** the client need not infer support from row values
+
+#### Scenario: Quick search is unavailable
+- **WHEN** no applicable filter service handles the collection element type
+- **THEN** the window reports search as unsupported
+- **AND** omitting search retains ordinary collection loading
diff --git a/openspec/changes/add-collection-sorting-and-filtering/specs/vaadin-collection-grid-adapter/spec.md b/openspec/changes/add-collection-sorting-and-filtering/specs/vaadin-collection-grid-adapter/spec.md
new file mode 100644
index 00000000000..1f8c7d4d504
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/specs/vaadin-collection-grid-adapter/spec.md
@@ -0,0 +1,36 @@
+## ADDED Requirements
+
+### Requirement: Causeway-owned Grid criteria affordances
+The private Grid adapter SHALL render only Causeway-owned sorting affordances described by the current immutable presentation and SHALL report normalized intent through a private host callback.
+Filtering SHALL remain a collection-host control shared with native presentation.
+
+#### Scenario: Sortable Grid column renders
+- **WHEN** the current presentation marks a declared column sortable
+- **THEN** its Grid header contains an accessible Causeway sort control with current direction state
+- **AND** activating it reports only the semantic member and next bounded direction to the host
+
+#### Scenario: Grid presentation is replaced
+- **WHEN** criteria, responsive mode, route generation, policy, columns, or collection state replaces the adapter presentation
+- **THEN** current header controls reflect only the current immutable criterion
+- **AND** stale header callbacks cannot restore superseded rows or criteria
+
+#### Scenario: Grid falls back to native
+- **WHEN** Grid no longer qualifies while sorting or filtering is active
+- **THEN** native controls retain the same current Causeway criteria
+- **AND** no duplicate toolkit or native criteria state machine remains connected
+
+## MODIFIED Requirements
+
+### Requirement: Unsupported sort and filter hints are not advertised
+The Grid adapter SHALL NOT delegate collection criteria ownership to Vaadin sorter, filter, array, or data-provider behavior.
+It SHALL accept only Causeway presentation options whose callbacks trigger complete server-window criteria.
+
+#### Scenario: Adapter creates columns under the criteria-aware range contract
+- **WHEN** generated columns are marked sortable by the current Causeway presentation
+- **THEN** Causeway-owned header controls invoke the host's normalized server-backed sort callback
+- **AND** raw toolkit sort orders or filters are neither exposed nor silently ignored
+
+#### Scenario: Criteria-aware server contract is absent
+- **WHEN** the collection host cannot apply sorting or filtering across the complete collection
+- **THEN** the adapter renders no active sorting affordance
+- **AND** it does not approximate the behavior over bounded items or cached virtual ranges
diff --git a/openspec/changes/add-collection-sorting-and-filtering/tasks.md b/openspec/changes/add-collection-sorting-and-filtering/tasks.md
new file mode 100644
index 00000000000..05e9c6d08e5
--- /dev/null
+++ b/openspec/changes/add-collection-sorting-and-filtering/tasks.md
@@ -0,0 +1,28 @@
+## 1. Rich GraphQL collection criteria
+
+- [ ] 1.1 Add backward-compatible bounded sort and search arguments plus capability metadata to rich collection windows.
+- [ ] 1.2 Apply accepted `DataTableInteractive` filtering and single-column sorting before slicing while preserving authorization, configured ordering, and bounded validation.
+- [ ] 1.3 Add model and end-to-end GraphQL tests for discovery, sorting, filtering, invalid criteria, counts, paging, and unchanged offset-and-size documents.
+
+## 2. Foundation criteria transport
+
+- [ ] 2.1 Discover criteria arguments and capability fields and include normalized criteria in collection-window operation variables and cache identities.
+- [ ] 2.2 Carry current criteria through initial loads, paging, refresh, virtual ranges, broker generations, and stale-contract checks.
+- [ ] 2.3 Add operation, context, range, and compatibility tests proving complete-window semantics and safe fallback on older schemas.
+
+## 3. Collection presentation
+
+- [ ] 3.1 Add observed default-off `sortable` and `filterable` attributes with bounded reactive criterion state and offset-zero reload.
+- [ ] 3.2 Render accessible native and Grid header sort controls plus one capability-gated bounded quick-search control without exposing toolkit APIs.
+- [ ] 3.3 Preserve focus, empty/loading/error presentation, native fallback, paging, associated actions, and responsive transitions under active criteria.
+- [ ] 3.4 Update foundation usage documentation and adapter/collection tests for defaults, criteria cycles, filtering, stale work, and unsupported capability behavior.
+
+## 4. Petclinic demonstration
+
+- [ ] 4.1 Add bounded owner filtering tokens through an application `CollectionFilterService`.
+- [ ] 4.2 Opt selected Petclinic collections into sorting and filtering while leaving unselected collections unchanged.
+- [ ] 4.3 Update Petclinic integration and Playwright coverage for cross-page sorting, filtering, clearing, accessibility, and associated-action continuity.
+
+## 5. Verification
+
+- [ ] 5.1 Run GraphQL model and end-to-end tests, foundation Node and Maven tests, Petclinic integration and default/native browser tests, RAT, compilation or inspections, diff checks, and strict OpenSpec validation.