Skip to content

Commit 148195e

Browse files
committed
RunList: Show filters in 3 sections
Show the RunList custom filter in 3 sections: build details, run details, result details. This commit also does the following: 1. Hides the default filter icon from table 2. Hides filter icon present in filtered columns Signed-off-by: Vallari Agrawal <[email protected]>
1 parent 07b1729 commit 148195e

File tree

1 file changed

+68
-26
lines changed

1 file changed

+68
-26
lines changed

src/components/RunList/index.tsx

+68-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type MRT_Updater,
1919
type MRT_ColumnFiltersState,
2020
type MRT_TableOptions,
21+
type MRT_TableInstance,
2122
} from 'material-react-table';
2223
import { type Theme } from "@mui/material/styles";
2324
import { parse } from "date-fns";
@@ -35,21 +36,15 @@ import {
3536
RunStatuses,
3637
} from "../../lib/paddles.d";
3738
import useDefaultTableOptions from "../../lib/table";
39+
import Typography from '@mui/material/Typography';
40+
import Box from '@mui/material/Box';
3841

3942

4043
const DEFAULT_PAGE_SIZE = 25;
4144
const NON_FILTER_PARAMS = [
4245
"page",
4346
"pageSize",
4447
];
45-
const FILTER_COLUMNS = [
46-
"status",
47-
"scheduled",
48-
"suite",
49-
"branch",
50-
"machine_type",
51-
"sha1",
52-
]
5348

5449
const _columns: MRT_ColumnDef<Run>[] = [
5550
{
@@ -289,6 +284,7 @@ export default function RunList(props: RunListProps) {
289284
},
290285
onColumnFiltersChange,
291286
columnFilterDisplayMode: 'custom',
287+
enableColumnFilters: false,
292288
muiFilterTextFieldProps: ({ column }) => ({
293289
label: `Filter by ${column.columnDef.header}`,
294290
}),
@@ -321,30 +317,76 @@ export default function RunList(props: RunListProps) {
321317
if (query.isError) return null;
322318
return (
323319
<div>
324-
{ openFilterMenu? (
325-
<Grid container spacing={3} style={{padding: "10px"}}>
320+
<Button onClick={toggleFilterMenu(!openFilterMenu)} >
321+
{openFilterMenu ? "Hide": "Show"} Filters
322+
</Button>
323+
<FilterMenu isOpen={openFilterMenu} table={table} />
324+
<MaterialReactTable table={table} />
325+
</div>
326+
)
327+
}
328+
329+
330+
// FilterMenu
331+
332+
type FilterMenuProps = {
333+
isOpen: boolean;
334+
table: MRT_TableInstance<Run>;
335+
};
336+
337+
338+
const FILTER_SECTIONS = ["run", "build", "result"]
339+
const FILTER_SECTIONS_COLUMNS = [
340+
["scheduled", "suite", "machine_type"],
341+
["branch", "sha1"],
342+
["status"],
343+
]
344+
345+
function FilterMenu({ isOpen, table}: FilterMenuProps) {
346+
if (!isOpen) {
347+
return null;
348+
}
349+
350+
return (
351+
<Box
352+
sx={{
353+
padding: '0.5em',
354+
margin: '1em',
355+
border: '2px dashed grey',
356+
borderRadius: '8px',
357+
maxWidth: '100%',
358+
}}
359+
>
360+
{FILTER_SECTIONS_COLUMNS.map((_, sectionIndex) => (
361+
<Box
362+
key={`section-${sectionIndex}`}
363+
sx={{
364+
marginBottom: '1.5em',
365+
paddingBottom: '0.5em',
366+
marginLeft: '0.5em',
367+
}}
368+
>
369+
<Typography variant="body2" gutterBottom color="gray">
370+
Filter by {FILTER_SECTIONS[sectionIndex]} details...
371+
</Typography>
372+
<Grid container spacing={1} alignItems="center">
326373
{table.getLeafHeaders().map((header) => {
327-
console.log(header.id)
328-
if (FILTER_COLUMNS.includes(header.id)) {
374+
if (FILTER_SECTIONS_COLUMNS[sectionIndex].includes(header.id)) {
329375
return (
330-
<Grid item xs={2}>
376+
<Grid item xs={2} key={header.id} marginLeft={"1.5em"}>
331377
<MRT_TableHeadCellFilterContainer
332-
key={header.id}
333378
header={header}
334379
table={table}
335-
style={{backgroundColor: "None"}}
336-
in
380+
style={{ backgroundColor: 'transparent', width: '100%' }}
337381
/>
338382
</Grid>
339-
)
340-
}
383+
);
384+
}
385+
return null;
341386
})}
342-
</Grid>)
343-
: ""}
344-
<Button onClick={toggleFilterMenu(!openFilterMenu)} >
345-
{openFilterMenu ? "Hide": "Show"} Filters
346-
</Button>
347-
<MaterialReactTable table={table} />
348-
</div>
349-
)
387+
</Grid>
388+
</Box>
389+
))}
390+
</Box>
391+
)
350392
}

0 commit comments

Comments
 (0)