Skip to content

Commit 93690e3

Browse files
committed
fix threshold sorting [ci]
Signed-off-by: Paweł Perek <pawel.perek@digitalasset.com>
1 parent d4c69e1 commit 93690e3

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

apps/sv/frontend/src/__tests__/governance/governance-sorting.test.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { ProposalListingData } from '../../utils/types';
1515
describe('Governance Page Sorting', () => {
1616
describe('Action Required Section', () => {
1717
test('should render items sorted by voting closes date ascending (closest deadline first)', () => {
18-
// Pass data intentionally in unsorted order
1918
const unsortedRequests: ActionRequiredData[] = [
2019
{
2120
actionName: 'Action C - Latest deadline',
@@ -49,7 +48,6 @@ describe('Governance Page Sorting', () => {
4948
const cards = screen.getAllByTestId('action-required-card');
5049
expect(cards).toHaveLength(3);
5150

52-
// Verify order: earliest deadline first
5351
const actionNames = cards.map(
5452
card => card.querySelector('[data-testid="action-required-action-content"]')?.textContent
5553
);
@@ -103,7 +101,6 @@ describe('Governance Page Sorting', () => {
103101
};
104102

105103
test('should render items sorted by effective date ascending (closest first)', () => {
106-
// Pass data intentionally in unsorted order
107104
const unsortedRequests: ProposalListingData[] = [
108105
{
109106
...baseData,
@@ -154,7 +151,7 @@ describe('Governance Page Sorting', () => {
154151
expect(actionNames[2]).toBe('Action C - Latest effective');
155152
});
156153

157-
test('should place Threshold items after items with specific effective dates', () => {
154+
test('should sort Threshold items by their voting deadline alongside dated items', () => {
158155
const unsortedRequests: ProposalListingData[] = [
159156
{
160157
...baseData,
@@ -192,9 +189,8 @@ describe('Governance Page Sorting', () => {
192189
row => row.querySelector('[data-testid="inflight-votes-row-action-name"]')?.textContent
193190
);
194191

195-
// Dated items should come before Threshold items
196-
expect(actionNames[0]).toBe('Dated Action');
197-
expect(actionNames[1]).toBe('Threshold Action');
192+
expect(actionNames[0]).toBe('Threshold Action');
193+
expect(actionNames[1]).toBe('Dated Action');
198194
});
199195

200196
test('should sort multiple Threshold items by voting deadline', () => {
@@ -260,7 +256,6 @@ describe('Governance Page Sorting', () => {
260256
};
261257

262258
test('should render items sorted by effective date descending (most recent first)', () => {
263-
// Pass data intentionally in unsorted order
264259
const unsortedRequests: ProposalListingData[] = [
265260
{
266261
...baseData,
@@ -349,7 +344,6 @@ describe('Governance Page Sorting', () => {
349344
row => row.querySelector('[data-testid="vote-history-row-action-name"]')?.textContent
350345
);
351346

352-
// Later time should come first (most recent)
353347
expect(actionNames[0]).toBe('Action B - Later time');
354348
expect(actionNames[1]).toBe('Action A - Earlier time');
355349
});

apps/sv/frontend/src/components/governance/ProposalListingSection.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,21 @@ const sortProposals = (
4545
): ProposalListingData[] => {
4646
if (!sortOrder) return data;
4747

48-
return data.toSorted((a, b) => {
49-
if (sortOrder === 'effectiveAtAsc') {
50-
// For ascending sort: items with "Threshold" (no specific effective date) go after items with dates
51-
const aIsThreshold = a.voteTakesEffect === 'Threshold';
52-
const bIsThreshold = b.voteTakesEffect === 'Threshold';
53-
54-
if (aIsThreshold && bIsThreshold) {
55-
// Both are threshold-based, sort by voting deadline
56-
return dayjs(a.votingThresholdDeadline).isBefore(dayjs(b.votingThresholdDeadline)) ? -1 : 1;
48+
return data
49+
.map(item => ({
50+
item,
51+
effectiveDate: dayjs(
52+
item.voteTakesEffect === 'Threshold' ? item.votingThresholdDeadline : item.voteTakesEffect
53+
),
54+
}))
55+
.toSorted((a, b) => {
56+
if (sortOrder === 'effectiveAtAsc') {
57+
return a.effectiveDate.isBefore(b.effectiveDate) ? -1 : 1;
58+
} else {
59+
return a.effectiveDate.isAfter(b.effectiveDate) ? -1 : 1;
5760
}
58-
if (aIsThreshold) return 1;
59-
if (bIsThreshold) return -1;
60-
61-
return dayjs(a.voteTakesEffect).isBefore(dayjs(b.voteTakesEffect)) ? -1 : 1;
62-
} else {
63-
// effectiveAtDesc: most recent first
64-
return dayjs(a.voteTakesEffect).isAfter(dayjs(b.voteTakesEffect)) ? -1 : 1;
65-
}
66-
});
61+
})
62+
.map(({ item }) => item);
6763
};
6864

6965
export const ProposalListingSection: React.FC<ProposalListingSectionProps> = props => {

0 commit comments

Comments
 (0)