From 95bb6051d00d3ad594eba64badf1cb49fd67de3b Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Fri, 18 Dec 2020 06:48:00 -0800 Subject: [PATCH] Add checkbox column to tables --- ui/src/components/DeadTasksTable.tsx | 7 ++-- ui/src/components/RetryTasksTable.tsx | 47 ++++++++++++++++++++++- ui/src/components/ScheduledTasksTable.tsx | 47 ++++++++++++++++++++++- 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/ui/src/components/DeadTasksTable.tsx b/ui/src/components/DeadTasksTable.tsx index 78857d4..e20026f 100644 --- a/ui/src/components/DeadTasksTable.tsx +++ b/ui/src/components/DeadTasksTable.tsx @@ -241,7 +241,9 @@ function DeadTasksTable(props: Props & ReduxProps) { indeterminate={numSelected > 0 && numSelected < rowCount} checked={rowCount > 0 && numSelected === rowCount} onChange={handleSelectAllClick} - inputProps={{ "aria-label": "select all dead tasks" }} + inputProps={{ + "aria-label": "select all tasks shown in the table", + }} /> {columns.map((col) => ( @@ -311,8 +313,6 @@ function Row(props: RowProps) { const { task } = props; const [open, setOpen] = useState(false); const classes = useRowStyles(); - - const labelId = `dead-tasks-table-checkbox-${task.id}`; return ( @@ -322,7 +322,6 @@ function Row(props: RowProps) { props.onSelectChange(event.target.checked) } checked={props.isSelected} - inputProps={{ "aria-labelledby": labelId }} /> diff --git a/ui/src/components/RetryTasksTable.tsx b/ui/src/components/RetryTasksTable.tsx index 97170c7..f845e41 100644 --- a/ui/src/components/RetryTasksTable.tsx +++ b/ui/src/components/RetryTasksTable.tsx @@ -12,6 +12,7 @@ import TableFooter from "@material-ui/core/TableFooter"; import TablePagination from "@material-ui/core/TablePagination"; import Paper from "@material-ui/core/Paper"; import Box from "@material-ui/core/Box"; +import Checkbox from "@material-ui/core/Checkbox"; import Collapse from "@material-ui/core/Collapse"; import IconButton from "@material-ui/core/IconButton"; import KeyboardArrowUpIcon from "@material-ui/icons/KeyboardArrowUp"; @@ -64,6 +65,7 @@ function RetryTasksTable(props: Props & ReduxProps) { const classes = useStyles(); const [page, setPage] = useState(0); const [pageSize, setPageSize] = useState(defaultPageSize); + const [selectedKeys, setSelectedKeys] = useState([]); const handleChangePage = ( event: React.MouseEvent | null, @@ -79,6 +81,15 @@ function RetryTasksTable(props: Props & ReduxProps) { setPage(0); }; + const handleSelectAllClick = (event: React.ChangeEvent) => { + if (event.target.checked) { + const newSelected = props.tasks.map((t) => t.key); + setSelectedKeys(newSelected); + } else { + setSelectedKeys([]); + } + }; + const fetchData = useCallback(() => { const pageOpts = { page: page + 1, size: pageSize }; listRetryTasksAsync(queue, pageOpts); @@ -106,6 +117,8 @@ function RetryTasksTable(props: Props & ReduxProps) { { label: "Actions" }, ]; + const rowCount = props.tasks.length; + const numSelected = selectedKeys.length; return ( + + 0 && numSelected < rowCount} + checked={rowCount > 0 && numSelected === rowCount} + onChange={handleSelectAllClick} + inputProps={{ + "aria-label": "select all tasks shown in the table", + }} + /> + {columns.map((col) => ( {col.label} ))} @@ -126,6 +149,16 @@ function RetryTasksTable(props: Props & ReduxProps) { { + if (checked) { + setSelectedKeys(selectedKeys.concat(task.key)); + } else { + setSelectedKeys( + selectedKeys.filter((key) => key !== task.key) + ); + } + }} onDeleteClick={() => { props.deleteRetryTaskAsync(task.queue, task.key); }} @@ -136,7 +169,7 @@ function RetryTasksTable(props: Props & ReduxProps) { void; onDeleteClick: () => void; } @@ -175,6 +210,14 @@ function Row(props: RowProps) { return ( + + ) => + props.onSelectChange(event.target.checked) + } + checked={props.isSelected} + /> + - + diff --git a/ui/src/components/ScheduledTasksTable.tsx b/ui/src/components/ScheduledTasksTable.tsx index ed6954f..0228b4e 100644 --- a/ui/src/components/ScheduledTasksTable.tsx +++ b/ui/src/components/ScheduledTasksTable.tsx @@ -12,6 +12,7 @@ import TableFooter from "@material-ui/core/TableFooter"; import TablePagination from "@material-ui/core/TablePagination"; import Paper from "@material-ui/core/Paper"; import Box from "@material-ui/core/Box"; +import Checkbox from "@material-ui/core/Checkbox"; import Collapse from "@material-ui/core/Collapse"; import IconButton from "@material-ui/core/IconButton"; import KeyboardArrowUpIcon from "@material-ui/icons/KeyboardArrowUp"; @@ -67,6 +68,7 @@ function ScheduledTasksTable(props: Props & ReduxProps) { const classes = useStyles(); const [page, setPage] = useState(0); const [pageSize, setPageSize] = useState(defaultPageSize); + const [selectedKeys, setSelectedKeys] = useState([]); const handleChangePage = ( event: React.MouseEvent | null, @@ -82,6 +84,15 @@ function ScheduledTasksTable(props: Props & ReduxProps) { setPage(0); }; + const handleSelectAllClick = (event: React.ChangeEvent) => { + if (event.target.checked) { + const newSelected = props.tasks.map((t) => t.key); + setSelectedKeys(newSelected); + } else { + setSelectedKeys([]); + } + }; + const fetchData = useCallback(() => { const pageOpts = { page: page + 1, size: pageSize }; listScheduledTasksAsync(queue, pageOpts); @@ -106,6 +117,8 @@ function ScheduledTasksTable(props: Props & ReduxProps) { { label: "Actions" }, ]; + const rowCount = props.tasks.length; + const numSelected = selectedKeys.length; return (
+ + 0 && numSelected < rowCount} + checked={rowCount > 0 && numSelected === rowCount} + onChange={handleSelectAllClick} + inputProps={{ + "aria-label": "select all tasks shown in the table", + }} + /> + {columns.map((col) => ( {col.label} ))} @@ -126,6 +149,16 @@ function ScheduledTasksTable(props: Props & ReduxProps) { { + if (checked) { + setSelectedKeys(selectedKeys.concat(task.key)); + } else { + setSelectedKeys( + selectedKeys.filter((key) => key !== task.key) + ); + } + }} onDeleteClick={() => { props.deleteScheduledTaskAsync(queue, task.key); }} @@ -136,7 +169,7 @@ function ScheduledTasksTable(props: Props & ReduxProps) { void; onDeleteClick: () => void; } @@ -175,6 +210,14 @@ function Row(props: RowProps) { return ( + + ) => + props.onSelectChange(event.target.checked) + } + checked={props.isSelected} + /> + - +