mirror of
https://github.com/unraid/api.git
synced 2026-01-01 06:01:18 -06:00
fix: incorrect state merging in redux store (#1437)
omit stale config entries while merging in new config state <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved state update handling across several modules to enhance performance and maintain consistency without impacting user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210628784568830
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import type { PayloadAction } from '@reduxjs/toolkit';
|
import type { PayloadAction } from '@reduxjs/toolkit';
|
||||||
import { createSlice } from '@reduxjs/toolkit';
|
import { createSlice } from '@reduxjs/toolkit';
|
||||||
import { merge } from 'lodash-es';
|
|
||||||
|
|
||||||
import { type DynamixConfig } from '@app/core/types/ini.js';
|
import { type DynamixConfig } from '@app/core/types/ini.js';
|
||||||
import { loadDynamixConfigFile } from '@app/store/actions/load-dynamix-config-file.js';
|
import { loadDynamixConfigFile } from '@app/store/actions/load-dynamix-config-file.js';
|
||||||
@@ -20,7 +19,7 @@ export const dynamix = createSlice({
|
|||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
updateDynamixConfig(state, action: PayloadAction<RecursivePartial<SliceState>>) {
|
updateDynamixConfig(state, action: PayloadAction<RecursivePartial<SliceState>>) {
|
||||||
return merge(state, action.payload);
|
return Object.assign(state, action.payload);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extraReducers(builder) {
|
extraReducers(builder) {
|
||||||
@@ -29,11 +28,14 @@ export const dynamix = createSlice({
|
|||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadDynamixConfigFile.fulfilled, (state, action) => {
|
builder.addCase(loadDynamixConfigFile.fulfilled, (state, action) => {
|
||||||
merge(state, action.payload, { status: FileLoadStatus.LOADED });
|
return {
|
||||||
|
...(action.payload as DynamixConfig),
|
||||||
|
status: FileLoadStatus.LOADED,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadDynamixConfigFile.rejected, (state, action) => {
|
builder.addCase(loadDynamixConfigFile.rejected, (state, action) => {
|
||||||
merge(state, action.payload, {
|
Object.assign(state, action.payload, {
|
||||||
status: FileLoadStatus.FAILED_LOADING,
|
status: FileLoadStatus.FAILED_LOADING,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { join } from 'path';
|
|||||||
|
|
||||||
import type { PayloadAction } from '@reduxjs/toolkit';
|
import type { PayloadAction } from '@reduxjs/toolkit';
|
||||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
||||||
import { merge } from 'lodash-es';
|
|
||||||
|
|
||||||
import type { RootState } from '@app/store/index.js';
|
import type { RootState } from '@app/store/index.js';
|
||||||
import type { StateFileToIniParserMap } from '@app/store/types.js';
|
import type { StateFileToIniParserMap } from '@app/store/types.js';
|
||||||
@@ -176,7 +175,7 @@ export const emhttp = createSlice({
|
|||||||
}>
|
}>
|
||||||
) {
|
) {
|
||||||
const { field } = action.payload;
|
const { field } = action.payload;
|
||||||
return merge(state, { [field]: action.payload.state });
|
return Object.assign(state, { [field]: action.payload.state });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extraReducers(builder) {
|
extraReducers(builder) {
|
||||||
@@ -185,18 +184,16 @@ export const emhttp = createSlice({
|
|||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadStateFiles.fulfilled, (state, action) => {
|
builder.addCase(loadStateFiles.fulfilled, (state, action) => {
|
||||||
merge(state, action.payload, { status: FileLoadStatus.LOADED });
|
Object.assign(state, action.payload, { status: FileLoadStatus.LOADED });
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadStateFiles.rejected, (state, action) => {
|
builder.addCase(loadStateFiles.rejected, (state, action) => {
|
||||||
merge(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
|
Object.assign(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadSingleStateFile.fulfilled, (state, action) => {
|
builder.addCase(loadSingleStateFile.fulfilled, (state, action) => {
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
// const changedKey = Object.keys(action.payload)[0]
|
Object.assign(state, action.payload);
|
||||||
// emhttpLogger.debug('Key', changedKey, 'Difference in changes', getDiff(action.payload, { [changedKey]: state[changedKey] } ))
|
|
||||||
merge(state, action.payload);
|
|
||||||
} else {
|
} else {
|
||||||
emhttpLogger.warn('Invalid payload returned from loadSingleStateFile()');
|
emhttpLogger.warn('Invalid payload returned from loadSingleStateFile()');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { format } from 'util';
|
|||||||
|
|
||||||
import type { PayloadAction } from '@reduxjs/toolkit';
|
import type { PayloadAction } from '@reduxjs/toolkit';
|
||||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
||||||
import { merge } from 'lodash-es';
|
|
||||||
|
|
||||||
import type { RootState } from '@app/store/index.js';
|
import type { RootState } from '@app/store/index.js';
|
||||||
import { logger } from '@app/core/log.js';
|
import { logger } from '@app/core/log.js';
|
||||||
@@ -48,7 +47,7 @@ export const registration = createSlice({
|
|||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
updateRegistrationState(state, action: PayloadAction<Partial<{ keyFile: string }>>) {
|
updateRegistrationState(state, action: PayloadAction<Partial<{ keyFile: string }>>) {
|
||||||
return merge(state, action.payload);
|
return Object.assign(state, action.payload);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extraReducers(builder) {
|
extraReducers(builder) {
|
||||||
@@ -57,11 +56,11 @@ export const registration = createSlice({
|
|||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadRegistrationKey.fulfilled, (state, action) => {
|
builder.addCase(loadRegistrationKey.fulfilled, (state, action) => {
|
||||||
merge(state, action.payload, { status: FileLoadStatus.LOADED });
|
Object.assign(state, action.payload, { status: FileLoadStatus.LOADED });
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.addCase(loadRegistrationKey.rejected, (state, action) => {
|
builder.addCase(loadRegistrationKey.rejected, (state, action) => {
|
||||||
merge(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
|
Object.assign(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user