feat: clean code

This commit is contained in:
Malena Aguiar committed 2026-09-12 15:53:21 -06:00
1 parent 71dd998390
commit 86b59da909
6 files changed
+1 -212

No files matched your search

-36
View File
@@ -1,9 +1,4 @@
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"; import { createSlice, type PayloadAction } from "@reduxjs/toolkit";
import {
DASHBOARD_CARD_IDS,
defaultVisibleCards,
type DashboardCardId,
} from "@/Pages/Dashboard/dashboardCards";
type ThemeMode = "light" | "dark"; type ThemeMode = "light" | "dark";
type ChartType = "histogram" | "line"; type ChartType = "histogram" | "line";
@@ -40,8 +35,6 @@ interface UIState {
language: string; language: string;
starPromptOpen: boolean; starPromptOpen: boolean;
chartType: ChartType; chartType: ChartType;
dashboardCards: Record<DashboardCardId, boolean>;
dashboardCardOrder: DashboardCardId[];
} }
const initialMode: ThemeMode = window?.matchMedia?.("(prefers-color-scheme: dark)") const initialMode: ThemeMode = window?.matchMedia?.("(prefers-color-scheme: dark)")
@@ -81,8 +74,6 @@ const initialState: UIState = {
language: "en", language: "en",
starPromptOpen: true, starPromptOpen: true,
chartType: "histogram", chartType: "histogram",
dashboardCards: { ...defaultVisibleCards },
dashboardCardOrder: [...DASHBOARD_CARD_IDS],
}; };
const uiSlice = createSlice({ const uiSlice = createSlice({
@@ -111,7 +102,6 @@ const uiSlice = createSlice({
setShowURL: (state, action: PayloadAction<boolean>) => { setShowURL: (state, action: PayloadAction<boolean>) => {
state.showURL = action.payload; state.showURL = action.payload;
}, },
setTimezone: (state, action: PayloadAction<{ timezone: string }>) => { setTimezone: (state, action: PayloadAction<{ timezone: string }>) => {
if (action.payload.timezone) { if (action.payload.timezone) {
state.timezone = action.payload.timezone; state.timezone = action.payload.timezone;
@@ -126,27 +116,6 @@ const uiSlice = createSlice({
setChartType: (state, action: PayloadAction<ChartType>) => { setChartType: (state, action: PayloadAction<ChartType>) => {
state.chartType = action.payload; 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, setLanguage,
setStarPromptOpen, setStarPromptOpen,
setChartType, setChartType,
setDashboardCards,
setDashboardCardsVisibility,
toggleDashboardCard,
resetDashboardCards,
setDashboardCardOrder,
} = uiSlice.actions; } = 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, isLoading,
error, error,
summary: data?.summary ?? EMPTY_SUMMARY, summary: data?.summary ?? EMPTY_SUMMARY,
monitors: data?.monitors ?? [],
slowestMonitors: data?.slowestMonitors ?? [],
lowestUptimeMonitors: data?.lowestUptimeMonitors ?? [],
downMonitors: data?.downMonitors ?? [],
monitorsByType: data?.monitorsByType ?? [], monitorsByType: data?.monitorsByType ?? [],
monitorsByGroup: data?.monitorsByGroup ?? [],
}; };
}; };
-3
View File
@@ -1,6 +1,5 @@
import type { ChartType } from "@/Features/UI/uiSlice"; import type { ChartType } from "@/Features/UI/uiSlice";
import type { User } from "./User"; import type { User } from "./User";
import type { DashboardCardId } from "@/Pages/Dashboard/dashboardCards";
export interface AuthState { export interface AuthState {
isLoading: boolean; isLoading: boolean;
@@ -40,8 +39,6 @@ export interface UIState {
language: string; language: string;
starPromptOpen: boolean; starPromptOpen: boolean;
chartType: ChartType; chartType: ChartType;
dashboardCards: Record<DashboardCardId, boolean>;
dashboardCardOrder: DashboardCardId[];
} }
export interface RootState { export interface RootState {
+1 -41
View File
@@ -1887,54 +1887,14 @@
} }
}, },
"dashboard": { "dashboard": {
"editCards": "Edit cards",
"error": "Failed to load data", "error": "Failed to load data",
"monitorStatus": { "monitorStatus": {
"ofUp": "of {{total}} up" "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": { "cards": {
"monitorStatus": "Monitor status", "monitorStatus": "Monitor status",
"currentlyDown": "Currently down", "monitorsByType": "Monitors by type"
"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"
}, },
"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": { "header": {
"title": "Dashboard", "title": "Dashboard",
"description": "See every monitor type in one place and spot what needs attention." "description": "See every monitor type in one place and spot what needs attention."
-37
View File
@@ -7,14 +7,9 @@ import {
persistReducer, persistReducer,
persistStore, persistStore,
createTransform, createTransform,
createMigrate,
PERSIST, PERSIST,
REHYDRATE, REHYDRATE,
} from "redux-persist"; } from "redux-persist";
import {
defaultVisibleCards,
DASHBOARD_CARD_IDS,
} from "@/Pages/Dashboard/dashboardCards";
const authTransform = createTransform( const authTransform = createTransform(
(inboundState: Record<string, unknown>) => { (inboundState: Record<string, unknown>) => {
@@ -25,44 +20,12 @@ const authTransform = createTransform(
{ whitelist: ["auth"] } { 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 = { const persistConfig = {
key: "root", key: "root",
version: 2,
storage, storage,
whitelist: ["auth", "ui"], whitelist: ["auth", "ui"],
transforms: [authTransform], transforms: [authTransform],
stateReconciler: autoMergeLevel2, stateReconciler: autoMergeLevel2,
migrate: createMigrate(migrations, { debug: false }),
}; };
const rootReducer = combineReducers({ const rootReducer = combineReducers({