Periodically fetch task info from TaskDetailsView

This commit is contained in:
Ken Hibino
2021-07-19 16:48:46 -07:00
parent 0f1e5ec78b
commit a5759fa646
3 changed files with 29 additions and 4 deletions

View File

@@ -255,8 +255,8 @@ function tasksReducer(
return { return {
...state, ...state,
taskInfo: { taskInfo: {
...state.taskInfo,
loading: true, loading: true,
error: "",
}, },
} }

View File

@@ -1,10 +1,25 @@
import React from "react"; import React, { useMemo } from "react";
import { connect, ConnectedProps } from "react-redux";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import Container from "@material-ui/core/Container"; import Container from "@material-ui/core/Container";
import Grid from "@material-ui/core/Grid"; import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { AppState } from "../store";
import { getTaskInfoAsync } from "../actions/tasksActions";
import { TaskDetailsRouteParams } from "../paths"; import { TaskDetailsRouteParams } from "../paths";
import { usePolling } from "../hooks";
function mapStateToProps(state: AppState) {
return {
loading: state.tasks.taskInfo.loading,
error: state.tasks.taskInfo.error,
taskInfo: state.tasks.taskInfo.data,
pollInterval: state.settings.pollInterval,
};
}
const connector = connect(mapStateToProps, { getTaskInfoAsync });
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
container: { container: {
@@ -12,11 +27,20 @@ const useStyles = makeStyles((theme) => ({
}, },
})); }));
interface Props {} type Props = ConnectedProps<typeof connector>;
function TaskDetailsView(props: Props) { function TaskDetailsView(props: Props) {
const classes = useStyles(); const classes = useStyles();
const { qname, taskId } = useParams<TaskDetailsRouteParams>(); const { qname, taskId } = useParams<TaskDetailsRouteParams>();
const { getTaskInfoAsync, pollInterval } = props;
const fetchTaskInfo = useMemo(() => {
return () => {
getTaskInfoAsync(qname, taskId);
};
}, [qname, taskId, getTaskInfoAsync]);
usePolling(fetchTaskInfo, pollInterval);
return ( return (
<Container maxWidth="lg" className={classes.container}> <Container maxWidth="lg" className={classes.container}>
@@ -31,4 +55,4 @@ function TaskDetailsView(props: Props) {
); );
} }
export default TaskDetailsView; export default connector(TaskDetailsView);

View File

@@ -51,6 +51,7 @@ function TasksView(props: ConnectedProps<typeof connector>) {
} }
const { listQueuesAsync } = props; const { listQueuesAsync } = props;
// Shoudn't we polling here?
useEffect(() => { useEffect(() => {
listQueuesAsync(); listQueuesAsync();
}, [listQueuesAsync]); }, [listQueuesAsync]);