fix(frontend): sort all columns on drive details page (closes #656)#1018
fix(frontend): sort all columns on drive details page (closes #656)#1018justadityaraj wants to merge 1 commit into
Conversation
The drive details SMART attributes table declares matSort on every column header (id, name, value, worst, thresh, ideal, failure, history) but sorting only ever worked for status, value, and thresh. The other column ids do not match field names on SmartAttributeModel — id is attribute_id, name and ideal come from metadata, failure is failure_rate, and history is a sparkline chart with no scalar key. MatTableDataSource's default sortingDataAccessor falls back to row[columnId], which silently returns undefined for those columns, so clicking the headers re-renders the data in the same order with no error. Set sortingDataAccessor on smartAttributeDataSource to map each column id to the value actually rendered in the corresponding cell, reusing the existing getAttributeName / getAttributeValue / getAttributeWorst / getAttributeThreshold / getAttributeIdeal getters so the sort key always matches what the user sees. attribute_id is coerced to Number so numeric SMART ids sort numerically rather than lexicographically. history exposes the latest observed value as a sort key — there is no meaningful scalar for a sparkline, but a deterministic order is better than a no-op when the user clicks the header. Closes AnalogJ#656
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1018 +/- ##
=======================================
Coverage 21.51% 21.51%
=======================================
Files 58 58
Lines 3346 3346
=======================================
Hits 720 720
Misses 2587 2587
Partials 39 39
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the contribution! Can you post a couple screenshots or screen recording of the fix? |
|
Hi @kaysond — checking in on this one after a while. Anything needed from my side to help move it along? Happy to rebase or adjust if useful. |
Haven't had time for testing. If you can post a screenshot/video of the fix I'll merge it |
|
Sure @kaysond, will do it by this weekend, in hospital now so will do this once I'm back! |
Summary
Closes #656.
Clicking any column header other than Status, Value, or Threshold on the drive details SMART attributes table re-renders the rows in the same order with no error. The
mat-sort-headerdirective is set on every column, butMatTableDataSource's defaultsortingDataAccessordoes a plainrow[columnId]lookup, and mostmatColumnDefids in the template don't match field names onSmartAttributeModel:idattribute.attribute_idnamegetAttributeName(attribute)—metadata.display_namevaluegetAttributeValue(attribute)— branches ondisplay_type(raw vs transformed vs value)worstgetAttributeWorst(attribute)threshgetAttributeThreshold(attribute)idealgetAttributeIdeal(attribute)—metadata.idealfailureattribute.failure_ratehistorySo
row['id'],row['name'],row['ideal'],row['failure'],row['history']all resolve toundefinedand the sort silently no-ops. Onlystatus,value, andthreshhappened to match field names.Fix
Set
sortingDataAccessoronsmartAttributeDataSourceinngAfterViewInitto map each column id to the value actually rendered in that cell, reusing the existinggetAttribute*getters so the sort key is always exactly what the user sees.attribute_idis coerced viaNumber(...)so numeric SMART ids sort numerically rather than lexicographically (e.g.5, 10, 12not10, 12, 5).worst/threshgetters can return either a number or''depending on display type — preserved as-is so empty cells group together.historyhas no meaningful scalar; exposing the latest observed value gives a deterministic order instead of a no-op when the user clicks the header.defaultbranch falls through to the priorrow[id]lookup so any future column id that matches a model field keeps working.41 lines changed in one file: `webapp/frontend/src/app/modules/detail/detail.component.ts`.
Verification
AI disclosure (per AI_POLICY.md)
This PR was written with Claude Code (Opus 4.7) as a pair-programming assistant. I drove issue selection, read the codebase, decided the fix shape (`sortingDataAccessor` mapping), wrote the column-to-getter mapping, verified the build, and manually tested the sort against my own running scrutiny instance with attached disks. The AI assisted with grepping the codebase, drafting the accessor switch statement, and proofreading. No code was shipped that I haven't read end-to-end.