Skip to content

Commit 1e79f6d

Browse files
committed
Fix warnings caused by react upgrade
- also had to upgrade react-virtualized to fix warnings - which then broke querying for rows as now there's a top level row container that was previously role rowgroup but now role row - so adjust code/tests to account for this
1 parent 80caab2 commit 1e79f6d

26 files changed

+170
-174
lines changed

packages/datagateway-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"react-draggable": "4.5.0",
3131
"react-i18next": "12.3.1",
3232
"react-redux": "8.1.3",
33-
"react-virtualized": "9.22.5",
33+
"react-virtualized": "9.22.6",
3434
"redux": "4.2.0",
3535
"redux-mock-store": "1.5.4",
3636
"redux-thunk": "2.4.1",

packages/datagateway-common/src/api/dataPublications.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { renderHook, waitFor } from '@testing-library/react';
1+
import { act, renderHook, waitFor } from '@testing-library/react';
22
import axios from 'axios';
33
import { History, createMemoryHistory } from 'history';
4-
import { act } from 'react-dom/test-utils';
54
import { DataPublication } from '../app.types';
65
import handleICATError from '../handleICATError';
76
import { createReactQueryWrapper } from '../setupTests';

packages/datagateway-common/src/api/datasets.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { renderHook, waitFor } from '@testing-library/react';
1+
import { act, renderHook, waitFor } from '@testing-library/react';
22
import axios from 'axios';
33
import { History, createMemoryHistory } from 'history';
4-
import { act } from 'react-dom/test-utils';
54
import { Dataset } from '../app.types';
65
import handleICATError from '../handleICATError';
76
import { createReactQueryWrapper } from '../setupTests';

packages/datagateway-common/src/table/headerRenderers/dataHeader.component.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1+
import AddIcon from '@mui/icons-material/Add';
2+
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
3+
import SortIcon from '@mui/icons-material/Sort';
4+
import {
5+
Box,
6+
Divider,
7+
SxProps,
8+
TableCell,
9+
TableSortLabel,
10+
Typography,
11+
} from '@mui/material';
112
import React from 'react';
13+
import Draggable from 'react-draggable';
14+
import { TableHeaderProps } from 'react-virtualized';
215
import {
316
Filter,
417
FiltersType,
518
Order,
619
SortType,
720
UpdateMethod,
821
} from '../../app.types';
9-
import { TableHeaderProps } from 'react-virtualized';
10-
import {
11-
TableCell,
12-
TableSortLabel,
13-
Box,
14-
Typography,
15-
Divider,
16-
SxProps,
17-
} from '@mui/material';
1822
import { StyledTooltip } from '../../arrowtooltip.component';
19-
import Draggable from 'react-draggable';
20-
import SortIcon from '@mui/icons-material/Sort';
21-
import AddIcon from '@mui/icons-material/Add';
22-
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
2323

2424
const DataHeader = (
2525
props: TableHeaderProps & {
@@ -135,6 +135,8 @@ const DataHeader = (
135135
</Typography>
136136
);
137137

138+
const dividerRef = React.useRef(null);
139+
138140
return (
139141
<TableCell
140142
size="small"
@@ -162,9 +164,12 @@ const DataHeader = (
162164
</div>
163165
<Draggable
164166
axis="none"
167+
nodeRef={dividerRef}
168+
offsetParent={document.body}
165169
onDrag={(_event, { deltaX }) => resizeColumn(dataKey, deltaX)}
166170
>
167171
<div
172+
ref={dividerRef}
168173
style={{
169174
marginLeft: 18,
170175
paddingLeft: '4px',

packages/datagateway-common/src/table/table.component.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ describe('Table component', () => {
7575
expect(within(columnHeaders[0]).getByText('Test 1')).toBeInTheDocument();
7676
expect(within(columnHeaders[1]).getByText('Test 2')).toBeInTheDocument();
7777

78-
const rows = await screen.findAllByRole('row');
79-
const cellsInFirstRow = within(rows[1]).getAllByRole('gridcell');
78+
const rows = (await screen.findAllByRole('row')).filter((e) =>
79+
e.hasAttribute('aria-rowindex')
80+
);
81+
const cellsInFirstRow = within(rows[0]).getAllByRole('gridcell');
8082
expect(within(cellsInFirstRow[0]).getByText('test1')).toBeInTheDocument();
8183
expect(within(cellsInFirstRow[1]).getByText('2 B')).toBeInTheDocument();
8284
});

packages/datagateway-common/src/table/table.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ export const VirtualizedTable = React.memo(
330330
return (
331331
<DetailsPanelRow
332332
{...props}
333+
// eslint-disable-next-line react/prop-types
334+
key={props.key}
333335
detailsPanel={detailsPanel}
334336
detailPanelRef={detailPanelRef}
335337
detailsPanelResize={detailsPanelResize}

packages/datagateway-dataview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"react-i18next": "12.3.1",
4444
"react-redux": "8.1.3",
4545
"react-router-dom": "5.3.4",
46-
"react-virtualized": "9.22.5",
46+
"react-virtualized": "9.22.6",
4747
"redux": "4.2.0",
4848
"redux-logger": "3.0.6",
4949
"redux-mock-store": "1.5.4",

packages/datagateway-dataview/src/page/pageRouting.component.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import { initialState as dgDataViewInitialState } from '../state/reducers/dgdata
1010
import PageRouting from './pageRouting.component';
1111

1212
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
13-
import { render, screen } from '@testing-library/react';
13+
import { act, render, screen } from '@testing-library/react';
1414
import axios from 'axios';
1515
import { History, createMemoryHistory } from 'history';
16-
import { act } from 'react-dom/test-utils';
1716
import { findColumnHeaderByName, flushPromises } from '../setupTests';
1817
import {
1918
checkDatasetId as unmockedCheckDatasetId,

packages/datagateway-dataview/src/page/withIdCheck.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import { act, render, RenderResult } from '@testing-library/react';
12
import React from 'react';
2-
import withIdCheck from './withIdCheck';
3-
import { act } from 'react-dom/test-utils';
4-
import { flushPromises } from '../setupTests';
53
import { MemoryRouter } from 'react-router-dom';
6-
import { render, RenderResult } from '@testing-library/react';
74
import type { Mock, MockInstance } from 'vitest';
5+
import { flushPromises } from '../setupTests';
6+
import withIdCheck from './withIdCheck';
87

98
describe('withIdCheck', () => {
109
let useEffect: MockInstance;

packages/datagateway-dataview/src/setupTests.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ export const findColumnHeaderByName = async (
9595
* Finds all table rows except the header row.
9696
*/
9797
export const findAllRows = async (): Promise<HTMLElement[]> =>
98-
(await screen.findAllByRole('row')).slice(1);
98+
(await screen.findAllByRole('row')).filter((e) =>
99+
e.hasAttribute('aria-rowindex')
100+
);
99101

100102
/**
101-
* Find the table row at the given index. This assumes the first table row is always the header row.
103+
* Find the table row at the given index.
102104
*
103-
* @param index The index of the table row, igoring the header row. For example, if the table has 2 rows and the first row is the header row,
104-
* the actual row that contains the data is considered the first row, and has an index of 0.
105+
* @param index The index of the table row to find - so the first data row of the table is 0.
105106
*/
106107
export const findRowAt = async (index: number): Promise<HTMLElement> => {
107108
let rows;

0 commit comments

Comments
 (0)