Add GroupSelect component

This commit is contained in:
Ken Hibino 2022-03-25 06:06:13 -07:00
parent b7667d8c7b
commit 3cd2cbe6f2
4 changed files with 108 additions and 2 deletions

View File

@ -388,7 +388,7 @@ export async function listQueueStats(): Promise<ListQueueStatsResponse> {
export async function listGroups(qname: string): Promise<ListGroupsResponse> { export async function listGroups(qname: string): Promise<ListGroupsResponse> {
const resp = await axios({ const resp = await axios({
method: "get", method: "get",
url: `${getBaseUrl()}/queues/${qname}`, url: `${getBaseUrl()}/queues/${qname}/groups`,
}); });
return resp.data; return resp.data;
} }

View File

@ -0,0 +1,51 @@
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import Autocomplete from "@material-ui/lab/Autocomplete";
import { GroupInfo } from "../api";
import { isDarkTheme } from "../theme";
const useStyles = makeStyles((theme) => ({
groupSelectOption: {
display: "flex",
justifyContent: "space-between",
width: "100%",
},
groupSize: {
fontSize: "12px",
color: theme.palette.text.secondary,
background: isDarkTheme(theme)
? "#303030"
: theme.palette.background.default,
textAlign: "center",
padding: "3px 6px",
borderRadius: "10px",
marginRight: "2px",
},
}));
interface Props {
groups: GroupInfo[];
error: string;
}
export default function GroupSelect(props: Props) {
const classes = useStyles();
return (
<Autocomplete
id="task-group-selector"
options={props.groups}
getOptionLabel={(option: GroupInfo) => option.group}
style={{ width: 300 }}
renderOption={(option: GroupInfo) => (
<div className={classes.groupSelectOption}>
<span>{option.group}</span>
<span className={classes.groupSize}>{option.size}</span>
</div>
)}
renderInput={(params) => (
<TextField {...params} label="Select group" variant="outlined" />
)}
/>
);
}

View File

@ -0,0 +1,55 @@
import React, { useCallback } from "react";
import { connect, ConnectedProps } from "react-redux";
import { makeStyles } from "@material-ui/core/styles";
import { listGroupsAsync } from "../actions/groupsActions";
import GroupSelect from "./GroupSelect";
import { usePolling } from "../hooks";
import { AppState } from "../store";
const useStyles = makeStyles((theme) => ({
groupSelector: {
paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(1),
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2),
},
}));
function mapStateToProps(state: AppState) {
return {
groups: state.groups.data,
groupsError: state.groups.error,
pollInterval: state.settings.pollInterval,
};
}
const mapDispatchToProps = {
listGroupsAsync,
};
const connector = connect(mapStateToProps, mapDispatchToProps);
interface Props {
queue: string;
}
function TaskGroupsTable(props: Props & ConnectedProps<typeof connector>) {
const { pollInterval, listGroupsAsync, queue } = props;
const classes = useStyles();
const fetchGroups = useCallback(() => {
listGroupsAsync(queue);
}, [listGroupsAsync, queue]);
usePolling(fetchGroups, pollInterval);
return (
<div>
<div className={classes.groupSelector}>
<GroupSelect groups={props.groups} error={props.groupsError} />
</div>
</div>
);
}
export default connector(TaskGroupsTable);

View File

@ -229,7 +229,7 @@ function TasksTable(props: Props & ReduxProps) {
/> />
</TabPanel> </TabPanel>
<TabPanel value="aggregating" selected={props.selected}> <TabPanel value="aggregating" selected={props.selected}>
<TaskGroupsTable /> <TaskGroupsTable queue={props.queue} />
</TabPanel> </TabPanel>
<TabPanel value="scheduled" selected={props.selected}> <TabPanel value="scheduled" selected={props.selected}>
<ScheduledTasksTable <ScheduledTasksTable