asynqmon/ui/src/views/TasksView.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-11-24 06:54:00 -08:00
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Container from "@material-ui/core/Container";
import Grid from "@material-ui/core/Grid";
import TasksTable from "../components/TasksTable";
2021-01-23 22:36:19 -08:00
import QueueInfoBanner from "../components/QueueInfoBanner";
2020-11-24 06:54:00 -08:00
import { useParams, useLocation } from "react-router-dom";
const useStyles = makeStyles((theme) => ({
container: {
2021-01-23 22:36:19 -08:00
paddingTop: theme.spacing(2),
2020-11-24 06:54:00 -08:00
},
2021-01-23 22:36:19 -08:00
bannerContainer: {
marginBottom: theme.spacing(2),
2020-11-24 06:54:00 -08:00
},
2021-01-23 22:36:19 -08:00
taskTableContainer: {
marginBottom: theme.spacing(4),
2020-11-24 06:54:00 -08:00
},
}));
function useQuery(): URLSearchParams {
return new URLSearchParams(useLocation().search);
}
interface RouteParams {
qname: string;
}
const validStatus = ["active", "pending", "scheduled", "retry", "archived"];
2020-11-24 06:54:00 -08:00
const defaultStatus = "active";
function TasksView() {
const classes = useStyles();
const { qname } = useParams<RouteParams>();
const query = useQuery();
let selected = query.get("status");
if (!selected || !validStatus.includes(selected)) {
selected = defaultStatus;
}
return (
2021-01-23 22:36:19 -08:00
<Container maxWidth="lg">
<Grid container spacing={0} className={classes.container}>
<Grid item xs={12} className={classes.bannerContainer}>
<QueueInfoBanner qname={qname} />
</Grid>
<Grid item xs={12} className={classes.taskTableContainer}>
2020-11-24 06:54:00 -08:00
<TasksTable queue={qname} selected={selected} />
</Grid>
</Grid>
</Container>
);
}
export default TasksView;