fix(frontend): sort the admin user columns ascending under the ascend caret - #7825
Open
aglinxinyuan wants to merge 2 commits into
Open
fix(frontend): sort the admin user columns ascending under the ascend caret#7825aglinxinyuan wants to merge 2 commits into
aglinxinyuan wants to merge 2 commits into
Conversation
Contributor
Automated Reviewer SuggestionsBased on the
|
Contributor
Backport auto-label reportThis
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7825 +/- ##
=========================================
Coverage 91.50% 91.50%
Complexity 4501 4501
=========================================
Files 1177 1177
Lines 47489 47489
Branches 5324 5324
=========================================
Hits 43457 43457
Misses 2366 2366
Partials 1666 1666
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…nd caret nz-table applies an NzTableSortFn's result as-is for 'ascend' and negates it for 'descend', so sortByID's reversed operands rendered the highest uid first under the up caret. The reversal was not a "newest accounts first" default: no column sets nzSortOrder, so the comparator only runs once a header is clicked, and Account Creation Time, the column that actually encodes recency, already sorts oldest-first. Extend the rendered-header table with the ID column so it pins the row order and the active caret in both directions, and supply the rows in an order that matches no column's ascending or descending expectation, so no leg can pass against a table that does not sort. Also note why sortByActive's active-before-inactive ranking is its ascending order rather than a reversal.
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.
What changes were proposed in this PR?
Seven sortable columns in the admin user table rendered backwards relative to the caret they lit.
sortByID,sortByName,sortByEmail,sortByAffiliation,sortByJoiningReason,sortByCommentandsortByRoleall compared with reversed operands.ng-zorro uses an
NzTableSortFn's result as-is forascendand negates it fordescend(ng-zorro-antd-table.mjs:822). Every one of these seven headers declaresnzSortDirections="['ascend','descend']"— nonullmember — so the first click is alwaysascend, and reversed operands render Z→A under a lit up-caret.All seven were verified individually against their own
<th>before being touched; none was already correct and none started atdescend:<th>nzSortDirectionssortByID['ascend','descend']sortByName['ascend','descend']sortByEmail['ascend','descend']sortByAffiliation['ascend','descend']sortByJoiningReason['ascend','descend']sortByComment['ascend','descend']sortByRolenzSortFnat 105),['ascend','descend']Same defect and same signature as
sortBySizein #7806. Two corroborations inside this file: the tie-breaker in all six string comparators is the contract-correct ascendinga.uid - b.uid, andsortByAccountCreationalready uses ascending form under an identical header.Why
sortByIDis in scope after allAn earlier revision of this PR left
sortByIDalone, on the theory that "highest uid first" might be a deliberate newest-accounts-first default rather than the same defect. It isn't, for two reasons:nzSortOrder(grep -c nzSortOrderoveradmin-user.component.htmlreturns 0). The table has no default sort at all — it renders in the order rows arrive until someone clicks a header. So the reversal cannot express a "newest first" default, because the comparator does not run until a click. Its only observable effect was that clicking the up caret on ID rendered highest-uid-first.sortByAccountCreationis(a - b), i.e. oldest-first under the up caret. If newest-first were the product stance, that is the column that would be reversed. It isn't, so ID was the lone inversion in the table.sortByActivewas examined for the same signature and deliberately not changed, only documented. Its key is a boolean, so there is no natural A→Z to reverse; ng-zorro's contract asks a comparator to declare its own ascending order, and "active before inactive" is that order — it is also what makes the first click useful. The existing unit test already pins both directions plus the uid tiebreak.The existing spec was cementing the defect
Its "column sort comparators" block asserted the reversed behaviour directly — e.g.
sortByName(Alice, Bob) > 0, andsortByIDhad a bareit("orders by descending uid"). Those assertions are corrected here, which is why they appear in the failing-before set below rather than being untouched.Failing before, passing after
admin-user.component.spec.ts14 is exactly 7 comparators × 2 tests each. The rendered-header failures show the #7806 signature — the caret assertions passed and only the order failed, e.g.
sorts User Role A-to-Z…→expected [3, 2, 1, 4] to deeply equal [4, 1, 2, 3], and for the ID columnexpected [4, 3, 2, 1] to deeply equal [1, 2, 3, 4].Test design, which matters more here than the fix
The fix is seven operand swaps; the risk is a test that cannot tell a correct comparator from one inverted the other way. Two layers, both covering all seven fields individually:
describe("sorted columns (rendered header)"), table-driven overASCENDING_BY_COLUMNand generating oneit()per column so each gets a fresh fixture — these headers have nonullstate, so a shared fixture would leave earlier columns sorted as secondary keys. Each case clicks the real rendered<th>, waits a macrotask (nz-table republishes its sort operators ondelay(0), so a baredetectChanges()reads the previous ordering), and pins the uid order and which caret carries.active, in both directions.The four fixture rows carry a distinct value in every sorted field, so no comparator reaches its uid tiebreak and any row exchange is visible. The seven per-field orders were chosen so all fourteen sequences (7 ascending + 7 descending) are distinct across the table and none equals the supplied order — no column's expectation can be satisfied by another column's sort, or by the table not sorting at all.
Adding the ID column tightened that last constraint, since uid is what the assertions are written in. The rows were supplied
1,2,3,4, which is exactly ID's ascending expectation — that leg would have passed against a table that never sorted. They are now supplied4,2,1,3, checked against all 24 permutations to collide with none of the fourteen asserted sequences, and the invariant is recorded in a comment so a future reshuffle re-checks it.Three mutation checks confirm both halves are load-bearing:
sortByID:2 failed | 53 passed— its unit test and its rendered test, nothing else.sortByAffiliation:2 failed | 53 passed. So no test passes while six of seven are still broken.['descend','ascend']— the tempting wrong "fix" that yields the right order with the wrong caret — still fails, onexpected false to be truefrom the caret assertion.Verification
admin-user.component.spec.ts55/55; siblinguser-quota.component.spec.ts25/25, unaffected.frontend/srcreferences these comparators (user-project.component.ts'ssortByNameAsc/Descare explicit-direction buttons, notNzTableSortFn).yarn format:ciexits 0; nojunit.xmlleft behind.Any related issues, documentation, discussions?
Closes #7824
How was this PR tested?
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5)