PromucFlow_constructor/app/client/src/ce/reducers/settingsReducer.ts
Ankita Kinger a866aa47c9
chore: Optimizing the solution for supporting tenant config on admin settings (#24454)
## Description

Optimizing the solution for supporting tenant config on admin settings

#### PR fixes following issue(s)
Fixes # (issue number)

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing

#### How Has This Been Tested?
- [x] Manual
- [ ] Jest
- [ ] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-14 19:39:38 +05:30

133 lines
3.3 KiB
TypeScript

import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import {
ReduxActionErrorTypes,
ReduxActionTypes,
} from "@appsmith/constants/ReduxActionConstants";
import { createReducer } from "utils/ReducerUtils";
import type { TenantReduxState } from "./tenantReducer";
import { tenantConfigConnection } from "@appsmith/constants/tenantConstants";
export const initialState: SettingsReduxState = {
isLoading: false,
isSaving: false,
isRestarting: false,
showReleaseNotes: false,
isRestartFailed: false,
config: {},
};
export interface SettingsReduxState {
isLoading: boolean;
isSaving: boolean;
isRestarting: boolean;
showReleaseNotes: boolean;
isRestartFailed: boolean;
config: {
[key: string]: string | boolean;
};
}
export const handlers = {
[ReduxActionTypes.FETCH_ADMIN_SETTINGS]: (state: SettingsReduxState) => ({
...state,
isLoading: true,
}),
[ReduxActionTypes.FETCH_ADMIN_SETTINGS_SUCCESS]: (
state: SettingsReduxState,
action: ReduxAction<SettingsReduxState>,
) => ({
...state,
isLoading: false,
config: {
...state.config,
...action.payload,
},
}),
[ReduxActionTypes.FETCH_CURRENT_TENANT_CONFIG_SUCCESS]: (
state: SettingsReduxState & TenantReduxState<any>,
action: ReduxAction<TenantReduxState<any>>,
) => {
const configs: any = {};
tenantConfigConnection.forEach((key: string) => {
if (action.payload?.tenantConfiguration?.hasOwnProperty(key)) {
configs[key] = action.payload?.tenantConfiguration?.[key];
}
});
return {
...state,
isLoading: false,
config: {
...state.config,
...configs,
},
};
},
[ReduxActionTypes.UPDATE_TENANT_CONFIG_SUCCESS]: (
state: SettingsReduxState & TenantReduxState<any>,
action: ReduxAction<TenantReduxState<any>>,
) => {
const configs: any = {};
tenantConfigConnection.forEach((key: string) => {
if (action.payload?.tenantConfiguration?.hasOwnProperty(key)) {
configs[key] = action.payload?.tenantConfiguration?.[key];
}
});
return {
...state,
isLoading: false,
config: {
...state.config,
...configs,
},
};
},
[ReduxActionTypes.FETCH_ADMIN_SETTINGS_ERROR]: (
state: SettingsReduxState,
) => ({
...state,
isLoading: false,
}),
[ReduxActionTypes.SAVE_ADMIN_SETTINGS]: (state: SettingsReduxState) => ({
...state,
isSaving: true,
}),
[ReduxActionTypes.SAVE_ADMIN_SETTINGS_ERROR]: (
state: SettingsReduxState,
) => ({
...state,
isSaving: false,
}),
[ReduxActionTypes.SAVE_ADMIN_SETTINGS_SUCCESS]: (
state: SettingsReduxState,
) => ({
...state,
isSaving: false,
}),
[ReduxActionTypes.TOGGLE_RELEASE_NOTES]: (
state: SettingsReduxState,
action: ReduxAction<boolean>,
) => ({
...state,
showReleaseNotes: action.payload,
}),
[ReduxActionTypes.RESTART_SERVER_POLL]: (state: SettingsReduxState) => ({
...state,
isRestarting: true,
}),
[ReduxActionTypes.RETRY_RESTART_SERVER_POLL]: (
state: SettingsReduxState,
) => ({
...state,
isRestarting: true,
isRestartFailed: false,
}),
[ReduxActionErrorTypes.RESTART_SERVER_ERROR]: (
state: SettingsReduxState,
) => ({
...state,
isRestartFailed: true,
}),
};
export default createReducer(initialState, handlers);