Skip to content

Commit 4cdaf4c

Browse files
authored
1 parent 843bf05 commit 4cdaf4c

File tree

5 files changed

+147
-13
lines changed

5 files changed

+147
-13
lines changed

src/components/BuildList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,4 @@ const BuildList: FunctionComponent = () => {
318318
);
319319
};
320320

321-
export default BuildList;
321+
export default React.memo(BuildList);

src/components/TestRunList/DataGridCustomToolbar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from "react";
22
import { Toolbar, Box } from "@material-ui/core";
3-
import { BaseComponentProps, DensitySelector } from "@material-ui/data-grid";
3+
import {
4+
BaseComponentProps,
5+
DensitySelector,
6+
FilterToolbarButton,
7+
} from "@material-ui/data-grid";
48
import { BulkDeleteButton } from "./BulkDeleteButton";
59

610
export const DataGridCustomToolbar: React.FunctionComponent<BaseComponentProps> = (
@@ -9,6 +13,7 @@ export const DataGridCustomToolbar: React.FunctionComponent<BaseComponentProps>
913
return (
1014
<>
1115
<Toolbar variant="dense">
16+
<FilterToolbarButton />
1217
<DensitySelector />
1318
<Box marginLeft="auto">
1419
<BulkDeleteButton {...props} />
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { FormControl, InputLabel, Select } from "@material-ui/core";
2+
import React from "react";
3+
import { useTestRunState } from "../../contexts";
4+
import {
5+
FilterInputValueProps,
6+
getStringOperators,
7+
} from "@material-ui/data-grid";
8+
import { TestStatus } from "../../types";
9+
10+
const StatusInputComponent = (props: FilterInputValueProps) => {
11+
const { item, applyValue } = props;
12+
const { testRuns } = useTestRunState();
13+
14+
const handleFilterChange = (event: any) => {
15+
applyValue({ ...item, value: event.target.value as string });
16+
};
17+
18+
const filterOptions: Array<TestStatus> = Array.from(
19+
new Set(testRuns.map((item) => item.status))
20+
);
21+
22+
return (
23+
<FormControl fullWidth>
24+
<InputLabel shrink id="statusFilter">
25+
Value
26+
</InputLabel>
27+
<Select
28+
id="statusFilter"
29+
native
30+
displayEmpty
31+
value={item.value}
32+
onChange={handleFilterChange}
33+
>
34+
<option aria-label="All" value="" />
35+
{filterOptions.map((item) => (
36+
<option key={item} value={item}>
37+
{item}
38+
</option>
39+
))}
40+
</Select>
41+
</FormControl>
42+
);
43+
};
44+
45+
export const StatusFilterOperators = getStringOperators()
46+
.filter((operator) => operator.value === "equals")
47+
.map((operator) => ({
48+
...operator,
49+
InputComponent: StatusInputComponent,
50+
}));
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { FormControl, InputLabel, Select } from "@material-ui/core";
2+
import React from "react";
3+
import { useTestRunState } from "../../contexts";
4+
import {
5+
FilterInputValueProps,
6+
getStringOperators,
7+
} from "@material-ui/data-grid";
8+
9+
const TagInputComponent = (props: FilterInputValueProps) => {
10+
const { item, applyValue } = props;
11+
const { testRuns } = useTestRunState();
12+
13+
const handleFilterChange = (event: any) => {
14+
applyValue({ ...item, value: event.target.value as string });
15+
};
16+
17+
const filterOptions: Array<string> = Array.from(
18+
new Set(
19+
testRuns
20+
.map((item) => item.os)
21+
.concat(testRuns.map((item) => item.browser))
22+
.concat(testRuns.map((item) => item.device))
23+
.concat(testRuns.map((item) => item.viewport))
24+
)
25+
);
26+
27+
return (
28+
<FormControl fullWidth>
29+
<InputLabel shrink id="tagFilter">
30+
Value
31+
</InputLabel>
32+
<Select
33+
id="tagFilter"
34+
native
35+
displayEmpty
36+
value={item.value}
37+
onChange={handleFilterChange}
38+
>
39+
<option aria-label="All" value="" />
40+
{filterOptions.map(
41+
(item) =>
42+
item && (
43+
<option key={item} value={item}>
44+
{item}
45+
</option>
46+
)
47+
)}
48+
</Select>
49+
</FormControl>
50+
);
51+
};
52+
53+
export const TagFilterOperators = getStringOperators()
54+
.filter((operator) => operator.value === "contains")
55+
.map((operator) => ({
56+
...operator,
57+
InputComponent: TagInputComponent,
58+
}));

src/components/TestRunList/index.tsx

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,57 @@ import {
1717
CellParams,
1818
} from "@material-ui/data-grid";
1919
import { DataGridCustomToolbar } from "./DataGridCustomToolbar";
20+
import { StatusFilterOperators } from "./StatusFilterOperators";
21+
import { TagFilterOperators } from "./TagFilterOperators";
2022

21-
const columns: ColDef[] = [
22-
{ field: "id", hide: true },
23+
const columnsDef: ColDef[] = [
24+
{ field: "id", hide: true, filterable: false },
2325
{ field: "name", headerName: "Name", flex: 1 },
2426
{
2527
field: "tags",
2628
headerName: "Tags",
2729
flex: 1,
28-
renderCell: (params: CellParams) => {
29-
const tags = [
30+
valueGetter: (params: CellParams) => {
31+
const tags: Array<string> = [
3032
params.row["os"],
3133
params.row["device"],
3234
params.row["browser"],
3335
params.row["viewport"],
3436
];
35-
return (
36-
<>
37-
{tags.map(
38-
(tag) => tag && <Chip key={tag} size="small" label={tag} />
39-
)}
40-
</>
37+
return tags.reduce(
38+
(prev, curr) => prev.concat(curr ? `${curr};` : ""),
39+
""
4140
);
4241
},
42+
renderCell: (params: CellParams) => (
43+
<React.Fragment>
44+
{params
45+
.getValue("tags")
46+
?.toString()
47+
.split(";")
48+
.map(
49+
(tag) =>
50+
tag && (
51+
<Chip
52+
key={tag}
53+
size="small"
54+
label={tag}
55+
style={{ margin: "1px" }}
56+
/>
57+
)
58+
)}
59+
</React.Fragment>
60+
),
61+
filterOperators: TagFilterOperators,
4362
},
4463
{
4564
field: "status",
4665
headerName: "Status",
66+
flex: 0.3,
4767
renderCell: (params: CellParams) => {
4868
return <TestStatusChip status={params.getValue("status")?.toString()} />;
4969
},
70+
filterOperators: StatusFilterOperators,
5071
},
5172
];
5273

@@ -76,7 +97,7 @@ const TestRunList: React.FunctionComponent = () => {
7697
<React.Fragment>
7798
<DataGrid
7899
rows={testRuns}
79-
columns={columns}
100+
columns={columnsDef}
80101
pageSize={10}
81102
rowsPerPageOptions={[10, 20, 30]}
82103
loading={loading}

0 commit comments

Comments
 (0)