fix(rules): sort lock states most-urgent-first on the Locks tab for #708 - #816
Open
hdimer wants to merge 1 commit into
Open
fix(rules): sort lock states most-urgent-first on the Locks tab for #708#816hdimer wants to merge 1 commit into
hdimer wants to merge 1 commit into
Conversation
…ucio#708 lockStateComparator already ranks STUCK above REPLICATING above OK above UNKNOWN, and AG-Grid negates a column comparator when 'desc' is requested, so the default sort applied in onGridReady inverted it a second time and put the least urgent locks on top. The first header click then landed on the 'none' step of AG-Grid's asc/desc/null cycle, which is why the column looked like it did not sort at all. Ask for 'asc' so the comparator is used as written, and add a component test that mounts the grid and pins the rendered order.
hdimer
marked this pull request as ready for review
August 22, 2026 14:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #708.
What's wrong
On the Rule page's Locks tab, the State column renders least-urgent-first:
OKandUNKNOWNon top,STUCKat the bottom, which is the opposite of whatlockStateComparator's own doc comment promises (ERROR > STUCK > REPLICATING > OK > UNKNOWN). That matches the screenshot on the issue, where the descending arrow is showing but every visible row isOK.lockStateComparatorreturnspriorityB - priorityA, i.e. it already ranks the most urgent state first. AG-Grid treats acolDef.comparatoras defining ascending order and negates its result when'desc'is requested (SortService.compareRowNodes).DetailsRuleLocksTable.onGridReadyasked forsort: 'desc', so the comparator got inverted a second time.That also explains the issue's literal wording ("the sorting does not take effect" rather than "the sorting is backwards"). AG-Grid's default sort cycle is asc → desc → none, so starting the column at
'desc'meant the user's first header click landed onnone: the sort disappeared and rows fell back to stream-arrival order, so clicking looked like a no-op.The fix
One word: ask for
'asc'so the comparator is used as written. Default order becomes STUCK → REPLICATING → OK → UNKNOWN, and clicking the header now toggles to the reverse instead of clearing the sort.I considered the other direction, flipping
lockStateComparatortopriorityA - priorityBand keeping'desc', which is the more conventional AG-Grid shape. I didn't go that way becausesrc/lib/core/utils/rule-sorting-utils.test.tsexplicitly pins the current "most urgent first" contract ([...states].sort(lockStateComparator)must yieldSTUCKfirst), andruleStateComparator/ruleActivityComparatorin the same module follow the same convention, so flipping it is a three-comparator refactor plus a test rewrite off the back of a one-line UI bug. Happy to do it that way instead if you'd prefer the comparators to follow AG-Grid's convention.Test
test/component/DetailsRuleLocks.test.tsxmounts the realDetailsRuleLocks, captures the grid API that the productiononGridReadyhands out (so the sort direction under test comes from the component, not from the test), feeds four rows in an order that is neither the expected result nor its reverse, and asserts the rendered order. It fails onmainwith[UNKNOWN, OK, REPLICATING, STUCK].npm testis green (108 suites, 456 tests).tsc --noEmitclean,eslintreports no new problems on the touched file. I left the pre-existing Prettier violation inDetailsRuleLocks.tsxalone (an unrelated long template literal) rather than mixing reformatting into the fix.One thing worth flagging, not fixed here
The same double inversion exists in two more places, both with a comment saying they prioritise error/stuck rules while doing the opposite:
src/component-library/pages/Rule/list/ListRuleTable.tsx:162src/component-library/pages/DID/details/views/DetailsDIDRules.tsx:143Both apply
sort: 'desc'overruleStateComparator, which is also written most-urgent-first. #708 only mentions the Locks tab so I kept the diff to that, but say the word and I'll fix those here or in a follow-up.I used an AI assistant while investigating and writing this. The diagnosis, the fix, and the test were reviewed and verified by me against the real test suite.
Used AI assistance on this; I reviewed and tested the change myself.