Skip to content

Commit dbbbe87

Browse files
authored
[BUG] Arrow-keys navigation not consider filters (#217)
* [BUG] Arrow-keys navigation not consider filters Visual-Regression-Tracker/Visual-Regression-Tracker#260
1 parent 0cb3964 commit dbbbe87

File tree

9 files changed

+96
-50
lines changed

9 files changed

+96
-50
lines changed

package-lock.json

Lines changed: 18 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@material-ui/core": "^4.11.2",
7-
"@material-ui/data-grid": "^4.0.0-alpha.19",
7+
"@material-ui/data-grid": "^4.0.0-alpha.33",
88
"@material-ui/icons": "^4.11.2",
99
"@material-ui/lab": "^4.0.0-alpha.57",
1010
"@testing-library/jest-dom": "^5.11.1",

src/components/TestDetailsDialog/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ const useStyles = makeStyles((theme) => ({
1212

1313
export const TestDetailsDialog: React.FunctionComponent = () => {
1414
const classes = useStyles();
15-
const { testRuns, selectedTestRunId } = useTestRunState();
15+
const {
16+
testRuns: allTestRuns,
17+
filteredTestRuns,
18+
selectedTestRunId,
19+
} = useTestRunState();
20+
21+
const testRuns = React.useMemo(() => filteredTestRuns ?? allTestRuns, [
22+
allTestRuns,
23+
filteredTestRuns,
24+
]);
1625

1726
const selectedTestRunIndex = React.useMemo(
1827
() => testRuns.findIndex((t) => t.id === selectedTestRunId),

src/components/TestRunList/BulkOperation.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import {
55
Tooltip,
66
LinearProgress,
77
} from "@material-ui/core";
8-
import { BaseComponentProps, RowModel } from "@material-ui/data-grid";
8+
import {
9+
GridRowData,
10+
GridSelectionState,
11+
useGridSlotComponentProps,
12+
} from "@material-ui/data-grid";
913
import { BaseModal } from "../BaseModal";
1014
import { useSnackbar } from "notistack";
1115
import { Delete, LayersClear, ThumbDown, ThumbUp } from "@material-ui/icons";
1216
import { testRunService } from "../../services";
1317
import { TestStatus } from "../../types";
1418
import { head } from "lodash";
1519

16-
export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
17-
props: BaseComponentProps
18-
) => {
20+
export const BulkOperation: React.FunctionComponent = () => {
21+
const props = useGridSlotComponentProps();
1922
const { enqueueSnackbar } = useSnackbar();
2023
const [approveDialogOpen, setApproveDialogOpen] = React.useState(false);
2124
const [rejectDialogOpen, setRejectDialogOpen] = React.useState(false);
@@ -31,7 +34,7 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
3134
const isMerge: boolean = React.useMemo(
3235
() =>
3336
!!head(
34-
props.rows.filter((value: RowModel) =>
37+
props.rows.filter((value: GridRowData) =>
3538
ids.includes(value.id.toString())
3639
)
3740
)?.merge,
@@ -42,18 +45,18 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
4245
() =>
4346
props.rows
4447
.filter(
45-
(value: RowModel) =>
48+
(value: GridRowData) =>
4649
ids.includes(value.id.toString()) &&
4750
[TestStatus.new, TestStatus.unresolved].includes(
4851
value.status.toString()
4952
)
5053
)
51-
.map((value: RowModel) => value.id.toString()),
54+
.map((value: GridRowData) => value.id.toString()),
5255
// eslint-disable-next-line
5356
[ids]
5457
);
5558

56-
const selectedRows: Record<React.ReactText, boolean> = props.state.selection;
59+
const selectedRows: GridSelectionState = props.state.selection;
5760
const count = Object.keys(selectedRows).length;
5861

5962
const toggleApproveDialogOpen = () => {

src/components/TestRunList/DataGridCustomToolbar.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import React from "react";
22
import { Toolbar, Box } from "@material-ui/core";
33
import {
4-
BaseComponentProps,
5-
DensitySelector,
6-
FilterToolbarButton,
4+
GridToolbarDensitySelector,
5+
GridToolbarFilterButton,
76
} from "@material-ui/data-grid";
87
import { BulkOperation } from "./BulkOperation";
98

10-
export const DataGridCustomToolbar: React.FunctionComponent<BaseComponentProps> = (
11-
props: BaseComponentProps
12-
) => {
9+
export const DataGridCustomToolbar: React.FunctionComponent = () => {
1310
return (
1411
<>
1512
<Toolbar variant="dense">
16-
<FilterToolbarButton />
17-
<DensitySelector />
13+
<GridToolbarFilterButton />
14+
<GridToolbarDensitySelector />
1815
<Box marginLeft="auto">
19-
<BulkOperation {...props} />
16+
<BulkOperation />
2017
</Box>
2118
</Toolbar>
2219
</>

src/components/TestRunList/StatusFilterOperators.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { FormControl, InputLabel, Select } from "@material-ui/core";
22
import React from "react";
33
import { useTestRunState } from "../../contexts";
44
import {
5-
FilterInputValueProps,
6-
getStringOperators,
5+
GridFilterInputValueProps,
6+
getGridStringOperators,
77
} from "@material-ui/data-grid";
88
import { TestStatus } from "../../types";
99

10-
const StatusInputComponent = (props: FilterInputValueProps) => {
10+
const StatusInputComponent = (props: GridFilterInputValueProps) => {
1111
const { item, applyValue } = props;
1212
const { testRuns } = useTestRunState();
1313

@@ -42,7 +42,7 @@ const StatusInputComponent = (props: FilterInputValueProps) => {
4242
);
4343
};
4444

45-
export const StatusFilterOperators = getStringOperators()
45+
export const StatusFilterOperators = getGridStringOperators()
4646
.filter((operator) => operator.value === "equals")
4747
.map((operator) => ({
4848
...operator,

src/components/TestRunList/TagFilterOperators.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { FormControl, InputLabel, Select } from "@material-ui/core";
22
import React from "react";
33
import { useTestRunState } from "../../contexts";
44
import {
5-
FilterInputValueProps,
6-
getStringOperators,
5+
GridFilterInputValueProps,
6+
getGridStringOperators,
77
} from "@material-ui/data-grid";
88

9-
const TagInputComponent = (props: FilterInputValueProps) => {
9+
const TagInputComponent = (props: GridFilterInputValueProps) => {
1010
const { item, applyValue } = props;
1111
const { testRuns } = useTestRunState();
1212

@@ -51,7 +51,7 @@ const TagInputComponent = (props: FilterInputValueProps) => {
5151
);
5252
};
5353

54-
export const TagFilterOperators = getStringOperators()
54+
export const TagFilterOperators = getGridStringOperators()
5555
.filter((operator) => operator.value === "contains")
5656
.map((operator) => ({
5757
...operator,

src/components/TestRunList/index.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@ import {
1111
import { useSnackbar } from "notistack";
1212
import {
1313
DataGrid,
14-
ColDef,
15-
RowParams,
16-
CellParams,
14+
GridCellParams,
15+
GridColDef,
16+
GridRowParams,
17+
GridValueGetterParams,
18+
GridValueFormatterParams,
19+
GridFilterModelParams,
1720
} from "@material-ui/data-grid";
1821
import { DataGridCustomToolbar } from "./DataGridCustomToolbar";
1922
import { StatusFilterOperators } from "./StatusFilterOperators";
2023
import { TagFilterOperators } from "./TagFilterOperators";
24+
import { TestRun } from "../../types";
2125

22-
const columnsDef: ColDef[] = [
26+
const columnsDef: GridColDef[] = [
2327
{ field: "id", hide: true, filterable: false },
2428
{ field: "name", headerName: "Name", flex: 1 },
2529
{
2630
field: "tags",
2731
headerName: "Tags",
2832
flex: 1,
29-
valueGetter: (params: CellParams) => {
33+
valueGetter: (params: GridValueGetterParams) => {
3034
const tags: Array<string> = [
3135
params.row["os"],
3236
params.row["device"],
@@ -39,10 +43,10 @@ const columnsDef: ColDef[] = [
3943
""
4044
);
4145
},
42-
renderCell: (params: CellParams) => (
46+
renderCell: (params: GridCellParams) => (
4347
<React.Fragment>
4448
{params
45-
.getValue("tags")
49+
.getValue(params.id, "tags")
4650
?.toString()
4751
.split(";")
4852
.map(
@@ -64,8 +68,12 @@ const columnsDef: ColDef[] = [
6468
field: "status",
6569
headerName: "Status",
6670
flex: 0.3,
67-
renderCell: (params: CellParams) => {
68-
return <TestStatusChip status={params.getValue("status")?.toString()} />;
71+
renderCell: (params: GridValueFormatterParams) => {
72+
return (
73+
<TestStatusChip
74+
status={params.getValue(params.id, "status")?.toString()}
75+
/>
76+
);
6977
},
7078
filterOperators: StatusFilterOperators,
7179
},
@@ -101,16 +109,26 @@ const TestRunList: React.FunctionComponent = () => {
101109
pageSize={10}
102110
rowsPerPageOptions={[10, 20, 30]}
103111
loading={loading}
104-
showToolbar={true}
105112
components={{
106113
Toolbar: DataGridCustomToolbar,
107114
}}
108115
checkboxSelection
109116
disableColumnSelector
110117
disableColumnMenu
111118
disableSelectionOnClick
112-
onRowClick={(param: RowParams) => {
113-
selectTestRun(testRunDispatch, param.getValue("id")?.toString());
119+
onRowClick={(param: GridRowParams) => {
120+
selectTestRun(
121+
testRunDispatch,
122+
param.getValue(param.id, "id")?.toString()
123+
);
124+
}}
125+
onFilterModelChange={(params: GridFilterModelParams) => {
126+
testRunDispatch({
127+
type: "filter",
128+
payload: Array.from(
129+
params.visibleRows.values()
130+
) as Array<TestRun>,
131+
});
114132
}}
115133
/>
116134
)}

src/contexts/testRun.context.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ interface IRejectAction {
4747
payload: TestRun;
4848
}
4949

50+
interface IFilterAction {
51+
type: "filter";
52+
payload: Array<TestRun>;
53+
}
54+
5055
type IAction =
5156
| IRequestAction
5257
| IGetAction
@@ -55,11 +60,13 @@ type IAction =
5560
| IUpdateAction
5661
| IApproveAction
5762
| IRejectAction
63+
| IFilterAction
5864
| ISelectAction;
5965

6066
type Dispatch = (action: IAction) => void;
6167
type State = {
6268
selectedTestRunId?: string;
69+
filteredTestRuns?: Array<TestRun>;
6370
testRuns: Array<TestRun>;
6471
loading: boolean;
6572
};
@@ -83,6 +90,11 @@ function testRunReducer(state: State, action: IAction): State {
8390
...state,
8491
selectedTestRunId: action.payload,
8592
};
93+
case "filter":
94+
return {
95+
...state,
96+
filteredTestRuns: action.payload,
97+
};
8698
case "request":
8799
return {
88100
...state,

0 commit comments

Comments
 (0)