Use chip for task type selection

This commit is contained in:
Ken Hibino 2021-01-24 16:33:46 -08:00
parent 2b2d5f88a5
commit 7336a37555

View File

@ -1,10 +1,9 @@
import React from "react"; import React from "react";
import { connect, ConnectedProps } from "react-redux"; import { connect, ConnectedProps } from "react-redux";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
import Paper from "@material-ui/core/Paper"; import Paper from "@material-ui/core/Paper";
import Chip from "@material-ui/core/Chip";
import ActiveTasksTable from "./ActiveTasksTable"; import ActiveTasksTable from "./ActiveTasksTable";
import PendingTasksTable from "./PendingTasksTable"; import PendingTasksTable from "./PendingTasksTable";
import ScheduledTasksTable from "./ScheduledTasksTable"; import ScheduledTasksTable from "./ScheduledTasksTable";
@ -38,13 +37,6 @@ function TabPanel(props: TabPanelProps) {
); );
} }
function a11yProps(value: string) {
return {
id: `scrollable-auto-tab-${value}`,
"aria-controls": `scrollable-auto-tabpanel-${value}`,
};
}
function mapStatetoProps(state: AppState, ownProps: Props) { function mapStatetoProps(state: AppState, ownProps: Props) {
// TODO: Add loading state for each queue. // TODO: Add loading state for each queue.
const queueInfo = state.queues.data.find( const queueInfo = state.queues.data.find(
@ -83,46 +75,31 @@ const useStyles = makeStyles((theme) => ({
height: "100%", height: "100%",
background: theme.palette.background.paper, background: theme.palette.background.paper,
}, },
header: {
display: "flex",
alignItems: "center",
paddingTop: theme.spacing(1),
},
heading: { heading: {
paddingTop: theme.spacing(1), paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(1), paddingBottom: theme.spacing(1),
paddingLeft: theme.spacing(2), paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2), paddingRight: theme.spacing(2),
borderBottom: `1px solid ${theme.palette.divider}`,
}, },
tabsContainer: { chip: {
// background: marginLeft: theme.spacing(1),
// theme.palette.type === "dark"
// ? "#303030"
// : theme.palette.background.default,
}, },
tabsRoot: { taskcount: {
// background: fontSize: "12px",
// theme.palette.type === "dark" color: theme.palette.text.secondary,
// ? "#303030" background:
// : theme.palette.background.default, theme.palette.type === "dark"
}, ? "#303030"
tabsIndicator: { : theme.palette.background.default,
right: "auto",
left: "0",
},
tabroot: {
flexGrow: 1,
textAlign: "center", textAlign: "center",
padding: theme.spacing(2), padding: "3px 6px",
}, borderRadius: "10px",
tabwrapper: { marginLeft: "2px",
alignItems: "center",
color: theme.palette.text.primary,
},
tabSelected: {
background: theme.palette.background.paper,
},
panelContainer: {},
taskCount: {
fontSize: "2rem",
fontWeight: 600,
margin: 0,
}, },
})); }));
@ -130,109 +107,62 @@ function TasksTable(props: Props & ReduxProps) {
const { currentStats } = props; const { currentStats } = props;
const classes = useStyles(); const classes = useStyles();
const history = useHistory(); const history = useHistory();
const chips = [
{ key: "active", label: "Active", count: currentStats.active },
{ key: "pending", label: "Pending", count: currentStats.pending },
{ key: "scheduled", label: "Scheduled", count: currentStats.scheduled },
{ key: "retry", label: "Retry", count: currentStats.retry },
{ key: "archived", label: "Archived", count: currentStats.archived },
];
return ( return (
<Paper variant="outlined" className={classes.container}> <Paper variant="outlined" className={classes.container}>
<div className={classes.header}>
<Typography color="textPrimary" className={classes.heading}> <Typography color="textPrimary" className={classes.heading}>
Tasks list Tasks
</Typography> </Typography>
<div className={classes.tabsContainer}> <div>
<Tabs {chips.map((c) => (
value={props.selected} <Chip
onChange={(_, value: string) => className={classes.chip}
history.push(queueDetailsPath(props.queue, value)) label={
<div>
{c.label} <span className={classes.taskcount}>{c.count}</span>
</div>
} }
aria-label="tasks table" variant="outlined"
classes={{ root: classes.tabsRoot, indicator: classes.tabsIndicator }} color={props.selected === c.key ? "primary" : "default"}
> onClick={() => history.push(queueDetailsPath(props.queue, c.key))}
<Tab
value="active"
label={`Active (${currentStats.active})`}
classes={{
root: classes.tabroot,
wrapper: classes.tabwrapper,
selected: classes.tabSelected,
}}
{...a11yProps("active")}
/> />
<Tab ))}
value="pending" </div>
label={`Pending (${currentStats.pending})`}
classes={{
root: classes.tabroot,
wrapper: classes.tabwrapper,
selected: classes.tabSelected,
}}
{...a11yProps("pending")}
/>
<Tab
value="scheduled"
label={`Scheduled (${currentStats.scheduled})`}
classes={{
root: classes.tabroot,
wrapper: classes.tabwrapper,
selected: classes.tabSelected,
}}
{...a11yProps("scheduled")}
/>
<Tab
value="retry"
label={`Retry (${currentStats.retry})`}
classes={{
root: classes.tabroot,
wrapper: classes.tabwrapper,
selected: classes.tabSelected,
}}
{...a11yProps("retry")}
/>
<Tab
value="archived"
label={`Archived (${currentStats.archived})`}
classes={{
root: classes.tabroot,
wrapper: classes.tabwrapper,
selected: classes.tabSelected,
}}
{...a11yProps("archived")}
/>
</Tabs>
</div> </div>
<TabPanel value="active" selected={props.selected}> <TabPanel value="active" selected={props.selected}>
<div className={classes.panelContainer}>
<ActiveTasksTable queue={props.queue} /> <ActiveTasksTable queue={props.queue} />
</div>
</TabPanel> </TabPanel>
<TabPanel value="pending" selected={props.selected}> <TabPanel value="pending" selected={props.selected}>
<div className={classes.panelContainer}>
<PendingTasksTable <PendingTasksTable
queue={props.queue} queue={props.queue}
totalTaskCount={currentStats.pending} totalTaskCount={currentStats.pending}
/> />
</div>
</TabPanel> </TabPanel>
<TabPanel value="scheduled" selected={props.selected}> <TabPanel value="scheduled" selected={props.selected}>
<div className={classes.panelContainer}>
<ScheduledTasksTable <ScheduledTasksTable
queue={props.queue} queue={props.queue}
totalTaskCount={currentStats.scheduled} totalTaskCount={currentStats.scheduled}
/> />
</div>
</TabPanel> </TabPanel>
<TabPanel value="retry" selected={props.selected}> <TabPanel value="retry" selected={props.selected}>
<div className={classes.panelContainer}>
<RetryTasksTable <RetryTasksTable
queue={props.queue} queue={props.queue}
totalTaskCount={currentStats.retry} totalTaskCount={currentStats.retry}
/> />
</div>
</TabPanel> </TabPanel>
<TabPanel value="archived" selected={props.selected}> <TabPanel value="archived" selected={props.selected}>
<div className={classes.panelContainer}>
<ArchivedTasksTable <ArchivedTasksTable
queue={props.queue} queue={props.queue}
totalTaskCount={currentStats.archived} totalTaskCount={currentStats.archived}
/> />
</div>
</TabPanel> </TabPanel>
</Paper> </Paper>
); );