Skip to content

Commit

Permalink
Shift-click sorting for download tables #1541
Browse files Browse the repository at this point in the history
  • Loading branch information
kaperoo committed Sep 4, 2023
1 parent 88d2702 commit a28a6bd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ describe('Download cart table component', () => {

rows = await screen.findAllByText(/(DATAFILE|DATASET|INVESTIGATION) \d/);
// row should be sorted by type desc & name asc.
expect(rows[0]).toHaveTextContent('INVESTIGATION 1');
expect(rows[1]).toHaveTextContent('INVESTIGATION 2');
expect(rows[2]).toHaveTextContent('DATASET 1');
expect(rows[3]).toHaveTextContent('DATAFILE 1');
expect(rows[0]).toHaveTextContent('DATAFILE 1');
expect(rows[1]).toHaveTextContent('DATASET 1');
expect(rows[2]).toHaveTextContent('INVESTIGATION 1');
expect(rows[3]).toHaveTextContent('INVESTIGATION 2');

await user.click(nameSortLabel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ const DownloadCartTable: React.FC<DownloadCartTableProps> = (
[t, textFilter]
);
const onSort = React.useCallback(
(column: string, order: 'desc' | 'asc' | null) => {
(column: string, order: 'desc' | 'asc' | null, _, shiftDown?: boolean) => {
if (order) {
setSort({ ...sort, [column]: order });
shiftDown
? setSort({ ...sort, [column]: order })

Check warning on line 200 in packages/datagateway-download/src/downloadCart/downloadCartTable.component.tsx

View check run for this annotation

Codecov / codecov/patch

packages/datagateway-download/src/downloadCart/downloadCartTable.component.tsx#L200

Added line #L200 was not covered by tests
: setSort({ [column]: order });
} else {
const { [column]: order, ...restOfSort } = sort;
setSort(restOfSort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ describe('Admin Download Status Table', () => {
downloadApiUrl: mockedSettings.downloadApiUrl,
facilityName: mockedSettings.facilityName,
},
`WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.userName asc, download.transport asc, download.id ASC LIMIT 0, 50`
`WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.transport asc, download.id ASC LIMIT 0, 50`
// `WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.userName asc, download.transport asc, download.id ASC LIMIT 0, 50`
);

await user.click(accessMethodSortLabel);
Expand All @@ -197,7 +198,8 @@ describe('Admin Download Status Table', () => {
downloadApiUrl: mockedSettings.downloadApiUrl,
facilityName: mockedSettings.facilityName,
},
`WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.userName asc, download.transport desc, download.id ASC LIMIT 0, 50`
`WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.transport desc, download.id ASC LIMIT 0, 50`
// `WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.userName asc, download.transport desc, download.id ASC LIMIT 0, 50`
);

await user.click(accessMethodSortLabel);
Expand All @@ -206,7 +208,8 @@ describe('Admin Download Status Table', () => {
downloadApiUrl: mockedSettings.downloadApiUrl,
facilityName: mockedSettings.facilityName,
},
`WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.userName asc, download.id ASC LIMIT 0, 50`
`WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.id ASC LIMIT 0, 50`
// `WHERE download.facilityName = '${mockedSettings.facilityName}' ORDER BY download.userName asc, download.id ASC LIMIT 0, 50`
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,16 @@ const AdminDownloadStatusTable: React.FC = () => {
},
]}
sort={sort}
onSort={(column: string, order: 'desc' | 'asc' | null) => {
onSort={(
column: string,
order: 'desc' | 'asc' | null,
_,
shiftDown?: boolean
) => {
if (order) {
setSort({ ...sort, [column]: order });
shiftDown
? setSort({ ...sort, [column]: order })

Check warning on line 381 in packages/datagateway-download/src/downloadStatus/adminDownloadStatusTable.component.tsx

View check run for this annotation

Codecov / codecov/patch

packages/datagateway-download/src/downloadStatus/adminDownloadStatusTable.component.tsx#L381

Added line #L381 was not covered by tests
: setSort({ [column]: order });
} else {
const { [column]: order, ...restOfSort } = sort;
setSort(restOfSort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,20 @@ describe('Download Status Table', () => {
// name should be in asc order
rows = await screen.findAllByText(/^test-file-\d$/);
expect(rows[0]).toHaveTextContent('test-file-1');
expect(rows[1]).toHaveTextContent('test-file-3');
expect(rows[2]).toHaveTextContent('test-file-2');
expect(rows[1]).toHaveTextContent('test-file-2');
expect(rows[2]).toHaveTextContent('test-file-3');
expect(rows[3]).toHaveTextContent('test-file-4');
expect(rows[4]).toHaveTextContent('test-file-5');

await user.click(nameSortLabel);

// name should be in desc order
rows = await screen.findAllByText(/^test-file-\d$/);
expect(rows[0]).toHaveTextContent('test-file-3');
expect(rows[1]).toHaveTextContent('test-file-1');
expect(rows[2]).toHaveTextContent('test-file-5');
expect(rows[3]).toHaveTextContent('test-file-4');
expect(rows[4]).toHaveTextContent('test-file-2');
expect(rows[0]).toHaveTextContent('test-file-5');
expect(rows[1]).toHaveTextContent('test-file-4');
expect(rows[2]).toHaveTextContent('test-file-3');
expect(rows[3]).toHaveTextContent('test-file-2');
expect(rows[4]).toHaveTextContent('test-file-1');
});

it('should filter data when text fields are typed into', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,16 @@ const DownloadStatusTable: React.FC<DownloadStatusTableProps> = (
},
]}
sort={sort}
onSort={(column: string, order: 'desc' | 'asc' | null) => {
onSort={(
column: string,
order: 'desc' | 'asc' | null,
_,
shiftDown?: boolean
) => {
if (order) {
setSort({ ...sort, [column]: order });
shiftDown
? setSort({ ...sort, [column]: order })

Check warning on line 337 in packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx

View check run for this annotation

Codecov / codecov/patch

packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx#L337

Added line #L337 was not covered by tests
: setSort({ [column]: order });
} else {
const { [column]: order, ...restOfSort } = sort;
setSort(restOfSort);
Expand Down

0 comments on commit a28a6bd

Please sign in to comment.