fix(ui): sort values by propertyKey within command class groups#4698
fix(ui): sort values by propertyKey within command class groups#4698ejohnson-lhi wants to merge 1 commit into
Conversation
| for (const key in groups) { | ||
| groups[key].sort((a, b) => (a.propertyKey ?? 0) - (b.propertyKey ?? 0)) | ||
| } | ||
|
|
There was a problem hiding this comment.
Good catch on the ordering, but this comparator has two issues worth fixing before merge:
NaNon stringpropertyKey.propertyKeyisstring | number | null(seeapi/lib/utils.ts:151-152,ZwaveClient.ts:442). CCs like Color Switch (red/green/blue), Notification/Alarm and Indicator use string keys, so(a.propertyKey ?? 0) - (b.propertyKey ?? 0)evaluates toNaNand leaves those groups in an undefined order — potentially scrambling CCs that were previously fine.- Sorting by
propertyKeyalone ignorespropertyandendpoint. A group can contain multiple properties and endpoints. For Configuration, partial (bitmask) params carry apropertyKeywhile base params don't, so a partial param gets pulled away from its base param.
Suggested type-safe comparator (endpoint → property → propertyKey, with natural-numeric string ordering so "slot 2" < "slot 10"):
| for (const key in groups) { | |
| groups[key].sort((a, b) => (a.propertyKey ?? 0) - (b.propertyKey ?? 0)) | |
| } | |
| // sort each group by endpoint → property → propertyKey so keyed | |
| // CCs (e.g. User Code slots) display in a stable, natural order. | |
| // Uses a type-safe comparator because propertyKey may be a string | |
| // (Color Switch, Notification, …) — numeric subtraction would NaN. | |
| const cmp = (a, b) => { | |
| if (typeof a === 'number' && typeof b === 'number') { | |
| return a - b | |
| } | |
| return String(a ?? '').localeCompare(String(b ?? ''), undefined, { | |
| numeric: true, | |
| }) | |
| } | |
| for (const key in groups) { | |
| groups[key].sort( | |
| (x, y) => | |
| cmp(x.endpoint ?? 0, y.endpoint ?? 0) || | |
| cmp(x.property, y.property) || | |
| cmp(x.propertyKey, y.propertyKey), | |
| ) | |
| } |
Note this now reorders all CC groups (rather than relying on insertion order), but the comparator is total and stable so it's safe.
AlCalzone
left a comment
There was a problem hiding this comment.
This is a special case that should be done on a per CC basis. Like @robertsLando pointed out, this change would mess up the sorting for Configuration CC at least.
I also wonder if this would be made obsolete by a dedicated user management UI:
#4638
Values within the User Code command class group (0x63) in the expanded node view are displayed in arbitrary insertion order, making it difficult to find and manage specific lock code slots. Sort only the User Code CC group by propertyKey so slots display in ascending numerical order. Other command classes (notably Configuration CC) are left in their original order.
1311a84 to
1dd0c9f
Compare
|
Thanks for the feedback! I've updated the PR to address your concerns:
|
|
FYI, the credential management PR was merged. Should be in the next release. |
Description
Values within each command class group in the expanded node view (
NodeDetails.vue) are displayed in arbitrary insertion order. For command classes with keyed properties — most notably User Code (0x63) — this means lock code slots appear unsorted (e.g. slot 5, slot 1, slot 12…) rather than in numerical order, making it difficult to find and manage specific slots.Changes
Sort each command class group's values by
propertyKeyin thecommandGroupscomputed property, so values display in consistent ascending order.Files changed:
src/components/nodes-table/NodeDetails.vue(4 lines added)How to test