Skip to content

Make Devices table columns sortable#20

Merged
rodchristiansen merged 2 commits into
mainfrom
sortable-devices-table
May 12, 2026
Merged

Make Devices table columns sortable#20
rodchristiansen merged 2 commits into
mainfrom
sortable-devices-table

Conversation

@rodchristiansen
Copy link
Copy Markdown
Owner

Summary

  • Bind a sortOrder state to the Devices Table so column headers expose ascending/descending sort indicators.
  • Each TableColumn now uses value: \.<keyPath>; optional String? attributes get non-optional sort keys via a private DeviceAttributes extension that falls back to "" for nil.
  • Default sort is by Serial Number.

Test plan

  • Launch the app, open the Devices tab, click each column header and confirm rows sort ascending then descending.
  • Confirm columns backed by optional fields (Status, Product Family, Source, Order Number, etc.) sort with empty values grouped together.
  • Confirm selection and inspector behavior still work after sorting.

Bind a sortOrder state to the Table and add value: KeyPaths on each
TableColumn so headers expose ascending/descending sort indicators.
Optional String attributes get non-optional sort keys via a private
extension that falls back to "" for nil values.
Copilot AI review requested due to automatic review settings May 8, 2026 19:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds user-driven sorting to the Devices table by wiring Table’s sortOrder and providing sortable value: key paths (including non-optional sort keys for optional attributes), with a default sort on Serial Number.

Changes:

  • Bind sortOrder to the Table and sort the backing collection using devices.sorted(using: sortOrder).
  • Update each TableColumn to supply a value: key path so headers can drive sorting.
  • Introduce private DeviceAttributes sort-key helpers that map optionals to non-optionals for sorting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 63 to 65
TableColumn("Storage", value: \.sortDeviceCapacity) { (d: DeviceAttributes) in
Text(d.deviceCapacity ?? "")
}
Comment on lines +22 to +24
private var sortedDevices: [DeviceAttributes] {
devices.sorted(using: sortOrder)
}
Comment on lines +10 to +12
var sortOrderNumber: String { orderNumber ?? "" }
var sortOrderDateTime: String { orderDateTime ?? "" }
var sortUpdatedDateTime: String { updatedDateTime ?? "" }
…ed sorted devices

- Storage column sorts by numeric rank (64GB < 256GB < 1TB) instead of string.
- Order Date / Updated columns sort on parsed ISO8601 Date so fractional-
  seconds variants order chronologically.
- Cache sorted devices in @State and refresh on devices/sortOrder changes
  so selection updates don't re-sort the whole table on every body pass.
@rodchristiansen rodchristiansen merged commit ca6b382 into main May 12, 2026
2 checks passed
@rodchristiansen rodchristiansen deleted the sortable-devices-table branch May 12, 2026 17:17
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