import React from "react"; import { connect, ConnectedProps } from "react-redux"; import styled from "styled-components"; import { makeStyles } from "@material-ui/core/styles"; import Tabs from "@material-ui/core/Tabs"; import Tab from "@material-ui/core/Tab"; import ActiveTasksTable from "./ActiveTasksTable"; import PendingTasksTable from "./PendingTasksTable"; import ScheduledTasksTable from "./ScheduledTasksTable"; import RetryTasksTable from "./RetryTasksTable"; import DeadTasksTable from "./DeadTasksTable"; import { useHistory } from "react-router-dom"; import { queueDetailsPath } from "../paths"; import { Typography } from "@material-ui/core"; import Paper from "@material-ui/core/Paper/Paper"; import { QueueInfo } from "../reducers/queuesReducer"; import { AppState } from "../store"; interface TabPanelProps { children?: React.ReactNode; selected: string; // currently selected value value: string; // tab panel will be shown if selected value equals to the value } const TabPanelRoot = styled.div` flex: 1; overflow-y: scroll; `; function TabPanel(props: TabPanelProps) { const { children, value, selected, ...other } = props; return ( ); } function a11yProps(value: string) { return { id: `scrollable-auto-tab-${value}`, "aria-controls": `scrollable-auto-tabpanel-${value}`, }; } const Container = styled.div` display: flex; width: 100%; height: 100%; `; const TaskCount = styled.div` font-size: 2rem; font-weight: 600; margin: 0; `; const Heading = styled.div` opacity: 0.7; font-size: 1.7rem; font-weight: 500; background: #f5f7f9; padding-left: 28px; padding-top: 28px; padding-bottom: 28px; `; const PanelContainer = styled.div` padding: 24px; background: #ffffff; `; const TabsContainer = styled.div` background: #f5f7f9; `; const useStyles = makeStyles((theme) => ({ paper: { padding: theme.spacing(2), marginBottom: theme.spacing(2), display: "flex", justifyContent: "space-between", }, heading: { padingLeft: theme.spacing(2), }, tabsRoot: { paddingLeft: theme.spacing(2), background: theme.palette.background.default, }, tabsIndicator: { right: "auto", left: "0", }, tabroot: { width: "204px", textAlign: "left", padding: theme.spacing(2), }, tabwrapper: { alignItems: "flex-start", }, tabSelected: { background: theme.palette.common.white, boxShadow: theme.shadows[1], }, })); function PanelHeading(props: { queue: string; processed: number; failed: number; paused: boolean; }) { const classes = useStyles(); return (
Queue Name {props.queue}
Processed Today (UTC) {props.processed}
Failed Today (UTC) {props.failed}
Paused {props.paused ? "YES" : "No"}
); } function mapStatetoProps(state: AppState, ownProps: Props) { // TODO: Add loading state for each queue. const queueInfo = state.queues.data.find( (q: QueueInfo) => q.name === ownProps.queue ); const currentStats = queueInfo ? queueInfo.currentStats : { queue: ownProps.queue, paused: false, size: 0, active: 0, pending: 0, scheduled: 0, retry: 0, dead: 0, processed: 0, failed: 0, timestamp: "n/a", }; return { currentStats }; } const connector = connect(mapStatetoProps); type ReduxProps = ConnectedProps; interface Props { queue: string; selected: string; } function TasksTable(props: Props & ReduxProps) { const { currentStats } = props; const classes = useStyles(); const history = useHistory(); return ( Tasks history.push(queueDetailsPath(props.queue, value)) } aria-label="tasks table" orientation="vertical" classes={{ root: classes.tabsRoot, indicator: classes.tabsIndicator }} > {currentStats.active}} classes={{ root: classes.tabroot, wrapper: classes.tabwrapper, selected: classes.tabSelected, }} {...a11yProps("active")} /> {currentStats.pending}} classes={{ root: classes.tabroot, wrapper: classes.tabwrapper, selected: classes.tabSelected, }} {...a11yProps("pending")} /> {currentStats.scheduled}} classes={{ root: classes.tabroot, wrapper: classes.tabwrapper, selected: classes.tabSelected, }} {...a11yProps("scheduled")} /> {currentStats.retry}} classes={{ root: classes.tabroot, wrapper: classes.tabwrapper, selected: classes.tabSelected, }} {...a11yProps("retry")} /> {currentStats.dead}} classes={{ root: classes.tabroot, wrapper: classes.tabwrapper, selected: classes.tabSelected, }} {...a11yProps("dead")} /> ); } export default connector(TasksTable);