Sort a lookup column from its header

FE
13h ago
+218-47

Sort a lookup column from its header. Builds on the lookup columns from #30439, which is merged, and on the server column from #30657. This PR targets #30657's branch, so the diff shows only the front part. Retarget to main once #30657 merges.

On a lookup column such as Company › Name on People, Sort in the column header orders the rows by the looked-up field: orderBy: [{ company: { name: AscNullsLast } }]. Clicking it again flips the direction. The sort chip reads "Company → Name", and saving the view stores the sort with its target.

Release order: this PR selects viewSort.relationTargetFieldMetadataId and writes it. Per UPGRADE_COMMANDS.md, front-end use of a new column waits until the release containing #30657 is deployed, so this should merge in a later release than #30657.

Changes

Front-only (14 files, +218 −47):

  • Sorts carry a target: RecordSort and ViewSort get relationTargetFieldMetadataId. The view sort fragment selects it, and saving a view (useSaveRecordSortsToViewSorts, useCreateViewFromCurrentView) writes it. areViewSortsEqual compares it, so changing only the target is saved as an update.
  • Query: turnSortsIntoOrderBy orders a sort with a target by that field of the related record, through the shared getOrderByForRelationField. A relation sort without a target still orders by the related record's label field.
  • Header: useHandleToggleColumnSort takes the lookup's target. It flips the direction only when the existing sort has the same target; otherwise it starts a new ascending sort. Sort shows when the looked-up field is sortable: the same selector as Filter, asked about the looked-up field.
  • Chip: EditableSortChip labels a sort with a target "Relation → Field" (the label util from #30653, renamed to getRelationTargetFieldLabel since both chips use it). Sub-field choices, e.g. which part of an address, come from the looked-up field.

A view sorts a field at most once (unique index on view and field), so a lookup column's sort and its relation column's sort replace each other. A header click already replaces all sorts.

Stack

PRWhat it doesBuilds on
#30439Front: lookup columns and their header filter (with #30653)merged
#30657Server: viewSort.relationTargetFieldMetadataIdmain
👉 this PRFront: sort a lookup column from its header#30657

Size: code +74 −19, tests +120 −4, regenerated graphql.ts +24 −24 (S).

Testing

  • Unit: turnSortsIntoOrderBy orders a lookup sort by the looked-up field ({ company: { employees: DescNullsLast } }). useHandleToggleColumnSort replaces a relation sort with a lookup sort, then flips it. The sort, view, record-index and table header suites pass (46 suites, 219 tests).
  • Browser check on the dev seed, with the server built from this branch and its instance command applied:
    • The Company › Name header menu shows Sort.
    • Sort sends orderBy: [{ company: { name: AscNullsLast } }], and rows start with 2020, 3Pillar Global, 6sense. Clicking again sends DescNullsLast (webOS, uTest, project44).
    • The chip reads "Company → Name".
    • Update view stores the sort with its target (viewSort.relationTargetFieldMetadataId set), and after a reload the table is still sorted by Company › Name descending.
  • Front typecheck, oxlint and oxfmt. generated-metadata/graphql.ts was regenerated against the schema of #30657.

Screenshots

Sort in a lookup column's header menu:

Header menu

Sorted by Company › Name, ascending:

Sorted ascending

After saving the view and reloading (descending):

After reload



Generated by Claude Code


Generated by Claude Code