asynqmon/ui/src/views/TasksView.tsx

79 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-01-24 13:37:45 -08:00
import React, { useEffect } from "react";
import { connect, ConnectedProps } from "react-redux";
2020-11-24 06:54:00 -08:00
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";
2021-01-24 13:37:45 -08:00
import QueueBreadCrumb from "../components/QueueBreadcrumb";
2020-11-24 06:54:00 -08:00
import { useParams, useLocation } from "react-router-dom";
2021-01-24 13:37:45 -08:00
import { listQueuesAsync } from "../actions/queuesActions";
import { AppState } from "../store";
function mapStateToProps(state: AppState) {
return {
queues: state.queues.data.map((q) => q.name),
};
}
const connector = connect(mapStateToProps, { listQueuesAsync });
2020-11-24 06:54:00 -08:00
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-24 13:37:45 -08:00
breadcrumbs: {
2021-01-23 22:36:19 -08:00
marginBottom: theme.spacing(2),
2020-11-24 06:54:00 -08:00
},
2021-01-24 13:37:45 -08:00
banner: {
marginBottom: theme.spacing(2),
},
tasksTable: {
2021-01-23 22:36:19 -08:00
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";
2021-01-24 13:37:45 -08:00
function TasksView(props: ConnectedProps<typeof connector>) {
2020-11-24 06:54:00 -08:00
const classes = useStyles();
const { qname } = useParams<RouteParams>();
const query = useQuery();
let selected = query.get("status");
if (!selected || !validStatus.includes(selected)) {
selected = defaultStatus;
}
2021-01-24 13:37:45 -08:00
const { listQueuesAsync } = props;
useEffect(() => {
listQueuesAsync();
}, [listQueuesAsync]);
2020-11-24 06:54:00 -08:00
return (
2021-01-23 22:36:19 -08:00
<Container maxWidth="lg">
<Grid container spacing={0} className={classes.container}>
2021-01-29 22:25:01 -08:00
<Grid item xs={12} className={classes.breadcrumbs}>
2021-01-24 13:37:45 -08:00
<QueueBreadCrumb queues={props.queues} selectedQueue={qname} />
</Grid>
<Grid item xs={12} className={classes.banner}>
2021-01-23 22:36:19 -08:00
<QueueInfoBanner qname={qname} />
</Grid>
2021-01-24 13:37:45 -08:00
<Grid item xs={12} className={classes.tasksTable}>
2020-11-24 06:54:00 -08:00
<TasksTable queue={qname} selected={selected} />
</Grid>
</Grid>
</Container>
);
}
2021-01-24 13:37:45 -08:00
export default connector(TasksView);