mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-02-23 20:30:12 +08:00
Move dailyStats chart type state to redux store
This commit is contained in:
parent
33ac2d7316
commit
8395647155
@ -1,9 +1,11 @@
|
|||||||
import { ThemePreference } from "../reducers/settingsReducer";
|
import { ThemePreference } from "../reducers/settingsReducer";
|
||||||
|
import { DailyStatsKey } from "../views/DashboardView";
|
||||||
// List of settings related action types.
|
// List of settings related action types.
|
||||||
export const POLL_INTERVAL_CHANGE = "POLL_INTERVAL_CHANGE";
|
export const POLL_INTERVAL_CHANGE = "POLL_INTERVAL_CHANGE";
|
||||||
export const THEME_PREFERENCE_CHANGE = "THEME_PREFERENCE_CHANGE";
|
export const THEME_PREFERENCE_CHANGE = "THEME_PREFERENCE_CHANGE";
|
||||||
export const TOGGLE_DRAWER = "TOGGLE_DRAWER";
|
export const TOGGLE_DRAWER = "TOGGLE_DRAWER";
|
||||||
export const TASK_ROWS_PER_PAGE_CHANGE = "TASK_ROWS_PER_PAGE_CHANGE";
|
export const TASK_ROWS_PER_PAGE_CHANGE = "TASK_ROWS_PER_PAGE_CHANGE";
|
||||||
|
export const DAILY_STATS_KEY_CHANGE = "DAILY_STATS_KEY_CHANGE";
|
||||||
|
|
||||||
interface PollIntervalChangeAction {
|
interface PollIntervalChangeAction {
|
||||||
type: typeof POLL_INTERVAL_CHANGE;
|
type: typeof POLL_INTERVAL_CHANGE;
|
||||||
@ -24,12 +26,18 @@ interface TaskRowsPerPageChange {
|
|||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DailyStatsKeyChange {
|
||||||
|
type: typeof DAILY_STATS_KEY_CHANGE;
|
||||||
|
value: DailyStatsKey;
|
||||||
|
}
|
||||||
|
|
||||||
// Union of all settings related action types.
|
// Union of all settings related action types.
|
||||||
export type SettingsActionTypes =
|
export type SettingsActionTypes =
|
||||||
| PollIntervalChangeAction
|
| PollIntervalChangeAction
|
||||||
| ThemePreferenceChangeAction
|
| ThemePreferenceChangeAction
|
||||||
| ToggleDrawerAction
|
| ToggleDrawerAction
|
||||||
| TaskRowsPerPageChange;
|
| TaskRowsPerPageChange
|
||||||
|
| DailyStatsKeyChange;
|
||||||
|
|
||||||
export function pollIntervalChange(value: number) {
|
export function pollIntervalChange(value: number) {
|
||||||
return {
|
return {
|
||||||
@ -55,3 +63,10 @@ export function taskRowsPerPageChange(value: number) {
|
|||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dailyStatsKeyChange(value: DailyStatsKey) {
|
||||||
|
return {
|
||||||
|
type: DAILY_STATS_KEY_CHANGE,
|
||||||
|
value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
DAILY_STATS_KEY_CHANGE,
|
||||||
POLL_INTERVAL_CHANGE,
|
POLL_INTERVAL_CHANGE,
|
||||||
SettingsActionTypes,
|
SettingsActionTypes,
|
||||||
TASK_ROWS_PER_PAGE_CHANGE,
|
TASK_ROWS_PER_PAGE_CHANGE,
|
||||||
@ -6,6 +7,7 @@ import {
|
|||||||
TOGGLE_DRAWER,
|
TOGGLE_DRAWER,
|
||||||
} from "../actions/settingsActions";
|
} from "../actions/settingsActions";
|
||||||
import { defaultPageSize } from "../components/TablePaginationActions"
|
import { defaultPageSize } from "../components/TablePaginationActions"
|
||||||
|
import { DailyStatsKey, defaultDailyStatsKey } from "../views/DashboardView";
|
||||||
|
|
||||||
export enum ThemePreference {
|
export enum ThemePreference {
|
||||||
SystemDefault,
|
SystemDefault,
|
||||||
@ -14,10 +16,20 @@ export enum ThemePreference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SettingsState {
|
export interface SettingsState {
|
||||||
|
// Time duration between data refresh.
|
||||||
pollInterval: number;
|
pollInterval: number;
|
||||||
|
|
||||||
|
// UI theme setting.
|
||||||
themePreference: ThemePreference;
|
themePreference: ThemePreference;
|
||||||
|
|
||||||
|
// Whether the drawer (i.e. sidebar) is open or not.
|
||||||
isDrawerOpen: boolean;
|
isDrawerOpen: boolean;
|
||||||
|
|
||||||
|
// Number of tasks displayed in task table.
|
||||||
taskRowsPerPage: number,
|
taskRowsPerPage: number,
|
||||||
|
|
||||||
|
// Type of the chart displayed for "Processed Tasks" section in dashboard.
|
||||||
|
dailyStatsChartType: DailyStatsKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: SettingsState = {
|
export const initialState: SettingsState = {
|
||||||
@ -25,6 +37,7 @@ export const initialState: SettingsState = {
|
|||||||
themePreference: ThemePreference.SystemDefault,
|
themePreference: ThemePreference.SystemDefault,
|
||||||
isDrawerOpen: true,
|
isDrawerOpen: true,
|
||||||
taskRowsPerPage: defaultPageSize,
|
taskRowsPerPage: defaultPageSize,
|
||||||
|
dailyStatsChartType: defaultDailyStatsKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
function settingsReducer(
|
function settingsReducer(
|
||||||
@ -56,6 +69,12 @@ function settingsReducer(
|
|||||||
taskRowsPerPage: action.value,
|
taskRowsPerPage: action.value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case DAILY_STATS_KEY_CHANGE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
dailyStatsChartType: action.value,
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { connect, ConnectedProps } from "react-redux";
|
import { connect, ConnectedProps } from "react-redux";
|
||||||
import Container from "@material-ui/core/Container";
|
import Container from "@material-ui/core/Container";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
@ -15,6 +15,7 @@ import {
|
|||||||
deleteQueueAsync,
|
deleteQueueAsync,
|
||||||
} from "../actions/queuesActions";
|
} from "../actions/queuesActions";
|
||||||
import { listQueueStatsAsync } from "../actions/queueStatsActions";
|
import { listQueueStatsAsync } from "../actions/queueStatsActions";
|
||||||
|
import { dailyStatsKeyChange } from "../actions/settingsActions";
|
||||||
import { AppState } from "../store";
|
import { AppState } from "../store";
|
||||||
import QueueSizeChart from "../components/QueueSizeChart";
|
import QueueSizeChart from "../components/QueueSizeChart";
|
||||||
import ProcessedTasksChart from "../components/ProcessedTasksChart";
|
import ProcessedTasksChart from "../components/ProcessedTasksChart";
|
||||||
@ -72,6 +73,7 @@ function mapStateToProps(state: AppState) {
|
|||||||
error: state.queues.error,
|
error: state.queues.error,
|
||||||
pollInterval: state.settings.pollInterval,
|
pollInterval: state.settings.pollInterval,
|
||||||
queueStats: state.queueStats.data,
|
queueStats: state.queueStats.data,
|
||||||
|
dailyStatsKey: state.settings.dailyStatsChartType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,21 +83,25 @@ const mapDispatchToProps = {
|
|||||||
resumeQueueAsync,
|
resumeQueueAsync,
|
||||||
deleteQueueAsync,
|
deleteQueueAsync,
|
||||||
listQueueStatsAsync,
|
listQueueStatsAsync,
|
||||||
|
dailyStatsKeyChange,
|
||||||
};
|
};
|
||||||
|
|
||||||
const connector = connect(mapStateToProps, mapDispatchToProps);
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
||||||
|
|
||||||
type Props = ConnectedProps<typeof connector>;
|
type Props = ConnectedProps<typeof connector>;
|
||||||
|
|
||||||
type DailyStatsKey = "today" | "last-7d" | "last-30d" | "last-90d";
|
export type DailyStatsKey = "today" | "last-7d" | "last-30d" | "last-90d";
|
||||||
const initialStatsKey = "last-7d";
|
export const defaultDailyStatsKey = "last-7d";
|
||||||
|
|
||||||
function DashboardView(props: Props) {
|
function DashboardView(props: Props) {
|
||||||
const { pollInterval, listQueuesAsync, queues, listQueueStatsAsync } = props;
|
const {
|
||||||
|
pollInterval,
|
||||||
|
listQueuesAsync,
|
||||||
|
queues,
|
||||||
|
listQueueStatsAsync,
|
||||||
|
dailyStatsKey,
|
||||||
|
} = props;
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [dailyStatsKey, setDailyStatsKey] = useState<DailyStatsKey>(
|
|
||||||
initialStatsKey
|
|
||||||
);
|
|
||||||
|
|
||||||
usePolling(listQueuesAsync, pollInterval);
|
usePolling(listQueuesAsync, pollInterval);
|
||||||
|
|
||||||
@ -204,8 +210,10 @@ function DashboardView(props: Props) {
|
|||||||
{ label: "Last 30d", key: "last-30d" },
|
{ label: "Last 30d", key: "last-30d" },
|
||||||
{ label: "Last 90d", key: "last-90d" },
|
{ label: "Last 90d", key: "last-90d" },
|
||||||
]}
|
]}
|
||||||
initialSelectedKey={initialStatsKey}
|
initialSelectedKey={dailyStatsKey}
|
||||||
onSelect={(key) => setDailyStatsKey(key as DailyStatsKey)}
|
onSelect={(key) =>
|
||||||
|
props.dailyStatsKeyChange(key as DailyStatsKey)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user