feat: clean code
This commit is contained in:
6 files changed
+1
-212
No files matched your search
@@ -1,9 +1,4 @@
|
||||
import { createSlice, type PayloadAction } from "@reduxjs/toolkit";
|
||||
import {
|
||||
DASHBOARD_CARD_IDS,
|
||||
defaultVisibleCards,
|
||||
type DashboardCardId,
|
||||
} from "@/Pages/Dashboard/dashboardCards";
|
||||
|
||||
type ThemeMode = "light" | "dark";
|
||||
type ChartType = "histogram" | "line";
|
||||
@@ -40,8 +35,6 @@ interface UIState {
|
||||
language: string;
|
||||
starPromptOpen: boolean;
|
||||
chartType: ChartType;
|
||||
dashboardCards: Record<DashboardCardId, boolean>;
|
||||
dashboardCardOrder: DashboardCardId[];
|
||||
}
|
||||
|
||||
const initialMode: ThemeMode = window?.matchMedia?.("(prefers-color-scheme: dark)")
|
||||
@@ -81,8 +74,6 @@ const initialState: UIState = {
|
||||
language: "en",
|
||||
starPromptOpen: true,
|
||||
chartType: "histogram",
|
||||
dashboardCards: { ...defaultVisibleCards },
|
||||
dashboardCardOrder: [...DASHBOARD_CARD_IDS],
|
||||
};
|
||||
|
||||
const uiSlice = createSlice({
|
||||
@@ -111,7 +102,6 @@ const uiSlice = createSlice({
|
||||
setShowURL: (state, action: PayloadAction<boolean>) => {
|
||||
state.showURL = action.payload;
|
||||
},
|
||||
|
||||
setTimezone: (state, action: PayloadAction<{ timezone: string }>) => {
|
||||
if (action.payload.timezone) {
|
||||
state.timezone = action.payload.timezone;
|
||||
@@ -126,27 +116,6 @@ const uiSlice = createSlice({
|
||||
setChartType: (state, action: PayloadAction<ChartType>) => {
|
||||
state.chartType = action.payload;
|
||||
},
|
||||
setDashboardCards: (
|
||||
state,
|
||||
action: PayloadAction<Record<DashboardCardId, boolean>>
|
||||
) => {
|
||||
state.dashboardCards = action.payload;
|
||||
},
|
||||
setDashboardCardsVisibility: (
|
||||
state,
|
||||
action: PayloadAction<{ id: DashboardCardId; visible: boolean }>
|
||||
) => {
|
||||
state.dashboardCards[action.payload.id] = action.payload.visible;
|
||||
},
|
||||
toggleDashboardCard: (state, action: PayloadAction<DashboardCardId>) => {
|
||||
state.dashboardCards[action.payload] = !state.dashboardCards[action.payload];
|
||||
},
|
||||
resetDashboardCards: (state) => {
|
||||
state.dashboardCards = { ...defaultVisibleCards };
|
||||
},
|
||||
setDashboardCardOrder: (state, action: PayloadAction<DashboardCardId[]>) => {
|
||||
state.dashboardCardOrder = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -163,9 +132,4 @@ export const {
|
||||
setLanguage,
|
||||
setStarPromptOpen,
|
||||
setChartType,
|
||||
setDashboardCards,
|
||||
setDashboardCardsVisibility,
|
||||
toggleDashboardCard,
|
||||
resetDashboardCards,
|
||||
setDashboardCardOrder,
|
||||
} = uiSlice.actions;
|
||||
@@ -1,90 +0,0 @@
|
||||
export const DASHBOARD_CARD_IDS = [
|
||||
"monitorStatus",
|
||||
"currentlyDown",
|
||||
"slowestMonitors",
|
||||
"lowestUptime",
|
||||
"monitorsByType",
|
||||
"monitorsByGroup",
|
||||
"busiestServers",
|
||||
"recentIncidents",
|
||||
"incidentStats",
|
||||
"notificationChannels",
|
||||
"maintenanceWindows",
|
||||
"statusPages",
|
||||
"failedChecks",
|
||||
"checkmateServer",
|
||||
"checkQueue",
|
||||
"recentErrors",
|
||||
"teamMembers",
|
||||
] as const;
|
||||
|
||||
export type DashboardCardId = (typeof DASHBOARD_CARD_IDS)[number];
|
||||
|
||||
export const defaultVisibleCards: Record<DashboardCardId, boolean> = {
|
||||
monitorStatus: true,
|
||||
currentlyDown: true,
|
||||
slowestMonitors: true,
|
||||
lowestUptime: true,
|
||||
monitorsByType: true,
|
||||
monitorsByGroup: true,
|
||||
busiestServers: false,
|
||||
recentIncidents: false,
|
||||
incidentStats: false,
|
||||
notificationChannels: false,
|
||||
maintenanceWindows: false,
|
||||
statusPages: false,
|
||||
failedChecks: false,
|
||||
checkmateServer: false,
|
||||
checkQueue: false,
|
||||
recentErrors: false,
|
||||
teamMembers: false,
|
||||
};
|
||||
|
||||
export const cardCategories: {
|
||||
labelKey: string;
|
||||
cards: DashboardCardId[];
|
||||
}[] = [
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.uptime",
|
||||
cards: [
|
||||
"monitorStatus",
|
||||
"currentlyDown",
|
||||
"slowestMonitors",
|
||||
"lowestUptime",
|
||||
"monitorsByType",
|
||||
"monitorsByGroup",
|
||||
],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.infrastructure",
|
||||
cards: ["busiestServers"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.incidents",
|
||||
cards: ["recentIncidents", "incidentStats"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.notifications",
|
||||
cards: ["notificationChannels"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.maintenance",
|
||||
cards: ["maintenanceWindows"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.statusPages",
|
||||
cards: ["statusPages"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.checks",
|
||||
cards: ["failedChecks"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.system",
|
||||
cards: ["checkmateServer", "checkQueue", "recentErrors"],
|
||||
},
|
||||
{
|
||||
labelKey: "pages.dashboard.modal.categories.settings",
|
||||
cards: ["teamMembers"],
|
||||
},
|
||||
];
|
||||
@@ -25,11 +25,6 @@ export const useDashboardData = () => {
|
||||
isLoading,
|
||||
error,
|
||||
summary: data?.summary ?? EMPTY_SUMMARY,
|
||||
monitors: data?.monitors ?? [],
|
||||
slowestMonitors: data?.slowestMonitors ?? [],
|
||||
lowestUptimeMonitors: data?.lowestUptimeMonitors ?? [],
|
||||
downMonitors: data?.downMonitors ?? [],
|
||||
monitorsByType: data?.monitorsByType ?? [],
|
||||
monitorsByGroup: data?.monitorsByGroup ?? [],
|
||||
};
|
||||
};
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { ChartType } from "@/Features/UI/uiSlice";
|
||||
import type { User } from "./User";
|
||||
import type { DashboardCardId } from "@/Pages/Dashboard/dashboardCards";
|
||||
|
||||
export interface AuthState {
|
||||
isLoading: boolean;
|
||||
@@ -40,8 +39,6 @@ export interface UIState {
|
||||
language: string;
|
||||
starPromptOpen: boolean;
|
||||
chartType: ChartType;
|
||||
dashboardCards: Record<DashboardCardId, boolean>;
|
||||
dashboardCardOrder: DashboardCardId[];
|
||||
}
|
||||
|
||||
export interface RootState {
|
||||
|
||||
@@ -1887,54 +1887,14 @@
|
||||
}
|
||||
},
|
||||
"dashboard": {
|
||||
"editCards": "Edit cards",
|
||||
"error": "Failed to load data",
|
||||
"monitorStatus": {
|
||||
"ofUp": "of {{total}} up"
|
||||
},
|
||||
"emptyStates": {
|
||||
"allMonitorsUp": "All monitors are up. No incidents open.",
|
||||
"noGroups": "No groups yet. Groups are set per monitor.",
|
||||
"topOf": "Top {{count}} of {{total}}"
|
||||
},
|
||||
"cards": {
|
||||
"monitorStatus": "Monitor status",
|
||||
"currentlyDown": "Currently down",
|
||||
"slowestMonitors": "Slowest monitors",
|
||||
"lowestUptime": "Lowest uptime",
|
||||
"monitorsByType": "Monitors by type",
|
||||
"monitorsByGroup": "Monitors by group",
|
||||
"busiestServers": "Busiest servers",
|
||||
"recentIncidents": "Recent incidents",
|
||||
"incidentStats": "Incident statistics",
|
||||
"notificationChannels": "Notification channels",
|
||||
"maintenanceWindows": "Maintenance windows",
|
||||
"statusPages": "Status pages",
|
||||
"failedChecks": "Failed checks",
|
||||
"checkmateServer": "Checkmate server",
|
||||
"checkQueue": "Check queue",
|
||||
"recentErrors": "Recent errors",
|
||||
"teamMembers": "Team members"
|
||||
"monitorsByType": "Monitors by type"
|
||||
},
|
||||
"modal": {
|
||||
"title": "Edit dashboard cards",
|
||||
"description": "Choose which cards to display on your dashboard.",
|
||||
"categories": {
|
||||
"uptime": "Uptime",
|
||||
"infrastructure": "Infrastructure",
|
||||
"incidents": "Incidents",
|
||||
"notifications": "Notifications",
|
||||
"maintenance": "Maintenance",
|
||||
"statusPages": "Status pages",
|
||||
"checks": "Checks",
|
||||
"system": "System",
|
||||
"settings": "Settings"
|
||||
},
|
||||
"resetToDefaults": "Reset to defaults",
|
||||
"selectAll": "Select all",
|
||||
"done": "Done"
|
||||
},
|
||||
"comingSoon": "Coming soon",
|
||||
"header": {
|
||||
"title": "Dashboard",
|
||||
"description": "See every monitor type in one place and spot what needs attention."
|
||||
|
||||
@@ -7,14 +7,9 @@ import {
|
||||
persistReducer,
|
||||
persistStore,
|
||||
createTransform,
|
||||
createMigrate,
|
||||
PERSIST,
|
||||
REHYDRATE,
|
||||
} from "redux-persist";
|
||||
import {
|
||||
defaultVisibleCards,
|
||||
DASHBOARD_CARD_IDS,
|
||||
} from "@/Pages/Dashboard/dashboardCards";
|
||||
|
||||
const authTransform = createTransform(
|
||||
(inboundState: Record<string, unknown>) => {
|
||||
@@ -25,44 +20,12 @@ const authTransform = createTransform(
|
||||
{ whitelist: ["auth"] }
|
||||
);
|
||||
|
||||
const migrations = {
|
||||
0: (state: any) => ({
|
||||
...state,
|
||||
ui: {
|
||||
...state?.ui,
|
||||
dashboardCards: state?.ui?.dashboardCards ?? { ...defaultVisibleCards },
|
||||
},
|
||||
}),
|
||||
1: (state: any) => {
|
||||
const cards = state?.ui?.dashboardCards;
|
||||
const hasAnyVisible = cards && Object.values(cards).some((v) => v);
|
||||
return {
|
||||
...state,
|
||||
ui: {
|
||||
...state?.ui,
|
||||
dashboardCards: hasAnyVisible ? cards : { ...defaultVisibleCards },
|
||||
},
|
||||
};
|
||||
},
|
||||
2: (state: any) => {
|
||||
const cards = state?.ui?.dashboardCards ?? { ...defaultVisibleCards };
|
||||
const stubCards = DASHBOARD_CARD_IDS.filter((id) => !defaultVisibleCards[id]);
|
||||
const resetCards = { ...cards };
|
||||
stubCards.forEach((id) => {
|
||||
resetCards[id] = false;
|
||||
});
|
||||
return { ...state, ui: { ...state?.ui, dashboardCards: resetCards } };
|
||||
},
|
||||
};
|
||||
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
version: 2,
|
||||
storage,
|
||||
whitelist: ["auth", "ui"],
|
||||
transforms: [authTransform],
|
||||
stateReconciler: autoMergeLevel2,
|
||||
migrate: createMigrate(migrations, { debug: false }),
|
||||
};
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
|
||||
Reference in new issue
Block a user