From 5e6aaa3caaeea5afa993753bf9df527cd7e8775a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 09:59:01 +0800 Subject: [PATCH 1/8] remove unused reducers --- .../infrastructureMonitorsSlice.js | 389 ------------------ .../PageSpeedMonitor/pageSpeedMonitorSlice.js | 309 -------------- client/src/store.js | 6 +- 3 files changed, 1 insertion(+), 703 deletions(-) delete mode 100644 client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js delete mode 100644 client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js diff --git a/client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js b/client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js deleted file mode 100644 index 62bdf4811..000000000 --- a/client/src/Features/InfrastructureMonitors/infrastructureMonitorsSlice.js +++ /dev/null @@ -1,389 +0,0 @@ -import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; -import { networkService } from "../../main"; -const initialState = { - isLoading: false, - monitorsSummary: [], - success: null, - msg: null, -}; - -export const createInfrastructureMonitor = createAsyncThunk( - "infrastructureMonitors/createMonitor", - async (data, thunkApi) => { - try { - const { monitor } = data; - const res = await networkService.createMonitor({ monitor: monitor }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const checkInfrastructureEndpointResolution = createAsyncThunk( - "infrastructureMonitors/CheckEndpoint", - async (data, thunkApi) => { - try { - const { monitorURL } = data; - const res = await networkService.checkEndpointResolution({ - monitorURL: monitorURL, - }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const getInfrastructureMonitorById = createAsyncThunk( - "infrastructureMonitors/getMonitorById", - async (data, thunkApi) => { - try { - const { monitorId } = data; - const res = await networkService.getMonitorById({ monitorId: monitorId }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const getInfrastructureMonitorsByTeamId = createAsyncThunk( - "infrastructureMonitors/getMonitorsByTeamId", - async (_, thunkApi) => { - const user = thunkApi.getState().auth.user; - try { - const res = await networkService.getMonitorsAndSummaryByTeamId({ - teamId: user.teamId, - types: ["hardware"], - limit: 1, - rowsPerPage: 0, - }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const updateInfrastructureMonitor = createAsyncThunk( - "infrastructureMonitors/updateMonitor", - async ({ monitorId, monitor }, thunkApi) => { - try { - const updatedFields = { - name: monitor.name, - description: monitor.description, - interval: monitor.interval, - notifications: monitor.notifications, - thresholds: monitor.thresholds, - secret: monitor.secret, - }; - const res = await networkService.updateMonitor({ - monitorId, - monitor, - updatedFields, - }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const deleteInfrastructureMonitor = createAsyncThunk( - "infrastructureMonitors/deleteMonitor", - async (data, thunkApi) => { - try { - const { monitor } = data; - const res = await networkService.deleteMonitorById({ monitorId: monitor._id }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const pauseInfrastructureMonitor = createAsyncThunk( - "infrastructureMonitors/pauseMonitor", - async (data, thunkApi) => { - try { - const { monitorId } = data; - const res = await networkService.pauseMonitorById({ monitorId: monitorId }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const deleteInfrastructureMonitorChecksByTeamId = createAsyncThunk( - "infrastructureMonitors/deleteChecksByTeamId", - async (data, thunkApi) => { - try { - const { teamId } = data; - const res = await networkService.deleteChecksByTeamId({ teamId: teamId }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const deleteAllInfrastructureMonitors = createAsyncThunk( - "infrastructureMonitors/deleteAllMonitors", - async (data, thunkApi) => { - try { - const res = await networkService.deleteAllMonitors(); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -const infrastructureMonitorsSlice = createSlice({ - name: "infrastructureMonitors", - initialState, - reducers: { - clearInfrastructureMonitorState: (state) => { - state.isLoading = false; - state.monitorsSummary = []; - state.success = null; - state.msg = null; - }, - }, - extraReducers: (builder) => { - builder - // ***************************************************** - // Monitors by teamId - // ***************************************************** - - .addCase(getInfrastructureMonitorsByTeamId.pending, (state) => { - state.isLoading = true; - }) - .addCase(getInfrastructureMonitorsByTeamId.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.msg; - state.monitorsSummary = action.payload.data; - }) - .addCase(getInfrastructureMonitorsByTeamId.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Getting infrastructure monitors failed"; - }) - - // ***************************************************** - // Create Monitor - // ***************************************************** - .addCase(createInfrastructureMonitor.pending, (state) => { - state.isLoading = true; - }) - .addCase(createInfrastructureMonitor.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(createInfrastructureMonitor.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to create infrastructure monitor"; - }) - // ***************************************************** - // Resolve Endpoint - // ***************************************************** - .addCase(checkInfrastructureEndpointResolution.pending, (state) => { - state.isLoading = true; - }) - .addCase(checkInfrastructureEndpointResolution.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(checkInfrastructureEndpointResolution.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to check endpoint resolution"; - }) - // ***************************************************** - // Get Monitor By Id - // ***************************************************** - .addCase(getInfrastructureMonitorById.pending, (state) => { - state.isLoading = true; - }) - .addCase(getInfrastructureMonitorById.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(getInfrastructureMonitorById.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to get infrastructure monitor"; - }) - // ***************************************************** - // update Monitor - // ***************************************************** - .addCase(updateInfrastructureMonitor.pending, (state) => { - state.isLoading = true; - }) - .addCase(updateInfrastructureMonitor.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(updateInfrastructureMonitor.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to update infrastructure monitor"; - }) - - // ***************************************************** - // Delete Monitor - // ***************************************************** - .addCase(deleteInfrastructureMonitor.pending, (state) => { - state.isLoading = true; - }) - .addCase(deleteInfrastructureMonitor.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(deleteInfrastructureMonitor.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to delete infrastructure monitor"; - }) - // ***************************************************** - // Delete Monitor checks by Team ID - // ***************************************************** - .addCase(deleteInfrastructureMonitorChecksByTeamId.pending, (state) => { - state.isLoading = true; - }) - .addCase(deleteInfrastructureMonitorChecksByTeamId.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(deleteInfrastructureMonitorChecksByTeamId.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to delete monitor checks"; - }) - // ***************************************************** - // Pause Monitor - // ***************************************************** - .addCase(pauseInfrastructureMonitor.pending, (state) => { - state.isLoading = true; - }) - .addCase(pauseInfrastructureMonitor.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(pauseInfrastructureMonitor.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to pause infrastructure monitor"; - }) - // ***************************************************** - // Delete all Monitors - // ***************************************************** - .addCase(deleteAllInfrastructureMonitors.pending, (state) => { - state.isLoading = true; - }) - .addCase(deleteAllInfrastructureMonitors.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(deleteAllInfrastructureMonitors.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload ? action.payload.msg : "Failed to delete all monitors"; - }); - }, -}); - -export const { setInfrastructureMonitors, clearInfrastructureMonitorState } = - infrastructureMonitorsSlice.actions; - -export default infrastructureMonitorsSlice.reducer; diff --git a/client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js b/client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js deleted file mode 100644 index 3ed2da13f..000000000 --- a/client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js +++ /dev/null @@ -1,309 +0,0 @@ -import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; -import { networkService } from "../../main"; -const initialState = { - isLoading: false, - monitorsSummary: [], - success: null, - msg: null, -}; - -export const createPageSpeed = createAsyncThunk( - "pageSpeedMonitors/createPageSpeed", - async (data, thunkApi) => { - try { - const { monitor } = data; - const res = await networkService.createMonitor({ monitor: monitor }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const checkEndpointResolution = createAsyncThunk( - "monitors/checkEndpoint", - async (data, thunkApi) => { - try { - const { monitorURL } = data; - const res = await networkService.checkEndpointResolution({ - monitorURL: monitorURL, - }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const getPagespeedMonitorById = createAsyncThunk( - "monitors/getMonitorById", - async (data, thunkApi) => { - try { - const { monitorId } = data; - const res = await networkService.getMonitorById({ monitorId: monitorId }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const getPageSpeedByTeamId = createAsyncThunk( - "pageSpeedMonitors/getPageSpeedByTeamId", - async (_, thunkApi) => { - const user = thunkApi.getState().auth.user; - try { - const res = await networkService.getMonitorsAndSummaryByTeamId({ - teamId: user.teamId, - types: ["pagespeed"], - }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const updatePageSpeed = createAsyncThunk( - "pageSpeedMonitors/updatePageSpeed", - async (data, thunkApi) => { - try { - const { monitor } = data; - const updatedFields = { - name: monitor.name, - description: monitor.description, - interval: monitor.interval, - notifications: monitor.notifications, - }; - const res = await networkService.updateMonitor({ - monitorId: monitor._id, - updatedFields: updatedFields, - }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const deletePageSpeed = createAsyncThunk( - "pageSpeedMonitors/deletePageSpeed", - async (data, thunkApi) => { - try { - const { monitor } = data; - const res = await networkService.deleteMonitorById({ monitorId: monitor._id }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); -export const pausePageSpeed = createAsyncThunk( - "pageSpeedMonitors/pausePageSpeed", - async (data, thunkApi) => { - try { - const { monitorId } = data; - const res = await networkService.pauseMonitorById({ monitorId: monitorId }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -const pageSpeedMonitorSlice = createSlice({ - name: "pageSpeedMonitor", - initialState, - reducers: { - clearMonitorState: (state) => { - state.isLoading = false; - state.monitorsSummary = []; - state.success = null; - state.msg = null; - }, - }, - extraReducers: (builder) => { - builder - // ***************************************************** - // Monitors by teamId - // ***************************************************** - - .addCase(getPageSpeedByTeamId.pending, (state) => { - state.isLoading = true; - }) - .addCase(getPageSpeedByTeamId.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.msg; - state.monitorsSummary = action.payload.data; - }) - .addCase(getPageSpeedByTeamId.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Getting page speed monitors failed"; - }) - - // ***************************************************** - .addCase(getPagespeedMonitorById.pending, (state) => { - state.isLoading = true; - }) - .addCase(getPagespeedMonitorById.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(getPagespeedMonitorById.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to get pagespeed monitor"; - }) - - // ***************************************************** - // Create Monitor - // ***************************************************** - .addCase(createPageSpeed.pending, (state) => { - state.isLoading = true; - }) - .addCase(createPageSpeed.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(createPageSpeed.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to create page speed monitor"; - }) - // ***************************************************** - // Resolve Endpoint - // ***************************************************** - .addCase(checkEndpointResolution.pending, (state) => { - state.isLoading = true; - }) - .addCase(checkEndpointResolution.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(checkEndpointResolution.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to check endpoint resolution"; - }) - // ***************************************************** - // Update Monitor - // ***************************************************** - .addCase(updatePageSpeed.pending, (state) => { - state.isLoading = true; - }) - .addCase(updatePageSpeed.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(updatePageSpeed.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to update page speed monitor"; - }) - - // ***************************************************** - // Delete Monitor - // ***************************************************** - .addCase(deletePageSpeed.pending, (state) => { - state.isLoading = true; - }) - .addCase(deletePageSpeed.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(deletePageSpeed.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to delete page speed monitor"; - }) - // ***************************************************** - // Pause Monitor - // ***************************************************** - .addCase(pausePageSpeed.pending, (state) => { - state.isLoading = true; - }) - .addCase(pausePageSpeed.fulfilled, (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - }) - .addCase(pausePageSpeed.rejected, (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to pause page speed monitor"; - }); - }, -}); - -export const { setMonitors, clearMonitorState } = pageSpeedMonitorSlice.actions; - -export default pageSpeedMonitorSlice.reducer; diff --git a/client/src/store.js b/client/src/store.js index f7cbdbde1..309ba52e2 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -1,7 +1,5 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit"; -import infrastructureMonitorsReducer from "./Features/InfrastructureMonitors/infrastructureMonitorsSlice"; -import pageSpeedMonitorReducer from "./Features/PageSpeedMonitor/pageSpeedMonitorSlice"; import authReducer from "./Features/Auth/authSlice"; import uiReducer from "./Features/UI/uiSlice"; import settingsReducer from "./Features/Settings/settingsSlice"; @@ -22,14 +20,12 @@ const authTransform = createTransform( const persistConfig = { key: "root", storage, - whitelist: ["auth", "pageSpeed", "ui", "settings"], + whitelist: ["auth", "ui", "settings"], transforms: [authTransform], }; const rootReducer = combineReducers({ - infrastructureMonitors: infrastructureMonitorsReducer, auth: authReducer, - pageSpeedMonitors: pageSpeedMonitorReducer, ui: uiReducer, settings: settingsReducer, }); From deeb6a030c7dfc10197163fb0c804c6a07915e22 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:00:48 +0800 Subject: [PATCH 2/8] remove settings reducer --- client/src/Features/Settings/settingsSlice.js | 100 ------------------ client/src/store.js | 4 +- 2 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 client/src/Features/Settings/settingsSlice.js diff --git a/client/src/Features/Settings/settingsSlice.js b/client/src/Features/Settings/settingsSlice.js deleted file mode 100644 index d0725627a..000000000 --- a/client/src/Features/Settings/settingsSlice.js +++ /dev/null @@ -1,100 +0,0 @@ -import { networkService } from "../../main"; -import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; - -const initialState = { - isLoading: false, - apiBaseUrl: "", - logLevel: "debug", - pagespeedApiKey: "", -}; - -export const getAppSettings = createAsyncThunk( - "settings/getSettings", - async (data, thunkApi) => { - try { - const res = await networkService.getAppSettings(); - return res.data; - } catch (error) { - if (error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const updateAppSettings = createAsyncThunk( - "settings/updateSettings", - async ({ settings }, thunkApi) => { - try { - const parsedSettings = { - language: settings.language, - pagespeedApiKey: settings.pagespeedApiKey, - }; - const res = await networkService.updateAppSettings({ settings: parsedSettings }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -const handleGetSettingsFulfilled = (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - state.apiBaseUrl = action.payload.data.apiBaseUrl; - state.logLevel = action.payload.data.logLevel; - state.language = action.payload.data.language; - state.pagespeedApiKey = action.payload.data.pagespeedApiKey; -}; -const handleGetSettingsRejected = (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload ? action.payload.msg : "Failed to get settings."; -}; -const handleUpdateSettingsFulfilled = (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - state.apiBaseUrl = action.payload.data.apiBaseUrl; - state.logLevel = action.payload.data.logLevel; -}; -const handleUpdateSettingsRejected = (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload ? action.payload.msg : "Failed to update settings."; -}; - -const settingsSlice = createSlice({ - name: "settings", - initialState, - extraReducers: (builder) => { - builder - .addCase(getAppSettings.pending, (state) => { - state.isLoading = true; - }) - .addCase(getAppSettings.fulfilled, handleGetSettingsFulfilled) - .addCase(getAppSettings.rejected, handleGetSettingsRejected); - - builder - .addCase(updateAppSettings.pending, (state) => { - state.isLoading = true; - }) - .addCase(updateAppSettings.fulfilled, handleUpdateSettingsFulfilled) - .addCase(updateAppSettings.rejected, handleUpdateSettingsRejected); - }, -}); - -export default settingsSlice.reducer; diff --git a/client/src/store.js b/client/src/store.js index 309ba52e2..69aa3d50b 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -2,7 +2,6 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit"; import authReducer from "./Features/Auth/authSlice"; import uiReducer from "./Features/UI/uiSlice"; -import settingsReducer from "./Features/Settings/settingsSlice"; import storage from "redux-persist/lib/storage"; import { persistReducer, persistStore, createTransform } from "redux-persist"; @@ -20,14 +19,13 @@ const authTransform = createTransform( const persistConfig = { key: "root", storage, - whitelist: ["auth", "ui", "settings"], + whitelist: ["auth", "ui"], transforms: [authTransform], }; const rootReducer = combineReducers({ auth: authReducer, ui: uiReducer, - settings: settingsReducer, }); const persistedReducer = persistReducer(persistConfig, rootReducer); From a63bcb5b4acf0f943389dc4069fd62eb396eb05f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:05:29 +0800 Subject: [PATCH 3/8] add missing finally block --- client/src/Components/ActionsMenu/index.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/Components/ActionsMenu/index.jsx b/client/src/Components/ActionsMenu/index.jsx index cdd7ecf7d..1b590a471 100644 --- a/client/src/Components/ActionsMenu/index.jsx +++ b/client/src/Components/ActionsMenu/index.jsx @@ -43,6 +43,8 @@ const ActionsMenu = ({ pauseCallback(); } catch (error) { createToast({ body: "Failed to pause monitor." }); + } finally { + setIsLoading(false); } }; From 1542cf01a768ea3c470aa1e330d7f174dcd10c06 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:13:22 +0800 Subject: [PATCH 4/8] comment out pagespeed check, TODO later --- client/src/Pages/PageSpeed/Monitors/index.jsx | 3 +-- client/src/Utils/Logger.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/client/src/Pages/PageSpeed/Monitors/index.jsx b/client/src/Pages/PageSpeed/Monitors/index.jsx index 319b0da21..dc1772227 100644 --- a/client/src/Pages/PageSpeed/Monitors/index.jsx +++ b/client/src/Pages/PageSpeed/Monitors/index.jsx @@ -21,7 +21,6 @@ const PageSpeed = () => { const { t } = useTranslation(); const isAdmin = useIsAdmin(); const { user } = useSelector((state) => state.auth); - const { pagespeedApiKey } = useSelector((state) => state.settings); const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({ teamId: user.teamId, @@ -60,7 +59,7 @@ const PageSpeed = () => { ]} link="/pagespeed/create" isAdmin={isAdmin} - showPageSpeedWarning={isAdmin && !pagespeedApiKey} + // showPageSpeedWarning={isAdmin && !pagespeedApiKey} /> ); } diff --git a/client/src/Utils/Logger.js b/client/src/Utils/Logger.js index b22cc0a22..f132ad408 100644 --- a/client/src/Utils/Logger.js +++ b/client/src/Utils/Logger.js @@ -6,8 +6,7 @@ class Logger { constructor() { let logLevel = LOG_LEVEL; this.unsubscribe = store.subscribe(() => { - const state = store.getState(); - logLevel = state.settings.logLevel || "debug"; + logLevel = "debug"; this.updateLogLevel(logLevel); }); } From 134e54773621671c9175002548c135058b536e9f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:18:43 +0800 Subject: [PATCH 5/8] remove redux loading state --- .../Monitors/Components/MonitorsTableMenu/index.jsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx index bce3020a6..15193da3e 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTableMenu/index.jsx @@ -1,7 +1,6 @@ /* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */ import { useRef, useState } from "react"; -import { useSelector } from "react-redux"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { createToast } from "../../../../../Utils/toastUtils"; @@ -30,7 +29,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { const [isOpen, setIsOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); const theme = useTheme(); - const { isLoading } = useSelector((state) => state.uptimeMonitors); const openMenu = (e) => { e.stopPropagation(); @@ -117,7 +115,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => { onCancel={cancelRemove} confirmationButtonLabel="Delete" onConfirm={handleRemove} - isLoading={isLoading} modelTitle="modal-delete-monitor" modelDescription="delete-monitor-confirmation" /> From d9c2f31f4eb4f6fb9b92f09ab93289a8239cab51 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:38:52 +0800 Subject: [PATCH 6/8] remove teamId from uptime monitor requests --- client/src/Hooks/monitorHooks.js | 11 +--- .../Maintenance/CreateMaintenance/index.jsx | 1 - .../Create/Hooks/useMonitorsFetch.jsx | 1 - client/src/Pages/Uptime/Monitors/index.jsx | 5 -- client/src/Utils/NetworkService.js | 64 ++++--------------- 5 files changed, 16 insertions(+), 66 deletions(-) diff --git a/client/src/Hooks/monitorHooks.js b/client/src/Hooks/monitorHooks.js index e5c405ac1..5072b5594 100644 --- a/client/src/Hooks/monitorHooks.js +++ b/client/src/Hooks/monitorHooks.js @@ -6,7 +6,7 @@ import { useMonitorUtils } from "./useMonitorUtils"; import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; -const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => { +const useFetchMonitorsWithSummary = ({ types, monitorUpdateTrigger }) => { const [isLoading, setIsLoading] = useState(false); const [monitors, setMonitors] = useState(undefined); const [monitorsSummary, setMonitorsSummary] = useState(undefined); @@ -17,7 +17,6 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => try { setIsLoading(true); const res = await networkService.getMonitorsWithSummaryByTeamId({ - teamId, types, }); const { monitors, summary } = res?.data?.data ?? {}; @@ -34,12 +33,11 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => } }; fetchMonitors(); - }, [teamId, types, monitorUpdateTrigger]); + }, [types, monitorUpdateTrigger]); return [monitors, monitorsSummary, isLoading, networkError]; }; const useFetchMonitorsWithChecks = ({ - teamId, types, limit, page, @@ -61,7 +59,6 @@ const useFetchMonitorsWithChecks = ({ try { setIsLoading(true); const res = await networkService.getMonitorsWithChecksByTeamId({ - teamId, limit, types, page, @@ -95,7 +92,6 @@ const useFetchMonitorsWithChecks = ({ order, page, rowsPerPage, - teamId, theme, types, monitorUpdateTrigger, @@ -104,7 +100,6 @@ const useFetchMonitorsWithChecks = ({ }; const useFetchMonitorsByTeamId = ({ - teamId, types, limit, page, @@ -127,7 +122,6 @@ const useFetchMonitorsByTeamId = ({ try { setIsLoading(true); const res = await networkService.getMonitorsByTeamId({ - teamId, limit, types, page, @@ -154,7 +148,6 @@ const useFetchMonitorsByTeamId = ({ }; fetchMonitors(); }, [ - teamId, types, limit, page, diff --git a/client/src/Pages/Maintenance/CreateMaintenance/index.jsx b/client/src/Pages/Maintenance/CreateMaintenance/index.jsx index f3754c6b0..e71c7112c 100644 --- a/client/src/Pages/Maintenance/CreateMaintenance/index.jsx +++ b/client/src/Pages/Maintenance/CreateMaintenance/index.jsx @@ -135,7 +135,6 @@ const CreateMaintenance = () => { setIsLoading(true); try { const response = await networkService.getMonitorsByTeamId({ - teamId: user.teamId, limit: null, types: ["http", "ping", "pagespeed", "port"], }); diff --git a/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx b/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx index 5c523b635..f380bed9a 100644 --- a/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx +++ b/client/src/Pages/StatusPage/Create/Hooks/useMonitorsFetch.jsx @@ -13,7 +13,6 @@ const useMonitorsFetch = () => { const fetchMonitors = async () => { try { const response = await networkService.getMonitorsByTeamId({ - teamId: user.teamId, limit: null, // donot return any checks for the monitors types: ["http", "ping", "port"], // status page is available for uptime, ping, and port monitors }); diff --git a/client/src/Pages/Uptime/Monitors/index.jsx b/client/src/Pages/Uptime/Monitors/index.jsx index e313d7deb..030ce922c 100644 --- a/client/src/Pages/Uptime/Monitors/index.jsx +++ b/client/src/Pages/Uptime/Monitors/index.jsx @@ -64,7 +64,6 @@ CreateMonitorButton.propTypes = { const UptimeMonitors = () => { // Redux state - const { user } = useSelector((state) => state.auth); const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage); // Local state @@ -106,11 +105,8 @@ const UptimeMonitors = () => { setMonitorUpdateTrigger((prev) => !prev); }, []); - const teamId = user.teamId; - const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] = useFetchMonitorsWithSummary({ - teamId, types: TYPES, monitorUpdateTrigger, }); @@ -140,7 +136,6 @@ const UptimeMonitors = () => { monitorsWithChecksIsLoading, monitorsWithChecksNetworkError, ] = useFetchMonitorsWithChecks({ - teamId, types: effectiveTypes, limit: 25, page: page, diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index f25828c66..e84596b97 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -135,36 +135,6 @@ class NetworkService { }); } - /** - * - * ************************************ - * Gets monitors and summary of stats by TeamID - * ************************************ - * - * @async - * @param {Object} config - The configuration object. - * @param {string} config.teamId - Team ID - * @param {Array} config.types - Array of monitor types - * @returns {Promise} The response from the axios POST request. - */ - async getMonitorsSummaryByTeamId(config) { - const params = new URLSearchParams(); - - if (config.types) { - config.types.forEach((type) => { - params.append("type", type); - }); - } - return this.axiosInstance.get( - `/monitors/team/summary/${config.teamId}?${params.toString()}`, - { - headers: { - "Content-Type": "application/json", - }, - } - ); - } - /** * ************************************ * Get all uptime monitors for a Team @@ -184,7 +154,7 @@ class NetworkService { */ async getMonitorsByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; + const { limit, types, page, rowsPerPage, filter, field, order } = config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); @@ -199,7 +169,7 @@ class NetworkService { if (field) params.append("field", field); if (order) params.append("order", order); - return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, { + return this.axiosInstance.get(`/monitors/team?${params.toString()}`, { headers: { "Content-Type": "application/json", }, @@ -949,7 +919,7 @@ class NetworkService { // Fetch monitors with summary by TeamID // ************************************ async getMonitorsWithSummaryByTeamId(config) { - const { teamId, types } = config; + const { types } = config; const params = new URLSearchParams(); if (types) { @@ -958,21 +928,18 @@ class NetworkService { }); } - return this.axiosInstance.get( - `/monitors/summary/team/${teamId}?${params.toString()}`, - { - headers: { - "Content-Type": "application/json", - }, - } - ); + return this.axiosInstance.get(`/monitors/summary/team?${params.toString()}`, { + headers: { + "Content-Type": "application/json", + }, + }); } // ************************************ // Fetch monitors with checks by TeamID // ************************************ async getMonitorsWithChecksByTeamId(config) { - const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; + const { limit, types, page, rowsPerPage, filter, field, order } = config; const params = new URLSearchParams(); if (limit) params.append("limit", limit); @@ -987,14 +954,11 @@ class NetworkService { if (field) params.append("field", field); if (order) params.append("order", order); - return this.axiosInstance.get( - `/monitors/team/${teamId}/with-checks?${params.toString()}`, - { - headers: { - "Content-Type": "application/json", - }, - } - ); + return this.axiosInstance.get(`/monitors/team/with-checks?${params.toString()}`, { + headers: { + "Content-Type": "application/json", + }, + }); } // ************************************ From afece4df650667c999313615e88af608bd3613d1 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:46:06 +0800 Subject: [PATCH 7/8] update routes, validation --- client/src/Components/Dialog/index.jsx | 2 +- client/src/Components/StatBox/index.jsx | 4 ++-- .../Monitors/Components/MonitorsTable/index.jsx | 7 ++++--- client/src/Pages/Infrastructure/Monitors/index.jsx | 5 +---- client/src/Pages/PageSpeed/Monitors/index.jsx | 3 --- server/db/mongo/modules/monitorModule.js | 7 ++++--- server/routes/monitorRoute.js | 8 ++++---- server/validation/joi.js | 4 +--- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/client/src/Components/Dialog/index.jsx b/client/src/Components/Dialog/index.jsx index e07597df4..678eb8721 100644 --- a/client/src/Components/Dialog/index.jsx +++ b/client/src/Components/Dialog/index.jsx @@ -57,7 +57,7 @@ Dialog.propTypes = { onCancel: PropTypes.func.isRequired, confirmationButtonLabel: PropTypes.string.isRequired, onConfirm: PropTypes.func.isRequired, - isLoading: PropTypes.bool.isRequired, + isLoading: PropTypes.bool, }; export default Dialog; diff --git a/client/src/Components/StatBox/index.jsx b/client/src/Components/StatBox/index.jsx index 93fa46c2b..7d093de60 100644 --- a/client/src/Components/StatBox/index.jsx +++ b/client/src/Components/StatBox/index.jsx @@ -136,8 +136,8 @@ const StatBox = ({ }; StatBox.propTypes = { - heading: PropTypes.string.isRequired, - subHeading: PropTypes.node.isRequired, + heading: PropTypes.string, + subHeading: PropTypes.node, gradient: PropTypes.bool, status: PropTypes.string, sx: PropTypes.object, diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index 761ecaa0e..7a5db231f 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -15,7 +15,7 @@ import { useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; -const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete }) => { +const MonitorsTable = ({ isLoading, monitors, isAdmin, handleActionMenuDelete }) => { // Utils const theme = useTheme(); const { t } = useTranslation(); @@ -86,6 +86,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete monitor={row} isAdmin={isAdmin} updateCallback={handleActionMenuDelete} + isLoading={isLoading} /> ), }, @@ -120,7 +121,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete return ( { // Redux state - const { user } = useSelector((state) => state.auth); // Local state const [page, setPage] = useState(0); @@ -56,7 +54,6 @@ const InfrastructureMonitors = () => { const field = toFilterStatus !== undefined ? "status" : undefined; const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({ - teamId: user.teamId, limit: 1, types: TYPES, page, @@ -118,7 +115,7 @@ const InfrastructureMonitors = () => { /> { const theme = useTheme(); const { t } = useTranslation(); const isAdmin = useIsAdmin(); - const { user } = useSelector((state) => state.auth); const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({ - teamId: user.teamId, limit: 10, types: TYPES, page: null, diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 3d9adab39..b6044f2c9 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -519,7 +519,8 @@ const getMonitorsByTeamId = async (req) => { order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const teamId = req.user.teamId; + const matchStage = { teamId: ObjectId.createFromHexString(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -560,7 +561,7 @@ const getMonitorsByTeamId = async (req) => { const getMonitorsAndSummaryByTeamId = async (req) => { try { const { type } = req.query; - const teamId = ObjectId.createFromHexString(req.params.teamId); + const teamId = ObjectId.createFromHexString(req.user.teamId); const matchStage = { teamId }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; @@ -594,7 +595,7 @@ const getMonitorsWithChecksByTeamId = async (req) => { field = "name"; order = "asc"; } - const teamId = ObjectId.createFromHexString(req.params.teamId); + const teamId = ObjectId.createFromHexString(req.user.teamId); // Build match stage const matchStage = { teamId }; if (type !== undefined) { diff --git a/server/routes/monitorRoute.js b/server/routes/monitorRoute.js index 6d1db90ad..0dabab407 100755 --- a/server/routes/monitorRoute.js +++ b/server/routes/monitorRoute.js @@ -35,17 +35,17 @@ class MonitorRoutes { fetchMonitorCertificate ); }); + this.router.get("/team", this.monitorController.getMonitorsByTeamId); + this.router.get("/:monitorId", this.monitorController.getMonitorById); - this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId); - this.router.get( - "/summary/team/:teamId", + "/summary/team", this.monitorController.getMonitorsAndSummaryByTeamId ); this.router.get( - "/team/:teamId/with-checks", + "/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId ); diff --git a/server/validation/joi.js b/server/validation/joi.js index 271cd2d21..aba7118d1 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -126,9 +126,7 @@ const getMonitorByIdQueryValidation = joi.object({ normalize: joi.boolean(), }); -const getMonitorsByTeamIdParamValidation = joi.object({ - teamId: joi.string().required(), -}); +const getMonitorsByTeamIdParamValidation = joi.object({}); const getMonitorsByTeamIdQueryValidation = joi.object({ limit: joi.number(), From 57f4db8d370daac1cf0f5bccad3adc0740fe6a2a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:52:05 +0800 Subject: [PATCH 8/8] remove reference to state --- client/src/Pages/Uptime/Create/index.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/src/Pages/Uptime/Create/index.jsx b/client/src/Pages/Uptime/Create/index.jsx index f481e81ac..184beffe5 100644 --- a/client/src/Pages/Uptime/Create/index.jsx +++ b/client/src/Pages/Uptime/Create/index.jsx @@ -28,7 +28,6 @@ import { useCreateMonitor } from "../../../Hooks/monitorHooks"; const CreateMonitor = () => { // Redux state const { user } = useSelector((state) => state.auth); - const { isLoading } = useSelector((state) => state.uptimeMonitors); // Local state const [errors, setErrors] = useState({}); @@ -467,7 +466,7 @@ const CreateMonitor = () => { variant="contained" color="accent" disabled={!Object.values(errors).every((value) => value === undefined)} - loading={isLoading || isCreating} + loading={isCreating} > {t("createMonitor")}