Skip to content

Commit 6bd7c38

Browse files
fix(scorecard): Enable sorting for all columns in entities table (#2648)
1 parent dfaf0e2 commit 6bd7c38

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-scorecard': patch
3+
---
4+
5+
Enable sorting for all other columns in entities table

workspaces/scorecard/plugins/scorecard/src/components/ScorecardPage/EntitiesTable/__tests__/EntitiesTableHeader.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,45 @@ describe('EntitiesTableHeader', () => {
9090
});
9191
expect(sortLabel).toBeInTheDocument();
9292
});
93+
94+
it('should call onSortRequest with the correct column id when a different sortable header is clicked', async () => {
95+
const onSortRequest = jest.fn();
96+
render(
97+
<table>
98+
<EntitiesTableHeader {...defaultProps} onSortRequest={onSortRequest} />
99+
</table>,
100+
);
101+
102+
await userEvent.click(
103+
screen.getByText('entitiesPage.entitiesTable.header.entity'),
104+
);
105+
expect(onSortRequest).toHaveBeenCalledWith('entityName');
106+
107+
await userEvent.click(
108+
screen.getByText('entitiesPage.entitiesTable.header.lastUpdated'),
109+
);
110+
expect(onSortRequest).toHaveBeenCalledWith('timestamp');
111+
});
112+
113+
it('should call onSortRequest again when clicking the already-active sorted column', async () => {
114+
const onSortRequest = jest.fn();
115+
render(
116+
<table>
117+
<EntitiesTableHeader
118+
orderBy="status"
119+
order="asc"
120+
onSortRequest={onSortRequest}
121+
/>
122+
</table>,
123+
);
124+
125+
const metricHeader = screen.getByText(
126+
'entitiesPage.entitiesTable.header.metric',
127+
);
128+
await userEvent.click(metricHeader);
129+
await userEvent.click(metricHeader);
130+
131+
expect(onSortRequest).toHaveBeenCalledTimes(2);
132+
expect(onSortRequest).toHaveBeenCalledWith('status');
133+
});
93134
});

workspaces/scorecard/plugins/scorecard/src/utils/constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@ export const SCORECARD_ENTITIES_TABLE_HEADERS: readonly HeadCell[] = [
3737
id: 'metricValue',
3838
label: 'entitiesPage.entitiesTable.header.value',
3939
width: '8%',
40-
sortable: false,
40+
sortable: true,
4141
},
4242
{
4343
id: 'entityName',
4444
label: 'entitiesPage.entitiesTable.header.entity',
4545
width: '28%',
46-
sortable: false,
46+
sortable: true,
4747
},
4848
{
4949
id: 'owner',
5050
label: 'entitiesPage.entitiesTable.header.owner',
5151
width: '20%',
52-
sortable: false,
52+
sortable: true,
5353
},
5454
{
5555
id: 'entityKind',
5656
label: 'entitiesPage.entitiesTable.header.kind',
5757
width: '12%',
58-
sortable: false,
58+
sortable: true,
5959
},
6060
{
6161
id: 'timestamp',
6262
label: 'entitiesPage.entitiesTable.header.lastUpdated',
6363
width: '20%',
64-
sortable: false,
64+
sortable: true,
6565
},
6666
];

0 commit comments

Comments
 (0)