diff --git a/src/app/store/auth/slice.ts b/src/app/store/auth/slice.ts index a8c8130371..39610f4135 100644 --- a/src/app/store/auth/slice.ts +++ b/src/app/store/auth/slice.ts @@ -47,9 +47,7 @@ const authSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, adminChangePasswordStart: (state: UserState) => { state.auth.saved = false; @@ -82,9 +80,7 @@ const authSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, changePasswordStart: (state: UserState) => { state.auth.saved = false; @@ -116,9 +112,7 @@ const authSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchStart: (state: UserState) => { state.auth.loading = true; diff --git a/src/app/store/bootresource/slice.ts b/src/app/store/bootresource/slice.ts index 621977ec38..8a275db994 100644 --- a/src/app/store/bootresource/slice.ts +++ b/src/app/store/bootresource/slice.ts @@ -53,9 +53,7 @@ const bootResourceSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteImageError: ( state: BootResourceState, @@ -83,9 +81,7 @@ const bootResourceSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchError: ( state: BootResourceState, @@ -116,9 +112,7 @@ const bootResourceSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, pollError: ( state: BootResourceState, @@ -170,9 +164,7 @@ const bootResourceSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, saveOtherError: ( state: BootResourceState, @@ -201,9 +193,7 @@ const bootResourceSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, saveUbuntuError: ( state: BootResourceState, @@ -231,9 +221,7 @@ const bootResourceSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, saveUbuntuCoreError: ( state: BootResourceState, @@ -259,9 +247,7 @@ const bootResourceSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, stopImportError: ( state: BootResourceState, diff --git a/src/app/store/config/slice.ts b/src/app/store/config/slice.ts index 0ab5decfa4..c404e31e86 100644 --- a/src/app/store/config/slice.ts +++ b/src/app/store/config/slice.ts @@ -17,9 +17,7 @@ const statusSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchStart: (state: ConfigState) => { state.loading = true; @@ -56,9 +54,7 @@ const statusSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateStart: (state: ConfigState) => { state.saved = false; diff --git a/src/app/store/controller/slice.ts b/src/app/store/controller/slice.ts index c6cd302af5..2f0102e457 100644 --- a/src/app/store/controller/slice.ts +++ b/src/app/store/controller/slice.ts @@ -133,7 +133,11 @@ const controllerSlice = createSlice({ ControllerMeta.PK, CreateParams, UpdateParams - >(ControllerMeta.MODEL, ControllerMeta.PK, setErrors), + >({ + modelName: ControllerMeta.MODEL, + primaryKey: ControllerMeta.PK, + setErrors, + }), checkImages: { prepare: (ids: Controller[ControllerMeta.PK][]) => ({ meta: { @@ -144,9 +148,7 @@ const controllerSlice = createSlice({ params: ids.map((id) => ({ [ControllerMeta.PK]: id })), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, checkImagesError: { prepare: (item: CheckImagesItem[], error: ControllerState["errors"]) => ({ @@ -247,9 +249,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteError: statusHandlers.delete.error, deleteNotify: ( @@ -311,9 +311,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getSummaryXmlError: statusHandlers.getSummaryXml.error, getSummaryXmlStart: statusHandlers.getSummaryXml.start, @@ -333,9 +331,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getSummaryYamlError: statusHandlers.getSummaryYaml.error, getSummaryYamlStart: statusHandlers.getSummaryYaml.start, @@ -354,9 +350,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, importImagesError: statusHandlers.importImages.error, importImagesStart: statusHandlers.importImages.start, @@ -375,9 +369,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, offError: statusHandlers.off.error, offStart: statusHandlers.off.start, @@ -396,9 +388,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, onError: statusHandlers.on.error, onStart: statusHandlers.on.start, @@ -417,9 +407,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, overrideFailedTestingError: statusHandlers.overrideFailedTesting.error, overrideFailedTestingStart: statusHandlers.overrideFailedTesting.start, @@ -439,9 +427,7 @@ const controllerSlice = createSlice({ params: ids.map((id) => ({ [ControllerMeta.PK]: id })), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, pollCheckImagesError: { prepare: (item: CheckImagesItem[], error: ControllerState["errors"]) => ({ @@ -494,9 +480,7 @@ const controllerSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, pollCheckImagesSuccess: { prepare: (item: CheckImagesItem[], payload: ImageSyncStatuses) => ({ @@ -536,9 +520,7 @@ const controllerSlice = createSlice({ params: system_id ? { system_id } : null, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: ControllerState, @@ -576,9 +558,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setZoneError: statusHandlers.setZone.error, setZoneStart: statusHandlers.setZone.start, @@ -601,9 +581,7 @@ const controllerSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, testError: statusHandlers.test.error, testStart: statusHandlers.test.start, diff --git a/src/app/store/device/slice.ts b/src/app/store/device/slice.ts index 4743bca41a..72cb6dd0e5 100644 --- a/src/app/store/device/slice.ts +++ b/src/app/store/device/slice.ts @@ -107,7 +107,11 @@ const deviceSlice = createSlice({ DeviceMeta.PK, CreateParams, UpdateParams - >(DeviceMeta.MODEL, DeviceMeta.PK, setErrors), + >({ + modelName: DeviceMeta.MODEL, + primaryKey: DeviceMeta.PK, + setErrors, + }), createInterface: { prepare: (params: CreateInterfaceParams) => ({ meta: { @@ -118,9 +122,7 @@ const deviceSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createInterfaceError: statusHandlers.createInterface.error, createInterfaceStart: statusHandlers.createInterface.start, @@ -149,9 +151,7 @@ const deviceSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createPhysicalError: statusHandlers.createPhysical.error, createPhysicalStart: statusHandlers.createPhysical.start, @@ -188,9 +188,7 @@ const deviceSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteError: statusHandlers.delete.error, deleteNotify: ( @@ -219,9 +217,7 @@ const deviceSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteInterfaceError: statusHandlers.deleteInterface.error, deleteInterfaceStart: statusHandlers.deleteInterface.start, @@ -242,9 +238,7 @@ const deviceSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, linkSubnetError: statusHandlers.linkSubnet.error, linkSubnetStart: statusHandlers.linkSubnet.start, @@ -260,9 +254,7 @@ const deviceSlice = createSlice({ params: system_id ? { system_id } : null, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: DeviceState, @@ -300,9 +292,7 @@ const deviceSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setZoneError: statusHandlers.setZone.error, setZoneStart: statusHandlers.setZone.start, @@ -317,9 +307,7 @@ const deviceSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, unlinkSubnetError: statusHandlers.unlinkSubnet.error, unlinkSubnetStart: statusHandlers.unlinkSubnet.start, @@ -338,9 +326,7 @@ const deviceSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateInterfaceError: statusHandlers.updateInterface.error, updateInterfaceStart: statusHandlers.updateInterface.start, diff --git a/src/app/store/dhcpsnippet/slice.ts b/src/app/store/dhcpsnippet/slice.ts index fe446557ef..43e37f1b80 100644 --- a/src/app/store/dhcpsnippet/slice.ts +++ b/src/app/store/dhcpsnippet/slice.ts @@ -16,7 +16,7 @@ const dhcpSnippetSlice = createSlice({ DHCPSnippetMeta.PK, CreateParams, UpdateParams - >(DHCPSnippetMeta.MODEL, DHCPSnippetMeta.PK), + >({ modelName: DHCPSnippetMeta.MODEL, primaryKey: DHCPSnippetMeta.PK }), }); export const { actions } = dhcpSnippetSlice; diff --git a/src/app/store/discovery/slice.ts b/src/app/store/discovery/slice.ts index 0d66a23c31..1a41eb30aa 100644 --- a/src/app/store/discovery/slice.ts +++ b/src/app/store/discovery/slice.ts @@ -20,9 +20,7 @@ const discoverySlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchStart: (state: DiscoveryState) => { state.loading = true; @@ -52,9 +50,7 @@ const discoverySlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteStart: (state: DiscoveryState) => { state.saved = false; @@ -98,9 +94,7 @@ const discoverySlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, clearStart: (state: DiscoveryState) => { state.saved = false; diff --git a/src/app/store/domain/slice.ts b/src/app/store/domain/slice.ts index 0021f9aaa7..e3c436baed 100644 --- a/src/app/store/domain/slice.ts +++ b/src/app/store/domain/slice.ts @@ -39,7 +39,10 @@ const domainSlice = createSlice({ DomainMeta.PK, CreateParams, UpdateParams - >(DomainMeta.MODEL, DomainMeta.PK), + >({ + modelName: DomainMeta.MODEL, + primaryKey: DomainMeta.PK, + }), ...generateGetReducers({ modelName: DomainMeta.MODEL, primaryKey: DomainMeta.PK, @@ -54,9 +57,7 @@ const domainSlice = createSlice({ params: { domain: id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setDefaultStart: (state: DomainState) => { state.saving = true; @@ -94,9 +95,7 @@ const domainSlice = createSlice({ params: id === null ? null : { id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: DomainState, @@ -121,9 +120,7 @@ const domainSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createAddressRecordStart: (state: DomainState) => { state.saving = true; @@ -151,9 +148,7 @@ const domainSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createDNSDataStart: (state: DomainState) => { state.saving = true; @@ -183,9 +178,7 @@ const domainSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteAddressRecordStart: (state: DomainState) => { state.saving = true; @@ -215,9 +208,7 @@ const domainSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteDNSDataStart: (state: DomainState) => { state.saving = true; @@ -247,9 +238,7 @@ const domainSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteDNSResourceError: ( state: DomainState, @@ -266,9 +255,7 @@ const domainSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateAddressRecord: { prepare: (params: UpdateAddressRecordParams) => { @@ -282,9 +269,7 @@ const domainSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateAddressRecordStart: (state: DomainState) => { state.saving = true; @@ -314,9 +299,7 @@ const domainSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateDNSDataStart: (state: DomainState) => { state.saving = true; @@ -346,9 +329,7 @@ const domainSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateDNSResourceStart: (state: DomainState) => { state.saving = true; @@ -372,9 +353,7 @@ const domainSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, }, }); diff --git a/src/app/store/event/slice.ts b/src/app/store/event/slice.ts index dbca97925d..9ad2018e2c 100644 --- a/src/app/store/event/slice.ts +++ b/src/app/store/event/slice.ts @@ -13,10 +13,10 @@ const eventSlice = createSlice({ name: EventMeta.MODEL, initialState: genericInitialState as EventState, reducers: { - ...generateCommonReducers( - EventMeta.MODEL, - EventMeta.PK - ), + ...generateCommonReducers({ + modelName: EventMeta.MODEL, + primaryKey: EventMeta.PK, + }), fetch: { prepare: ( node_id: EventRecord["node_id"], @@ -41,9 +41,7 @@ const eventSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchSuccess: ( state: EventState, diff --git a/src/app/store/fabric/slice.ts b/src/app/store/fabric/slice.ts index db27439dae..5c735ea098 100644 --- a/src/app/store/fabric/slice.ts +++ b/src/app/store/fabric/slice.ts @@ -22,7 +22,10 @@ const fabricSlice = createSlice({ FabricMeta.PK, CreateParams, UpdateParams - >(FabricMeta.MODEL, FabricMeta.PK), + >({ + modelName: FabricMeta.MODEL, + primaryKey: FabricMeta.PK, + }), ...generateGetReducers({ modelName: FabricMeta.MODEL, primaryKey: FabricMeta.PK, @@ -38,9 +41,7 @@ const fabricSlice = createSlice({ params: id === null ? null : { [FabricMeta.PK]: id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: FabricState, diff --git a/src/app/store/general/slice.ts b/src/app/store/general/slice.ts index 40c6628545..815f8beea8 100644 --- a/src/app/store/general/slice.ts +++ b/src/app/store/general/slice.ts @@ -22,9 +22,7 @@ const generatePrepareReducer = (method: string) => ({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }); const generateStartReducer = @@ -161,9 +159,7 @@ const generalSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, generateCertificateStart: generateStartReducer("generatedCertificate"), generateCertificateError: generateErrorReducer("generatedCertificate"), diff --git a/src/app/store/iprange/slice.ts b/src/app/store/iprange/slice.ts index 28eec96939..4bc8d2707b 100644 --- a/src/app/store/iprange/slice.ts +++ b/src/app/store/iprange/slice.ts @@ -23,7 +23,10 @@ const ipRangeSlice = createSlice({ IPRangeMeta.PK, CreateParams, UpdateParams - >(IPRangeMeta.MODEL, IPRangeMeta.PK), + >({ + modelName: IPRangeMeta.MODEL, + primaryKey: IPRangeMeta.PK, + }), ...generateGetReducers({ modelName: IPRangeMeta.MODEL, primaryKey: IPRangeMeta.PK, diff --git a/src/app/store/licensekeys/slice.ts b/src/app/store/licensekeys/slice.ts index 966849676a..5ea7378399 100644 --- a/src/app/store/licensekeys/slice.ts +++ b/src/app/store/licensekeys/slice.ts @@ -23,22 +23,21 @@ const licenseKeysSlice = createSlice({ LicenseKeysMeta.PK, CreateParams, UpdateParams - >(LicenseKeysMeta.MODEL, LicenseKeysMeta.PK), + >({ + modelName: LicenseKeysMeta.MODEL, + primaryKey: LicenseKeysMeta.PK, + }), create: { prepare: (params: CreateParams) => ({ payload: params, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, delete: { prepare: (params: LicenseKeys) => ({ payload: params, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, dismissStart: (state: LicenseKeysState) => { state.saved = false; @@ -66,17 +65,13 @@ const licenseKeysSlice = createSlice({ prepare: () => ({ payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, update: { prepare: (params: UpdateParams) => ({ payload: params, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateSuccess: (state: LicenseKeysState, action) => { state.errors = null; diff --git a/src/app/store/machine/slice.ts b/src/app/store/machine/slice.ts index 0f6a11a0f0..7b50087f68 100644 --- a/src/app/store/machine/slice.ts +++ b/src/app/store/machine/slice.ts @@ -239,9 +239,7 @@ const generateActionParams =

( }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }); const invalidateQueries = (state: MachineState) => { @@ -275,7 +273,11 @@ const machineSlice = createSlice({ MachineMeta.PK, CreateParams, UpdateParams - >(MachineMeta.MODEL, MachineMeta.PK, setErrors), + >({ + modelName: MachineMeta.MODEL, + primaryKey: MachineMeta.PK, + setErrors, + }), [NodeActions.ABORT]: generateActionParams( NodeActions.ABORT ), @@ -294,9 +296,7 @@ const machineSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, addChassisError: ( state: MachineState, @@ -329,9 +329,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, applyStorageLayoutError: statusHandlers.applyStorageLayout.error, applyStorageLayoutStart: statusHandlers.applyStorageLayout.start, @@ -348,9 +346,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, checkPowerError: statusHandlers.checkPower.error, checkPowerStart: statusHandlers.checkPower.start, @@ -383,9 +379,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, count: { prepare: (callId: string, filters?: FetchFilters | null) => ({ @@ -400,9 +394,7 @@ const machineSlice = createSlice({ } : null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, countError: { prepare: (callId: string, errors: MachineStateCount["errors"]) => ({ @@ -495,9 +487,7 @@ const machineSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createBondError: statusHandlers.createBond.error, createBondStart: statusHandlers.createBond.start, @@ -512,9 +502,7 @@ const machineSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createBridgeError: statusHandlers.createBridge.error, createBridgeStart: statusHandlers.createBridge.start, @@ -533,9 +521,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createCacheSetError: statusHandlers.createCacheSet.error, createCacheSetStart: statusHandlers.createCacheSet.start, @@ -555,9 +541,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createLogicalVolumeError: statusHandlers.createLogicalVolume.error, createLogicalVolumeStart: statusHandlers.createLogicalVolume.start, @@ -579,9 +563,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createPartitionError: statusHandlers.createPartition.error, createPartitionStart: statusHandlers.createPartition.start, @@ -596,9 +578,7 @@ const machineSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createPhysicalError: statusHandlers.createPhysical.error, createPhysicalStart: statusHandlers.createPhysical.start, @@ -621,9 +601,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createRaidError: statusHandlers.createRaid.error, createRaidStart: statusHandlers.createRaid.start, @@ -638,9 +616,7 @@ const machineSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createVlanError: statusHandlers.createVlan.error, createVlanStart: statusHandlers.createVlan.start, @@ -659,9 +635,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createVmfsDatastoreError: statusHandlers.createVmfsDatastore.error, createVmfsDatastoreStart: statusHandlers.createVmfsDatastore.start, @@ -680,9 +654,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createVolumeGroupError: statusHandlers.createVolumeGroup.error, createVolumeGroupStart: statusHandlers.createVolumeGroup.start, @@ -753,9 +725,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteCacheSetError: statusHandlers.deleteCacheSet.error, deleteCacheSetStart: statusHandlers.deleteCacheSet.start, @@ -773,9 +743,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteDiskError: statusHandlers.deleteDisk.error, deleteDiskStart: statusHandlers.deleteDisk.start, @@ -795,9 +763,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteFilesystemError: statusHandlers.deleteFilesystem.error, deleteFilesystemStart: statusHandlers.deleteFilesystem.start, @@ -815,9 +781,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteInterfaceError: statusHandlers.deleteInterface.error, deleteInterfaceStart: statusHandlers.deleteInterface.start, @@ -835,9 +799,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deletePartitionError: statusHandlers.deletePartition.error, deletePartitionStart: statusHandlers.deletePartition.start, @@ -855,9 +817,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteVolumeGroupError: statusHandlers.deleteVolumeGroup.error, deleteVolumeGroupStart: statusHandlers.deleteVolumeGroup.start, @@ -888,9 +848,7 @@ const machineSlice = createSlice({ } : null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchError: { prepare: (callId: string, errors: MachineStateList["errors"]) => ({ @@ -1003,9 +961,7 @@ const machineSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, filterGroupsError: ( state: MachineState, @@ -1044,9 +1000,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, filterOptionsError: { prepare: ( @@ -1172,9 +1126,7 @@ const machineSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, get: { prepare: (machineID: Machine[MachineMeta.PK], callId: string) => ({ @@ -1187,9 +1139,7 @@ const machineSlice = createSlice({ params: { system_id: machineID }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getError: { prepare: ( @@ -1309,9 +1259,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getSummaryXmlError: statusHandlers.getSummaryXml.error, getSummaryXmlStart: statusHandlers.getSummaryXml.start, @@ -1331,9 +1279,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getSummaryYamlError: statusHandlers.getSummaryYaml.error, getSummaryYamlStart: statusHandlers.getSummaryYaml.start, @@ -1348,9 +1294,7 @@ const machineSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, linkSubnetError: statusHandlers.linkSubnet.error, linkSubnetStart: statusHandlers.linkSubnet.start, @@ -1386,9 +1330,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, mountSpecialError: statusHandlers.mountSpecial.error, mountSpecialStart: statusHandlers.mountSpecial.start, @@ -1455,9 +1397,7 @@ const machineSlice = createSlice({ params: system_id ? { system_id } : null, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: MachineState, @@ -1486,9 +1426,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setBootDiskError: statusHandlers.setBootDisk.error, setBootDiskStart: statusHandlers.setBootDisk.start, @@ -1541,9 +1479,7 @@ const machineSlice = createSlice({ }, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, softOffError: statusHandlers.softOff.error, softOffStart: statusHandlers.softOff.start, @@ -1564,9 +1500,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, [NodeActions.TAG]: generateActionParams(NodeActions.TAG), [`${NodeActions.TAG}Error`]: statusHandlers.tag.error, @@ -1596,9 +1530,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, unlinkSubnetError: statusHandlers.unlinkSubnet.error, unlinkSubnetStart: statusHandlers.unlinkSubnet.start, @@ -1616,9 +1548,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, unmountSpecialError: statusHandlers.unmountSpecial.error, unmountSpecialStart: statusHandlers.unmountSpecial.start, @@ -1639,9 +1569,7 @@ const machineSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, unsubscribe: { prepare: (ids: Machine[MachineMeta.PK][]) => ({ @@ -1653,9 +1581,7 @@ const machineSlice = createSlice({ params: { system_ids: ids }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, unsubscribeError: ( state: MachineState, @@ -1714,9 +1640,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateDiskError: statusHandlers.updateDisk.error, updateDiskStart: statusHandlers.updateDisk.start, @@ -1737,9 +1661,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateFilesystemError: statusHandlers.updateFilesystem.error, updateFilesystemStart: statusHandlers.updateFilesystem.start, @@ -1758,9 +1680,7 @@ const machineSlice = createSlice({ params: preparePayloadParams(params), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateInterfaceError: statusHandlers.updateInterface.error, updateInterfaceStart: statusHandlers.updateInterface.start, @@ -1774,10 +1694,11 @@ const machineSlice = createSlice({ MachineMeta.PK, CreateParams, UpdateParams - >(MachineMeta.MODEL, MachineMeta.PK, setErrors).updateNotify( - state, - action - ); + >({ + modelName: MachineMeta.MODEL, + primaryKey: MachineMeta.PK, + setErrors, + }).updateNotify(state, action); // infer the new grouping value for each machine list // based on machine details sent as notification payload Object.keys(state.lists).forEach((callId: string) => { @@ -1882,9 +1803,7 @@ const machineSlice = createSlice({ }), }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateVmfsDatastoreError: statusHandlers.updateVmfsDatastore.error, updateVmfsDatastoreStart: statusHandlers.updateVmfsDatastore.start, diff --git a/src/app/store/nodedevice/slice.ts b/src/app/store/nodedevice/slice.ts index 6255917cad..cd12989d71 100644 --- a/src/app/store/nodedevice/slice.ts +++ b/src/app/store/nodedevice/slice.ts @@ -20,10 +20,10 @@ const nodeDeviceSlice = createSlice({ name: NodeDeviceMeta.MODEL, initialState: genericInitialState as NodeDeviceState, reducers: { - ...generateCommonReducers( - NodeDeviceMeta.MODEL, - NodeDeviceMeta.PK - ), + ...generateCommonReducers({ + modelName: NodeDeviceMeta.MODEL, + primaryKey: NodeDeviceMeta.PK, + }), getByNodeId: { prepare: (nodeID: Node["system_id"]) => ({ meta: { diff --git a/src/app/store/notification/slice.ts b/src/app/store/notification/slice.ts index 27f3d2345d..d3bdc9fcfe 100644 --- a/src/app/store/notification/slice.ts +++ b/src/app/store/notification/slice.ts @@ -18,7 +18,10 @@ const notificationSlice = createSlice({ NotificationMeta.PK, CreateParams, void - >(NotificationMeta.MODEL, NotificationMeta.PK), + >({ + modelName: NotificationMeta.MODEL, + primaryKey: NotificationMeta.PK, + }), dismiss: { prepare: (id: Notification[NotificationMeta.PK]) => ({ meta: { @@ -31,9 +34,7 @@ const notificationSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, dismissStart: (state: NotificationState) => { state.saved = false; diff --git a/src/app/store/packagerepository/slice.ts b/src/app/store/packagerepository/slice.ts index 044d8b86b8..80b38d254d 100644 --- a/src/app/store/packagerepository/slice.ts +++ b/src/app/store/packagerepository/slice.ts @@ -20,7 +20,10 @@ const packageRepositorySlice = createSlice({ PackageRepositoryMeta.PK, CreateParams, UpdateParams - >(PackageRepositoryMeta.MODEL, PackageRepositoryMeta.PK), + >({ + modelName: PackageRepositoryMeta.MODEL, + primaryKey: PackageRepositoryMeta.PK, + }), }); export const { actions } = packageRepositorySlice; diff --git a/src/app/store/pod/slice.ts b/src/app/store/pod/slice.ts index f1261e2f8a..9b71874b25 100644 --- a/src/app/store/pod/slice.ts +++ b/src/app/store/pod/slice.ts @@ -65,8 +65,10 @@ const podSlice = createSlice({ } as PodState, reducers: { ...generateCommonReducers( - PodMeta.MODEL, - PodMeta.PK + { + modelName: PodMeta.MODEL, + primaryKey: PodMeta.PK, + } ), clearProjects: (state: PodState) => { state.projects = {}; @@ -94,9 +96,7 @@ const podSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, composeError: statusHandlers.compose.error, composeStart: statusHandlers.compose.start, @@ -111,9 +111,7 @@ const podSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteError: statusHandlers.delete.error, deleteStart: statusHandlers.delete.start, @@ -167,9 +165,7 @@ const podSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getProjectsSuccess: { prepare: ( @@ -219,9 +215,7 @@ const podSlice = createSlice({ }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, pollLxdServerStop: { prepare: () => ({ @@ -232,9 +226,7 @@ const podSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, pollLxdServerError: ( state: PodState, @@ -284,9 +276,7 @@ const podSlice = createSlice({ params: { id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, refreshError: statusHandlers.refresh.error, refreshStart: statusHandlers.refresh.start, @@ -302,9 +292,7 @@ const podSlice = createSlice({ params: id === null ? null : { id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: PodState, diff --git a/src/app/store/resourcepool/slice.ts b/src/app/store/resourcepool/slice.ts index 2b6ead0c10..7abbc7e837 100644 --- a/src/app/store/resourcepool/slice.ts +++ b/src/app/store/resourcepool/slice.ts @@ -22,7 +22,10 @@ const resourcePoolSlice = createSlice({ ResourcePoolMeta.PK, CreateParams, UpdateParams - >(ResourcePoolMeta.MODEL, ResourcePoolMeta.PK), + >({ + modelName: ResourcePoolMeta.MODEL, + primaryKey: ResourcePoolMeta.PK, + }), createWithMachines: { prepare: (params: CreateWithMachinesParams) => ({ payload: { diff --git a/src/app/store/script/slice.ts b/src/app/store/script/slice.ts index ee0f505a6f..e5dc104150 100644 --- a/src/app/store/script/slice.ts +++ b/src/app/store/script/slice.ts @@ -13,10 +13,10 @@ const scriptSlice = createSlice({ name: ScriptMeta.MODEL, initialState: genericInitialState as ScriptState, reducers: { - ...generateCommonReducers( - ScriptMeta.MODEL, - ScriptMeta.PK - ), + ...generateCommonReducers({ + modelName: ScriptMeta.MODEL, + primaryKey: ScriptMeta.PK, + }), get: { prepare: ( id: Script[ScriptMeta.PK], diff --git a/src/app/store/scriptresult/slice.ts b/src/app/store/scriptresult/slice.ts index 9dc5880535..b9fc5081fd 100644 --- a/src/app/store/scriptresult/slice.ts +++ b/src/app/store/scriptresult/slice.ts @@ -36,7 +36,10 @@ const scriptResultSlice = createSlice({ ScriptResultMeta.PK, void, void - >(ScriptResultMeta.MODEL, ScriptResultMeta.PK), + >({ + modelName: ScriptResultMeta.MODEL, + primaryKey: ScriptResultMeta.PK, + }), get: { prepare: (id: ScriptResult[ScriptResultMeta.PK]) => ({ meta: { diff --git a/src/app/store/service/slice.ts b/src/app/store/service/slice.ts index 16bd6bf11e..8e8b9a9c94 100644 --- a/src/app/store/service/slice.ts +++ b/src/app/store/service/slice.ts @@ -11,10 +11,10 @@ import { const serviceSlice = createSlice({ name: ServiceMeta.MODEL, initialState: genericInitialState as ServiceState, - reducers: generateCommonReducers( - ServiceMeta.MODEL, - ServiceMeta.PK - ), + reducers: generateCommonReducers({ + modelName: ServiceMeta.MODEL, + primaryKey: ServiceMeta.PK, + }), }); export const { actions } = serviceSlice; diff --git a/src/app/store/space/slice.ts b/src/app/store/space/slice.ts index bf5e6aa8c2..39d5df9755 100644 --- a/src/app/store/space/slice.ts +++ b/src/app/store/space/slice.ts @@ -22,7 +22,10 @@ const spaceSlice = createSlice({ SpaceMeta.PK, CreateParams, UpdateParams - >(SpaceMeta.MODEL, SpaceMeta.PK), + >({ + modelName: SpaceMeta.MODEL, + primaryKey: SpaceMeta.PK, + }), ...generateGetReducers({ modelName: SpaceMeta.MODEL, primaryKey: SpaceMeta.PK, @@ -38,9 +41,7 @@ const spaceSlice = createSlice({ params: id === null ? null : { [SpaceMeta.PK]: id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: SpaceState, diff --git a/src/app/store/sshkey/slice.ts b/src/app/store/sshkey/slice.ts index 955584b9fe..6c1431a246 100644 --- a/src/app/store/sshkey/slice.ts +++ b/src/app/store/sshkey/slice.ts @@ -13,10 +13,10 @@ const sshKeySlice = createSlice({ name: SSHKeyMeta.MODEL, initialState: genericInitialState as SSHKeyState, reducers: { - ...generateCommonReducers( - SSHKeyMeta.MODEL, - SSHKeyMeta.PK - ), + ...generateCommonReducers({ + modelName: SSHKeyMeta.MODEL, + primaryKey: SSHKeyMeta.PK, + }), import: { prepare: (params: ImportParams) => ({ meta: { @@ -27,9 +27,7 @@ const sshKeySlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, importStart: (state: SSHKeyState, _action: PayloadAction) => { state.saved = false; diff --git a/src/app/store/sslkey/slice.ts b/src/app/store/sslkey/slice.ts index 05d99ada2e..d5545b77ab 100644 --- a/src/app/store/sslkey/slice.ts +++ b/src/app/store/sslkey/slice.ts @@ -16,7 +16,10 @@ const sslKeySlice = createSlice({ SSLKeyMeta.PK, CreateParams, void - >(SSLKeyMeta.MODEL, SSLKeyMeta.PK), + >({ + modelName: SSLKeyMeta.MODEL, + primaryKey: SSLKeyMeta.PK, + }), }); export const { actions } = sslKeySlice; diff --git a/src/app/store/staticroute/slice.ts b/src/app/store/staticroute/slice.ts index 96ac2ccfbf..31f24b58e5 100644 --- a/src/app/store/staticroute/slice.ts +++ b/src/app/store/staticroute/slice.ts @@ -16,7 +16,10 @@ const staticRouteSlice = createSlice({ StaticRouteMeta.PK, CreateParams, UpdateParams - >(StaticRouteMeta.MODEL, StaticRouteMeta.PK), + >({ + modelName: StaticRouteMeta.MODEL, + primaryKey: StaticRouteMeta.PK, + }), }); export const { actions } = staticRouteSlice; diff --git a/src/app/store/status/slice.ts b/src/app/store/status/slice.ts index a40784dc68..532111f38c 100644 --- a/src/app/store/status/slice.ts +++ b/src/app/store/status/slice.ts @@ -25,9 +25,7 @@ const statusSlice = createSlice({ prepare: () => ({ payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, checkAuthenticatedStart: (state: StatusState) => { state.authenticating = true; @@ -49,9 +47,7 @@ const statusSlice = createSlice({ prepare: (params: { password: string; username: string }) => ({ payload: params, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, loginStart: (state: StatusState) => { state.authenticating = true; @@ -73,9 +69,7 @@ const statusSlice = createSlice({ prepare: () => ({ payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, externalLoginSuccess: (state: StatusState) => { state.authenticated = true; @@ -94,9 +88,7 @@ const statusSlice = createSlice({ prepare: () => ({ payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, logoutSuccess: (state: StatusState) => { state.authenticated = false; diff --git a/src/app/store/subnet/slice.ts b/src/app/store/subnet/slice.ts index 46008ef562..42adf54be5 100644 --- a/src/app/store/subnet/slice.ts +++ b/src/app/store/subnet/slice.ts @@ -60,7 +60,11 @@ const subnetSlice = createSlice({ SubnetMeta.PK, CreateParams, UpdateParams - >(SubnetMeta.MODEL, SubnetMeta.PK, setErrors), + >({ + modelName: SubnetMeta.MODEL, + primaryKey: SubnetMeta.PK, + setErrors, + }), createNotify: (state: SubnetState, action: PayloadAction) => { // In the event that the server erroneously attempts to create an existing // subnet, due to a race condition etc., ensure we update instead of @@ -108,9 +112,7 @@ const subnetSlice = createSlice({ params: { [SubnetMeta.PK]: id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, scanError: statusHandlers.scan.error, scanStart: statusHandlers.scan.start, @@ -156,9 +158,7 @@ const subnetSlice = createSlice({ params: id === null ? null : { [SubnetMeta.PK]: id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: SubnetState, diff --git a/src/app/store/tag/slice.ts b/src/app/store/tag/slice.ts index 9e79f3f703..e90b037ed9 100644 --- a/src/app/store/tag/slice.ts +++ b/src/app/store/tag/slice.ts @@ -24,8 +24,10 @@ const tagSlice = createSlice({ initialState: { ...genericInitialState, lists: {} } as TagState, reducers: { ...generateCommonReducers( - TagMeta.MODEL, - TagMeta.PK + { + modelName: TagMeta.MODEL, + primaryKey: TagMeta.PK, + } ), fetch: { prepare: (params?: { node_filter: FetchFilters }, callId?: string) => { @@ -42,9 +44,7 @@ const tagSlice = createSlice({ : null, }; }, - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchError: { prepare: (errors: TagStateList["errors"], callId?: string) => ({ diff --git a/src/app/store/token/slice.ts b/src/app/store/token/slice.ts index 2fe86853f4..1008be9700 100644 --- a/src/app/store/token/slice.ts +++ b/src/app/store/token/slice.ts @@ -16,7 +16,10 @@ const tokenSlice = createSlice({ TokenMeta.PK, CreateParams, UpdateParams - >(TokenMeta.MODEL, TokenMeta.PK), + >({ + modelName: TokenMeta.MODEL, + primaryKey: TokenMeta.PK, + }), }); export const { actions } = tokenSlice; diff --git a/src/app/store/user/slice.ts b/src/app/store/user/slice.ts index 329a5ce29d..3a880e58f8 100644 --- a/src/app/store/user/slice.ts +++ b/src/app/store/user/slice.ts @@ -34,7 +34,10 @@ const userSlice = createSlice({ UserMeta.PK, CreateParams, UpdateParams - >(UserMeta.MODEL, UserMeta.PK), + >({ + modelName: UserMeta.MODEL, + primaryKey: UserMeta.PK, + }), /** * Mark the intro as completed for the authenticated user. */ @@ -46,9 +49,7 @@ const userSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, markIntroCompleteError: ( state: UserState, diff --git a/src/app/store/utils/slice.test.ts b/src/app/store/utils/slice.test.ts index 289e900515..1efacbd8a4 100644 --- a/src/app/store/utils/slice.test.ts +++ b/src/app/store/utils/slice.test.ts @@ -20,10 +20,10 @@ describe("slice", () => { slice = createSlice({ name: TokenMeta.MODEL, initialState: genericInitialState as TokenState, - reducers: generateCommonReducers( - TokenMeta.MODEL, - TokenMeta.PK - ), + reducers: generateCommonReducers({ + modelName: TokenMeta.MODEL, + primaryKey: TokenMeta.PK, + }), }); }); @@ -258,10 +258,10 @@ describe("slice", () => { name: TokenMeta.MODEL, initialState: genericInitialState as TokenState, reducers: { - ...generateCommonReducers( - TokenMeta.MODEL, - TokenMeta.PK - ), + ...generateCommonReducers({ + modelName: TokenMeta.MODEL, + primaryKey: TokenMeta.PK, + }), custom: (state: TokenState, _action: PayloadAction) => { state.errors = "small potato"; }, @@ -284,10 +284,10 @@ describe("slice", () => { name: TokenMeta.MODEL, initialState: genericInitialState as TokenState, reducers: { - ...generateCommonReducers( - TokenMeta.MODEL, - TokenMeta.PK - ), + ...generateCommonReducers({ + modelName: TokenMeta.MODEL, + primaryKey: TokenMeta.PK, + }), fetchError: (state: TokenState, action: PayloadAction) => { state.errors = `${action.payload} potato`; }, @@ -314,10 +314,10 @@ describe("slice", () => { slice = createSlice({ name: TokenMeta.MODEL, initialState: genericInitialState as TokenState, - reducers: generateCommonReducers( - TokenMeta.MODEL, - TokenMeta.PK - ), + reducers: generateCommonReducers({ + modelName: TokenMeta.MODEL, + primaryKey: TokenMeta.PK, + }), }); }); @@ -414,10 +414,10 @@ describe("slice", () => { statuses: {}, } as PodState, reducers: { - ...generateCommonReducers( - PodMeta.MODEL, - PodMeta.PK - ), + ...generateCommonReducers({ + modelName: PodMeta.MODEL, + primaryKey: PodMeta.PK, + }), refreshStart: statusHandlers.refresh.start, refreshSuccess: statusHandlers.refresh.success, refreshError: statusHandlers.refresh.error, diff --git a/src/app/store/utils/slice.ts b/src/app/store/utils/slice.ts index 350f305fab..52672cccef 100644 --- a/src/app/store/utils/slice.ts +++ b/src/app/store/utils/slice.ts @@ -132,7 +132,7 @@ export const updateErrors = < error?: boolean; } | null, event: string | null, - indexKey: K + primaryKey: K ): S => { // If no action and event have been provided then clean up the errors. if (!action && !event) { @@ -143,7 +143,7 @@ export const updateErrors = < const items = Array.isArray(item) ? item : [item]; let newErrors = state.eventErrors as S["eventErrors"][0][]; items.forEach((item) => { - const metaId = item ? item[indexKey] : null; + const metaId = item ? item[primaryKey] : null; // Clean any existing errors that match the event and machine. newErrors = newErrors.filter( (errorItem) => errorItem.event !== event || errorItem.id !== metaId @@ -167,7 +167,7 @@ export const updateErrors = < * @template E - The type of the errors for a model's state. * @template R - The type of the model's reducers. * @param name - The name of the model that matches the name in MAAS. - * @param indexKey - The key used to index a model e.g. "system_id". + * @param primaryKey - The key used to index a model e.g. "system_id". * @param initialState - Any additional initial state that doesn't * exist on all models. * @param reducers - Additional reducers or overrides for @@ -181,29 +181,31 @@ export const generateCommonReducers = < K extends keyof S["items"][0], CreateParams, UpdateParams, ->( - name: keyof SliceState, - indexKey: K, +>({ + modelName, + primaryKey, + setErrors, +}: { + modelName: keyof SliceState; + primaryKey: K; setErrors?: ( state: S, action: PayloadAction | null, event: string | null - ) => S -) => { + ) => S; +}) => { return { fetch: { // Slices that need to pass params to the payload should overwrite this // action and reducer. prepare: () => ({ meta: { - model: name, + model: modelName, method: "list", }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchStart: (state: S) => { state.loading = true; @@ -223,16 +225,14 @@ export const generateCommonReducers = < create: { prepare: (params: CreateParams) => ({ meta: { - model: name, + model: modelName, method: "create", }, payload: { params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createStart: (state: S) => { state.saved = false; @@ -256,7 +256,7 @@ export const generateCommonReducers = < // of creating duplicates. const existingIdx = state.items.findIndex( (existingItem: S["items"][0]) => - existingItem[indexKey] === action.payload[indexKey] + existingItem[primaryKey] === action.payload[primaryKey] ); if (existingIdx !== -1) { state.items[existingIdx] = action.payload; @@ -274,16 +274,14 @@ export const generateCommonReducers = < update: { prepare: (params: UpdateParams) => ({ meta: { - model: name, + model: modelName, method: "update", }, payload: { params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateStart: (state: S) => { state.saved = false; @@ -303,7 +301,7 @@ export const generateCommonReducers = < }, updateNotify: (state: S, action: PayloadAction) => { state.items.forEach((item: S["items"][0], i: number) => { - if (item[indexKey] === action.payload[indexKey]) { + if (item[primaryKey] === action.payload[primaryKey]) { state.items[i] = action.payload; } }); @@ -313,7 +311,7 @@ export const generateCommonReducers = < // action and reducer. prepare: (id: S["items"][0][K]) => ({ meta: { - model: name, + model: modelName, method: "delete", }, payload: { @@ -322,9 +320,7 @@ export const generateCommonReducers = < }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteStart: (state: S) => { state.saved = false; @@ -344,7 +340,7 @@ export const generateCommonReducers = < }, deleteNotify: (state: S, action: PayloadAction) => { const index = state.items.findIndex( - (item: S["items"][0]) => item[indexKey] === action.payload + (item: S["items"][0]) => item[primaryKey] === action.payload ); state.items.splice(index, 1); }, @@ -392,7 +388,7 @@ export type StatusHandlers< * state e.g. DHCPSnippet * @template K - A model key e.g. "id" * @param name - The name of the model that matches the name in MAAS. - * @param indexKey - The key used to index a model e.g. "id" + * @param primaryKey - The key used to index a model e.g. "id" * or "system_id". * @param handlers - A collection of status handlers. * @param setErrors - A function to update eventErrors. @@ -405,7 +401,7 @@ export const generateStatusHandlers = < // optional alternative success payload type A = void, >( - indexKey: K, + primaryKey: K, handlers: StatusHandlers[], setErrors?: ( state: Draft, @@ -432,7 +428,7 @@ export const generateStatusHandlers = < status.start && status.start(state, action); if (action.meta.item) { const statusItem = - state.statuses[String(action.meta.item[indexKey])]; + state.statuses[String(action.meta.item[primaryKey])]; const statusKey = status.statusKey; if (objectHasKey(statusKey as string, statusItem)) { statusItem[statusKey] = true; @@ -456,7 +452,7 @@ export const generateStatusHandlers = < status.success && status.success(state, action); if (action.meta.item) { const statusItem = - state.statuses[String(action.meta.item[indexKey])]; + state.statuses[String(action.meta.item[primaryKey])]; // Sometimes the server will respond with "machine/deleteNotify" // before "machine/deleteSuccess", which removes the machine // system_id from statuses so check the item exists, to be safe. @@ -487,7 +483,7 @@ export const generateStatusHandlers = < } if (action.meta.item) { const statusItem = - state.statuses[String(action.meta.item[indexKey])]; + state.statuses[String(action.meta.item[primaryKey])]; const statusKey = status.statusKey; if (objectHasKey(statusKey as string, statusItem)) { statusItem[statusKey] = false; @@ -535,9 +531,7 @@ export const generateGetReducers = < }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getStart: (state: S) => { state.loading = true; diff --git a/src/app/store/vlan/slice.ts b/src/app/store/vlan/slice.ts index f3bdca7ecf..72be45d275 100644 --- a/src/app/store/vlan/slice.ts +++ b/src/app/store/vlan/slice.ts @@ -56,7 +56,11 @@ const vlanSlice = createSlice({ VLANMeta.PK, CreateParams, UpdateParams - >(VLANMeta.MODEL, VLANMeta.PK, setErrors), + >({ + modelName: VLANMeta.MODEL, + primaryKey: VLANMeta.PK, + setErrors, + }), configureDHCP: { prepare: (params: ConfigureDHCPParams) => ({ meta: { @@ -67,9 +71,7 @@ const vlanSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, configureDHCPError: statusHandlers.configureDHCP.error, configureDHCPStart: statusHandlers.configureDHCP.start, @@ -119,9 +121,7 @@ const vlanSlice = createSlice({ params: id === null ? null : { [VLANMeta.PK]: id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, setActiveError: ( state: VLANState, diff --git a/src/app/store/vmcluster/slice.ts b/src/app/store/vmcluster/slice.ts index e288de64fa..fff6a8d25b 100644 --- a/src/app/store/vmcluster/slice.ts +++ b/src/app/store/vmcluster/slice.ts @@ -26,10 +26,10 @@ const vmClusterSlice = createSlice({ }, } as VMClusterState, reducers: { - ...generateCommonReducers( - VMClusterMeta.MODEL, - VMClusterMeta.PK - ), + ...generateCommonReducers({ + modelName: VMClusterMeta.MODEL, + primaryKey: VMClusterMeta.PK, + }), cleanup: (state: VMClusterState) => { state.errors = null; state.eventErrors = []; @@ -46,9 +46,7 @@ const vmClusterSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteError: ( state: VMClusterState, @@ -85,9 +83,7 @@ const vmClusterSlice = createSlice({ }, payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchError: ( state: VMClusterState, @@ -129,9 +125,7 @@ const vmClusterSlice = createSlice({ params: { id }, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, getError: ( state: VMClusterState, diff --git a/src/app/store/zone/slice.ts b/src/app/store/zone/slice.ts index 39890ee83d..d41db09cbc 100644 --- a/src/app/store/zone/slice.ts +++ b/src/app/store/zone/slice.ts @@ -114,9 +114,7 @@ const zoneSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, createError: (state, action: PayloadAction) => { addError(state, create, action.payload); @@ -150,9 +148,7 @@ const zoneSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, deleteError: { prepare: (action: ZonePayloadActionWithIdentifier) => action, @@ -183,9 +179,7 @@ const zoneSlice = createSlice({ prepare: () => ({ payload: null, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, fetchError: (state, action: PayloadAction) => { addError(state, fetch, action.payload); @@ -209,9 +203,7 @@ const zoneSlice = createSlice({ params, }, }), - reducer: () => { - // No state changes need to be handled for this action. - }, + reducer: () => {}, }, updateError: { prepare: (action: ZonePayloadActionWithIdentifier) => action,