diff --git a/ui/src/api.ts b/ui/src/api.ts index ac1a7ab..215400e 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -300,6 +300,7 @@ export interface TaskInfo { next_process_at: string; timeout_seconds: number; deadline: string; + group: string; completed_at: string; result: string; ttl_seconds: number; diff --git a/ui/src/components/TaskGroupsTable.tsx b/ui/src/components/TaskGroupsTable.tsx index 8998f5a..6743b31 100644 --- a/ui/src/components/TaskGroupsTable.tsx +++ b/ui/src/components/TaskGroupsTable.tsx @@ -33,6 +33,7 @@ import TablePaginationActions, { rowsPerPageOptions, } from "./TablePaginationActions"; import { listAggregatingTasksAsync } from "../actions/tasksActions"; +import { taskRowsPerPageChange } from "../actions/settingsActions"; const useStyles = makeStyles((theme) => ({ groupSelector: { @@ -60,6 +61,9 @@ function mapStateToProps(state: AppState) { return { groups: state.groups.data, groupsError: state.groups.error, + loading: state.tasks.aggregatingTasks.loading, + group: state.tasks.aggregatingTasks.group, + tasks: state.tasks.aggregatingTasks.data, pollInterval: state.settings.pollInterval, pageSize: state.settings.taskRowsPerPage, }; @@ -68,6 +72,7 @@ function mapStateToProps(state: AppState) { const mapDispatchToProps = { listGroupsAsync, listAggregatingTasksAsync, + taskRowsPerPageChange, }; const connector = connect(mapStateToProps, mapDispatchToProps); @@ -80,12 +85,10 @@ const columns: TableColumn[] = [ { key: "id", label: "ID", align: "left" }, { key: "type", label: "Type", align: "left" }, { key: "paylod", label: "Payload", align: "left" }, + { key: "group", label: "Group", align: "left" }, { key: "actions", label: "Actions", align: "center" }, ]; -// TODO: remove this once we read the real data. -const dummyTasks: TaskInfoExtended[] = []; - function TaskGroupsTable(props: Props & ConnectedProps) { const [selectedGroup, setSelectedGroup] = React.useState( null @@ -102,6 +105,29 @@ function TaskGroupsTable(props: Props & ConnectedProps) { } = props; const classes = useStyles(); + const handlePageChange = ( + event: React.MouseEvent | null, + newPage: number + ) => { + setPage(newPage); + }; + + const handleRowsPerPageChange = ( + event: React.ChangeEvent + ) => { + props.taskRowsPerPageChange(parseInt(event.target.value, 10)); + setPage(0); + }; + + const handleSelectAllClick = (event: React.ChangeEvent) => { + if (event.target.checked) { + const newSelected = props.tasks.map((t) => t.id); + setSelectedIds(newSelected); + } else { + setSelectedIds([]); + } + }; + const fetchGroups = useCallback(() => { listGroupsAsync(queue); }, [listGroupsAsync, queue]); @@ -116,7 +142,7 @@ function TaskGroupsTable(props: Props & ConnectedProps) { usePolling(fetchGroups, pollInterval); usePolling(fetchTasks, pollInterval); - const rowCount = 0; // TODO: props.tasks.length; + const rowCount = props.tasks.length; const numSelected = selectedIds.length; return (
@@ -177,7 +203,7 @@ function TaskGroupsTable(props: Props & ConnectedProps) { 0 && numSelected < rowCount} checked={rowCount > 0 && numSelected === rowCount} - onChange={() => {} /*TODO: handleSelectAllClick*/} + onChange={handleSelectAllClick} inputProps={{ "aria-label": "select all tasks shown in the table", }} @@ -204,8 +230,8 @@ function TaskGroupsTable(props: Props & ConnectedProps) { - { - /*props.tasks */ dummyTasks.map((task) => ( + {props.group === selectedGroup?.group && + props.tasks.map((task) => ( ) { onArchiveClick={() => { // TODO: props.archivePendingTaskAsync(queue, task.id); }} - onActionCellEnter={() => {} /*setActiveTaskId(task.id) */} - onActionCellLeave={() => {} /*setActiveTaskId("")*/} - showActions={false /*activeTaskId === task.id*/} + onActionCellEnter={() => setActiveTaskId(task.id)} + onActionCellLeave={() => setActiveTaskId("")} + showActions={activeTaskId === task.id} /> - )) - } + ))} {} /* handlePageChange */} - onRowsPerPageChange={() => {} /* handleRowsPerPageChange */} + onPageChange={handlePageChange} + onRowsPerPageChange={handleRowsPerPageChange} ActionsComponent={TablePaginationActions} className={classes.pagination} /> @@ -359,8 +384,7 @@ function Row(props: RowProps) { {prettifyPayload(task.payload)} - {task.retried} - {task.max_retry} + {task.group} {!window.READ_ONLY && ( ({ @@ -530,6 +534,7 @@ function tasksReducer( ...state, aggregatingTasks: { ...state.aggregatingTasks, + group: action.group, loading: false, error: action.error, data: [],