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";
|
2020-07-03 08:58:58 +00:00
|
|
|
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: "",
|
2020-06-20 05:29:30 +00:00
|
|
|
isCreating: false,
|
2019-11-13 07:34:59 +00:00
|
|
|
isFetching: false,
|
2019-12-11 15:14:38 +00:00
|
|
|
isRunning: {},
|
|
|
|
|
isSaving: {},
|
|
|
|
|
isDeleting: {},
|
2020-07-03 08:58:58 +00:00
|
|
|
isDirty: {},
|
2020-04-28 10:47:59 +00:00
|
|
|
currentCategory: "",
|
|
|
|
|
lastUsedEditorPage: "",
|
|
|
|
|
lastSelectedPage: "",
|
2020-05-07 07:56:37 +00:00
|
|
|
extraformData: {},
|
2020-06-03 05:40:48 +00:00
|
|
|
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;
|
2020-06-20 05:29:30 +00:00
|
|
|
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>;
|
2020-07-03 08:58:58 +00:00
|
|
|
isDirty: Record<string, boolean>;
|
2020-04-28 10:47:59 +00:00
|
|
|
currentCategory: string;
|
|
|
|
|
lastUsedEditorPage: string;
|
2020-06-03 05:40:48 +00:00
|
|
|
datasourceFieldText: Record<string, string>;
|
2020-04-28 10:47:59 +00:00
|
|
|
lastSelectedPage: string;
|
2020-05-07 07:56:37 +00:00
|
|
|
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,
|
|
|
|
|
}),
|
2020-06-20 05:29:30 +00:00
|
|
|
[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,
|
|
|
|
|
}),
|
2020-07-03 08:58:58 +00:00
|
|
|
[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
|
|
|
}),
|
2020-07-03 08:58:58 +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,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-07-03 08:58:58 +00:00
|
|
|
[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
|
|
|
}),
|
2020-07-03 08:58:58 +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,
|
|
|
|
|
},
|
2020-07-03 08:58:58 +00:00
|
|
|
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,
|
|
|
|
|
}),
|
2019-12-11 15:24:27 +00:00
|
|
|
[ReduxActionTypes.FETCH_PAGE_SUCCESS]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
lastUsed: "",
|
|
|
|
|
}),
|
2020-04-28 10:47:59 +00:00
|
|
|
[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,
|
|
|
|
|
}),
|
2020-05-07 07:56:37 +00:00
|
|
|
[ReduxActionTypes.SET_EXTRA_FORMDATA]: (
|
|
|
|
|
state: ApiPaneReduxState,
|
|
|
|
|
action: ReduxAction<{ id: string; values: {} }>,
|
|
|
|
|
) => {
|
|
|
|
|
const { id, values } = action.payload;
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
extraformData: {
|
|
|
|
|
...state.extraformData,
|
|
|
|
|
[id]: values,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-06-03 05:40:48 +00:00
|
|
|
[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;
|