Skip to content

feat(smw): server-side default sort (source.orderBy) - #100

Merged
alistair3149 merged 7 commits into
StarCitizenTools:mainfrom
octfx:feat/smw-orderby
Nov 12, 2026
Merged

alistair3149 merged 7 commits into
StarCitizenTools:mainfrom
octfx:feat/smw-orderby

Conversation

@octfx

@octfx octfx commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Add order by support on a single field based on what bucket does.

This patch branch currently runs on star-citizen.wiki here: https://star-citizen.wiki/Comm-Link:%C3%9Cbersicht.
The data grid is generated and sorted by https://star-citizen.wiki/Modul:CommLinkList#L-72, where without the sort key, the list returns pages in ascending order, meaning oldest first.

This just sets the default order, client side can still override/change on what the sort runs on.

Code Disclosure: Generated by an LLM

octfx and others added 7 commits November 8, 2026 22:47
The only lever was initialState.sortModel, which AG Grid applies during init with events suppressed, so the Infinite Row Model's first fetch races ahead unsorted. Mirror Bucket's orderBy instead: { field, direction }, validated at parse time and stored in the query spec. SmwDataSource applies it whenever the request carries no sortModel, via toSortKeys for alias resolution and the subject tiebreaker. A user sort replaces it; clearing the sort falls back to it.
The filterProp heading's hyphen changed its GitHub anchor and broke the
link from filters.md, so use the em dash the rest of data-sources.md
uses. The Lua module's API block listed every SMW source field except
orderBy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SMW's parseOrderBy was a near-copy of Bucket's. Hoist it into
SourceCompilerSupport, taking the allowed fields and how the error names
them, with a native mixed type. SmwSourceCompiler now computes
$hasSubjectColumn once instead of repeating the mainlabel test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parse time is the only author-feedback point, but three mistakes got
past it:

- A numeric printout label ('Has population=2020') became an int array
  key, so the strict field match rejected orderBy = { field = '2020' }.
- A non-string direction or a misspelled key such as `dir` silently
  sorted ascending. Both now fail, for Bucket sources too.
- A printout labelled '_subject' passed orderBy validation but sorted by
  page name, because '_subject' is the page column's key everywhere. The
  label is now reserved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each backend special-cased "no sortModel means the spec's orderBy" in
its own executeQuery, and the two copies differed: SMW treated the field
as a colId, Bucket as a select string. AbstractBackendDataSource::getPage
now substitutes the default once, and Bucket maps its select string to
the colId through an orderByColId() override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unless a wiki enables SMW_QSORT_UNCONDITIONAL, SMW sorts on a property
by requiring a value for it, so pages without one drop out of the rows.
The count query ran without sort keys and still counted them, so the
total overshot and the Infinite Row Model padded the grid with blank
rows. A default orderBy makes that the first view.

countTotal() now receives the effective sort, and SMW's count query
carries the same sort keys as the page query. The docs say which pages
a property sort leaves out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default sort lived only in the stored spec, so AG Grid showed no
sort arrow and its header-click cycle started from "unsorted": the first
click on an ascending default re-sent the same order. The compilers now
set the column's colDef sort, which AG Grid shows and sends with its
first fetch. The spec still covers a request whose sort the user
cleared.

The docs no longer compare orderBy with initialState.sortModel, a path
AG Grid does not have (it is initialState.sort.sortModel).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alistair3149
alistair3149 merged commit 3bdfdd4 into StarCitizenTools:main Nov 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants