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 05:07:27 +00:00
|
|
|
} from "constants/ReduxActionConstants";
|
2019-11-13 07:34:59 +00:00
|
|
|
|
|
|
|
|
const initialState: ApiPaneReduxState = {
|
|
|
|
|
isFetching: false,
|
|
|
|
|
isRunning: false,
|
|
|
|
|
isSaving: false,
|
|
|
|
|
isDeleting: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export interface ApiPaneReduxState {
|
|
|
|
|
isFetching: boolean;
|
|
|
|
|
isRunning: boolean;
|
|
|
|
|
isSaving: boolean;
|
|
|
|
|
isDeleting: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isSaving: true,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionTypes.CREATE_ACTION_SUCCESS]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isSaving: false,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.CREATE_ACTION_ERROR]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isSaving: false,
|
|
|
|
|
}),
|
2019-11-20 10:57:05 +00:00
|
|
|
[ReduxActionTypes.RUN_API_REQUEST]: (state: ApiPaneReduxState) => ({
|
2019-11-13 07:34:59 +00:00
|
|
|
...state,
|
|
|
|
|
isRunning: true,
|
|
|
|
|
}),
|
2019-11-20 10:57:05 +00:00
|
|
|
[ReduxActionTypes.RUN_API_SUCCESS]: (state: ApiPaneReduxState) => ({
|
2019-11-13 07:34:59 +00:00
|
|
|
...state,
|
|
|
|
|
isRunning: false,
|
|
|
|
|
}),
|
2019-11-20 10:57:05 +00:00
|
|
|
[ReduxActionErrorTypes.RUN_API_ERROR]: (state: ApiPaneReduxState) => ({
|
2019-11-13 07:34:59 +00:00
|
|
|
...state,
|
|
|
|
|
isRunning: false,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionTypes.UPDATE_ACTION_INIT]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isSaving: true,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionTypes.UPDATE_ACTION_SUCCESS]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isSaving: false,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.UPDATE_ACTION_ERROR]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isSaving: false,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionTypes.DELETE_ACTION_INIT]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isDeleting: true,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionTypes.DELETE_ACTION_SUCCESS]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isDeleting: false,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.DELETE_ACTION_ERROR]: (state: ApiPaneReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isDeleting: false,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default apiPaneReducer;
|