## Description Splitting uiReducers to support modules on EE #### PR fixes following issue(s) Fixes [#27581](https://github.com/appsmithorg/appsmith/issues/27581) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] JUnit - [ ] Jest - [x] 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
241 lines
6.0 KiB
TypeScript
241 lines
6.0 KiB
TypeScript
import { createReducer } from "utils/ReducerUtils";
|
|
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
|
import {
|
|
ReduxActionTypes,
|
|
ReduxActionErrorTypes,
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
|
import type { Action } from "entities/Action";
|
|
import type { UpdateActionPropertyActionPayload } from "actions/pluginActionActions";
|
|
|
|
export const initialState: ApiPaneReduxState = {
|
|
isCreating: false,
|
|
isFetching: false,
|
|
isRunning: {},
|
|
isSaving: {},
|
|
isDeleting: {},
|
|
isDirty: {},
|
|
currentCategory: "",
|
|
extraformData: {},
|
|
selectedConfigTabIndex: 0,
|
|
selectedResponseTab: "",
|
|
};
|
|
|
|
export interface ApiPaneReduxState {
|
|
isCreating: boolean; // RR
|
|
isFetching: boolean; // RR
|
|
isRunning: Record<string, boolean>;
|
|
isSaving: Record<string, boolean>; // RN
|
|
isDeleting: Record<string, boolean>;
|
|
isDirty: Record<string, boolean>;
|
|
currentCategory: string;
|
|
extraformData: Record<string, any>;
|
|
selectedConfigTabIndex: number;
|
|
selectedResponseTab: string;
|
|
selectedRightPaneTab?: string;
|
|
}
|
|
|
|
export const handlers = {
|
|
[ReduxActionTypes.FETCH_ACTIONS_INIT]: (state: ApiPaneReduxState) => ({
|
|
...state,
|
|
isFetching: true,
|
|
}),
|
|
[ReduxActionTypes.FETCH_ACTIONS_SUCCESS]: (state: ApiPaneReduxState) => ({
|
|
...state,
|
|
isFetching: false,
|
|
}),
|
|
[ReduxActionErrorTypes.FETCH_ACTIONS_ERROR]: (state: ApiPaneReduxState) => ({
|
|
...state,
|
|
isFetching: false,
|
|
}),
|
|
[ReduxActionTypes.CREATE_ACTION_INIT]: (
|
|
state: ApiPaneReduxState,
|
|
): ApiPaneReduxState => ({
|
|
...state,
|
|
isCreating: true,
|
|
}),
|
|
[ReduxActionTypes.CREATE_ACTION_SUCCESS]: (
|
|
state: ApiPaneReduxState,
|
|
): ApiPaneReduxState => ({
|
|
...state,
|
|
isCreating: false,
|
|
}),
|
|
[ReduxActionErrorTypes.CREATE_ACTION_ERROR]: (
|
|
state: ApiPaneReduxState,
|
|
): ApiPaneReduxState => ({
|
|
...state,
|
|
isCreating: false,
|
|
}),
|
|
[ReduxActionTypes.RUN_ACTION_REQUEST]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isRunning: {
|
|
...state.isRunning,
|
|
[action.payload.id]: true,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.RUN_ACTION_SUCCESS]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ [id: string]: any }>,
|
|
) => {
|
|
const actionId = Object.keys(action.payload)[0];
|
|
return {
|
|
...state,
|
|
isRunning: {
|
|
...state.isRunning,
|
|
[actionId]: false,
|
|
},
|
|
};
|
|
},
|
|
[ReduxActionErrorTypes.RUN_ACTION_ERROR]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isRunning: {
|
|
...state.isRunning,
|
|
[action.payload.id]: false,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.RUN_ACTION_CANCELLED]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
): ApiPaneReduxState => ({
|
|
...state,
|
|
isRunning: {
|
|
...state.isRunning,
|
|
[action.payload.id]: false,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.UPDATE_ACTION_PROPERTY]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<UpdateActionPropertyActionPayload>,
|
|
) => ({
|
|
...state,
|
|
isDirty: {
|
|
...state.isDirty,
|
|
[action.payload.id]: true,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.UPDATE_ACTION_INIT]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isSaving: {
|
|
...state.isSaving,
|
|
[action.payload.id]: true,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.UPDATE_ACTION_SUCCESS]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ data: Action }>,
|
|
) => ({
|
|
...state,
|
|
isSaving: {
|
|
...state.isSaving,
|
|
[action.payload.data.id]: false,
|
|
},
|
|
isDirty: {
|
|
...state.isDirty,
|
|
[action.payload.data.id]: false,
|
|
},
|
|
}),
|
|
[ReduxActionErrorTypes.UPDATE_ACTION_ERROR]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isSaving: {
|
|
...state.isSaving,
|
|
[action.payload.id]: false,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.DELETE_ACTION_INIT]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isDeleting: {
|
|
...state.isDeleting,
|
|
[action.payload.id]: true,
|
|
},
|
|
}),
|
|
[ReduxActionTypes.DELETE_ACTION_SUCCESS]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isDeleting: {
|
|
...state.isDeleting,
|
|
[action.payload.id]: false,
|
|
},
|
|
}),
|
|
[ReduxActionErrorTypes.DELETE_ACTION_ERROR]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string }>,
|
|
) => ({
|
|
...state,
|
|
isDeleting: {
|
|
...state.isDeleting,
|
|
[action.payload.id]: false,
|
|
},
|
|
}),
|
|
|
|
[ReduxActionTypes.SET_CURRENT_CATEGORY]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ category: string }>,
|
|
) => ({
|
|
...state,
|
|
currentCategory: action.payload.category,
|
|
}),
|
|
|
|
/**
|
|
* This redux action sets the extraformData field for an action. This is used to select the
|
|
* appropriate body type tab selection in the Rest API plugin based on the content-type.
|
|
* This redux action can be extended to other functionalities as well in the future.
|
|
*
|
|
* @param {ApiPaneReduxState} state
|
|
* @param {ReduxAction} action
|
|
* @returns {ApiPaneReduxState}
|
|
*/
|
|
[ReduxActionTypes.SET_EXTRA_FORMDATA]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ id: string; values: Record<string, unknown> }>,
|
|
) => {
|
|
const { id, values } = action.payload;
|
|
return {
|
|
...state,
|
|
extraformData: {
|
|
...state.extraformData,
|
|
[id]: values,
|
|
},
|
|
};
|
|
},
|
|
[ReduxActionTypes.SET_API_PANE_CONFIG_SELECTED_TAB]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ selectedTabIndex: number }>,
|
|
) => {
|
|
const { selectedTabIndex } = action.payload;
|
|
return {
|
|
...state,
|
|
selectedConfigTabIndex: selectedTabIndex,
|
|
};
|
|
},
|
|
[ReduxActionTypes.SET_API_RIGHT_PANE_SELECTED_TAB]: (
|
|
state: ApiPaneReduxState,
|
|
action: ReduxAction<{ selectedTab: number }>,
|
|
) => {
|
|
const { selectedTab } = action.payload;
|
|
return {
|
|
...state,
|
|
selectedRightPaneTab: selectedTab,
|
|
};
|
|
},
|
|
};
|
|
|
|
const apiPaneReducer = createReducer(initialState, handlers);
|
|
|
|
export default apiPaneReducer;
|