From 3ab1ed31a6468e4d8f0f103b3def7d3f05f82722 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Tue, 22 Dec 2020 05:49:39 -0800 Subject: [PATCH] Redesign TableActions component to be more generic --- ui/src/components/DeadTasksTable.tsx | 36 +++++++-- ui/src/components/RetryTasksTable.tsx | 50 +++++++++--- ui/src/components/ScheduledTasksTable.tsx | 50 +++++++++--- ui/src/components/TableActions.tsx | 95 +++++++---------------- 4 files changed, 139 insertions(+), 92 deletions(-) diff --git a/ui/src/components/DeadTasksTable.tsx b/ui/src/components/DeadTasksTable.tsx index 11b2778..ff069c1 100644 --- a/ui/src/components/DeadTasksTable.tsx +++ b/ui/src/components/DeadTasksTable.tsx @@ -13,6 +13,8 @@ import Paper from "@material-ui/core/Paper"; import Box from "@material-ui/core/Box"; import Collapse from "@material-ui/core/Collapse"; import IconButton from "@material-ui/core/IconButton"; +import PlayArrowIcon from "@material-ui/icons/PlayArrow"; +import DeleteIcon from "@material-ui/icons/Delete"; import KeyboardArrowUpIcon from "@material-ui/icons/KeyboardArrowUp"; import KeyboardArrowDownIcon from "@material-ui/icons/KeyboardArrowDown"; import Typography from "@material-ui/core/Typography"; @@ -164,13 +166,33 @@ function DeadTasksTable(props: Props & ReduxProps) { return (
0} - onRunAllClick={handleRunAllClick} - onDeleteAllClick={handleDeleteAllClick} - onBatchRunClick={handleBatchRunClick} - onBatchDeleteClick={handleBatchDeleteClick} + showIconButtons={numSelected > 0} + iconButtonActions={[ + { + tooltip: "Delete", + icon: , + onClick: handleBatchDeleteClick, + disabled: props.batchActionPending, + }, + { + tooltip: "Run", + icon: , + onClick: handleBatchRunClick, + disabled: props.batchActionPending, + }, + ]} + menuItemActions={[ + { + label: "Delete All", + onClick: handleDeleteAllClick, + disabled: props.allActionPending, + }, + { + label: "Run All", + onClick: handleRunAllClick, + disabled: props.allActionPending, + }, + ]} /> 0} - onRunAllClick={handleRunAllClick} - onDeleteAllClick={handleDeleteAllClick} - onKillAllClick={handleKillAllClick} - onBatchRunClick={handleBatchRunClick} - onBatchDeleteClick={handleBatchDeleteClick} - onBatchKillClick={handleBatchKillClick} + showIconButtons={numSelected > 0} + iconButtonActions={[ + { + tooltip: "Delete", + icon: , + onClick: handleBatchDeleteClick, + disabled: props.batchActionPending, + }, + { + tooltip: "Kill", + icon: , + onClick: handleBatchKillClick, + disabled: props.batchActionPending, + }, + { + tooltip: "Run", + icon: , + onClick: handleBatchRunClick, + disabled: props.batchActionPending, + }, + ]} + menuItemActions={[ + { + label: "Delete All", + onClick: handleDeleteAllClick, + disabled: props.allActionPending, + }, + { + label: "Kill All", + onClick: handleKillAllClick, + disabled: props.allActionPending, + }, + { + label: "Run All", + onClick: handleRunAllClick, + disabled: props.allActionPending, + }, + ]} />
0} - onRunAllClick={handleRunAllClick} - onKillAllClick={handleKillAllClick} - onDeleteAllClick={handleDeleteAllClick} - onBatchRunClick={handleBatchRunClick} - onBatchDeleteClick={handleBatchDeleteClick} - onBatchKillClick={handleBatchKillClick} + showIconButtons={numSelected > 0} + iconButtonActions={[ + { + tooltip: "Delete", + icon: , + onClick: handleBatchDeleteClick, + disabled: props.batchActionPending, + }, + { + tooltip: "Kill", + icon: , + onClick: handleBatchKillClick, + disabled: props.batchActionPending, + }, + { + tooltip: "Run", + icon: , + onClick: handleBatchRunClick, + disabled: props.batchActionPending, + }, + ]} + menuItemActions={[ + { + label: "Delete All", + onClick: handleDeleteAllClick, + disabled: props.allActionPending, + }, + { + label: "Kill All", + onClick: handleKillAllClick, + disabled: props.allActionPending, + }, + { + label: "Run All", + onClick: handleRunAllClick, + disabled: props.allActionPending, + }, + ]} />
({ }, })); +interface MenuItemAction { + label: string; + onClick: () => void; + disabled: boolean; +} + +interface IconButtonAction { + icon: React.ReactElement; + tooltip: string; + onClick: () => void; + disabled: boolean; +} + interface Props { - allActionPending: boolean; - onRunAllClick: () => void; - onDeleteAllClick: () => void; - onKillAllClick?: () => void; - showBatchActions: boolean; - batchActionPending: boolean; - onBatchRunClick: () => void; - onBatchDeleteClick: () => void; - onBatchKillClick?: () => void; + menuItemActions: MenuItemAction[]; + iconButtonActions: IconButtonAction[]; + showIconButtons: boolean; } export default function TableActions(props: Props) { @@ -63,68 +67,25 @@ export default function TableActions(props: Props) { open={Boolean(menuAnchor)} onClose={closeMenu} > - { - props.onRunAllClick(); - closeMenu(); - }} - disabled={props.allActionPending} - > - Run All - - {props.onKillAllClick && ( + {props.menuItemActions.map((action) => ( { - if (!props.onKillAllClick) return; - props.onKillAllClick(); - closeMenu(); - }} - disabled={props.allActionPending} + key={action.label} + onClick={action.onClick} + disabled={action.disabled} > - Kill All + {action.label} - )} - { - props.onDeleteAllClick(); - closeMenu(); - }} - disabled={props.allActionPending} - > - Delete All - + ))} - {props.showBatchActions && ( + {props.showIconButtons && (
- {props.onBatchKillClick && ( - - { - if (!props.onBatchKillClick) return; - props.onBatchKillClick(); - }} - > - + {props.iconButtonActions.map((action) => ( + + + {action.icon} - )} - - - - - - - - - - + ))}
)}