mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-18 10:53:31 +08:00
Add GroupSelect component
This commit is contained in:
parent
b7667d8c7b
commit
3cd2cbe6f2
@ -388,7 +388,7 @@ export async function listQueueStats(): Promise<ListQueueStatsResponse> {
|
||||
export async function listGroups(qname: string): Promise<ListGroupsResponse> {
|
||||
const resp = await axios({
|
||||
method: "get",
|
||||
url: `${getBaseUrl()}/queues/${qname}`,
|
||||
url: `${getBaseUrl()}/queues/${qname}/groups`,
|
||||
});
|
||||
return resp.data;
|
||||
}
|
||||
|
51
ui/src/components/GroupSelect.tsx
Normal file
51
ui/src/components/GroupSelect.tsx
Normal 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" />
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
55
ui/src/components/TaskGroupsTable.tsx
Normal file
55
ui/src/components/TaskGroupsTable.tsx
Normal 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);
|
@ -229,7 +229,7 @@ function TasksTable(props: Props & ReduxProps) {
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel value="aggregating" selected={props.selected}>
|
||||
<TaskGroupsTable />
|
||||
<TaskGroupsTable queue={props.queue} />
|
||||
</TabPanel>
|
||||
<TabPanel value="scheduled" selected={props.selected}>
|
||||
<ScheduledTasksTable
|
||||
|
Loading…
Reference in New Issue
Block a user