PromucFlow_constructor/app/client/src/reducers/uiReducers/apiPaneReducer.ts

239 lines
5.8 KiB
TypeScript
Raw Normal View History

2019-11-25 05:07:27 +00:00
import { createReducer } from "utils/AppsmithUtils";
2019-11-13 07:34:59 +00:00
import {
ReduxActionTypes,
ReduxActionErrorTypes,
2019-11-25 09:15:11 +00:00
ReduxAction,
2019-11-25 05:07:27 +00:00
} from "constants/ReduxActionConstants";
2020-06-04 13:49:22 +00:00
import { RestAction } from "entities/Action";
import { UpdateActionPropertyActionPayload } from "actions/actionActions";
2019-11-13 07:34:59 +00:00
const initialState: ApiPaneReduxState = {
2019-11-25 09:15:11 +00:00
lastUsed: "",
isCreating: false,
2019-11-13 07:34:59 +00:00
isFetching: false,
2019-12-11 15:14:38 +00:00
isRunning: {},
isSaving: {},
isDeleting: {},
isDirty: {},
currentCategory: "",
lastUsedEditorPage: "",
lastSelectedPage: "",
extraformData: {},
datasourceFieldText: {},
2019-11-13 07:34:59 +00:00
};
2020-06-18 14:16:49 +00:00
2019-11-13 07:34:59 +00:00
export interface ApiPaneReduxState {
2019-11-25 09:15:11 +00:00
lastUsed: string;
isCreating: boolean;
2019-11-13 07:34:59 +00:00
isFetching: boolean;
2019-12-11 15:14:38 +00:00
isRunning: Record<string, boolean>;
isSaving: Record<string, boolean>;
isDeleting: Record<string, boolean>;
isDirty: Record<string, boolean>;
currentCategory: string;
lastUsedEditorPage: string;
datasourceFieldText: Record<string, string>;
lastSelectedPage: string;
extraformData: Record<string, any>;
2019-11-13 07:34:59 +00:00
}
const apiPaneReducer = createReducer(initialState, {
[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]: (
2019-12-11 15:14:38 +00:00
state: ApiPaneReduxState,
2020-02-13 11:38:34 +00:00
action: ReduxAction<{ id: string }>,
2019-12-11 15:14:38 +00:00
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isRunning: {
...state.isRunning,
2020-02-13 11:38:34 +00:00
[action.payload.id]: true,
2019-12-11 15:14:38 +00:00
},
2019-11-13 07:34:59 +00:00
}),
[ReduxActionTypes.RUN_ACTION_SUCCESS]: (
2019-12-11 15:14:38 +00:00
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]: (
2019-12-11 15:14:38 +00:00
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isRunning: {
...state.isRunning,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
[ReduxActionTypes.UPDATE_ACTION_PROPERTY]: (
state: ApiPaneReduxState,
action: ReduxAction<UpdateActionPropertyActionPayload>,
) => ({
...state,
isDirty: {
...state.isDirty,
[action.payload.id]: true,
},
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.UPDATE_ACTION_INIT]: (
state: ApiPaneReduxState,
action: ReduxAction<{ data: RestAction }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isSaving: {
...state.isSaving,
[action.payload.data.id]: true,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.UPDATE_ACTION_SUCCESS]: (
state: ApiPaneReduxState,
action: ReduxAction<{ data: RestAction }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isSaving: {
...state.isSaving,
[action.payload.data.id]: false,
},
isDirty: {
...state.isDirty,
[action.payload.data.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionErrorTypes.UPDATE_ACTION_ERROR]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isSaving: {
...state.isSaving,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.DELETE_ACTION_INIT]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isDeleting: {
...state.isDeleting,
[action.payload.id]: true,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.DELETE_ACTION_SUCCESS]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isDeleting: {
...state.isDeleting,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionErrorTypes.DELETE_ACTION_ERROR]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isDeleting: {
...state.isDeleting,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-11-25 09:15:11 +00:00
[ReduxActionTypes.API_PANE_CHANGE_API]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
...state,
lastUsed: action.payload.id,
}),
[ReduxActionTypes.FETCH_PAGE_SUCCESS]: (state: ApiPaneReduxState) => ({
...state,
lastUsed: "",
}),
[ReduxActionTypes.SET_CURRENT_CATEGORY]: (
state: ApiPaneReduxState,
action: ReduxAction<{ category: string }>,
) => ({
...state,
currentCategory: action.payload.category,
}),
[ReduxActionTypes.SET_LAST_USED_EDITOR_PAGE]: (
state: ApiPaneReduxState,
action: ReduxAction<{ path: string }>,
) => ({
...state,
lastUsedEditorPage: action.payload.path,
}),
[ReduxActionTypes.SET_LAST_SELECTED_PAGE_PAGE]: (
state: ApiPaneReduxState,
action: ReduxAction<{ selectedPageId: string }>,
) => ({
...state,
lastSelectedPage: action.payload.selectedPageId,
}),
[ReduxActionTypes.SET_EXTRA_FORMDATA]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string; values: {} }>,
) => {
const { id, values } = action.payload;
return {
...state,
extraformData: {
...state.extraformData,
[id]: values,
},
};
},
[ReduxActionTypes.SET_DATASOURCE_FIELD_TEXT]: (
state: ApiPaneReduxState,
action: ReduxAction<{ apiId: string; value: string }>,
) => {
const { apiId } = action.payload;
return {
...state,
datasourceFieldText: {
...state.datasourceFieldText,
[apiId]: action.payload.value,
},
};
},
2019-11-13 07:34:59 +00:00
});
export default apiPaneReducer;