PromucFlow_constructor/app/client/src/reducers/entityReducers/datasourceReducer.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-11-25 05:07:27 +00:00
import { createReducer } from "utils/AppsmithUtils";
import { ReduxActionTypes, ReduxAction } from "constants/ReduxActionConstants";
import { Datasource } from "api/DatasourcesApi";
2019-11-07 09:32:38 +00:00
export interface DatasourceDataState {
list: Datasource[];
loading: boolean;
}
2019-11-07 09:32:38 +00:00
const initialState: DatasourceDataState = {
list: [],
loading: false,
};
2019-11-07 09:32:38 +00:00
const datasourceReducer = createReducer(initialState, {
[ReduxActionTypes.FETCH_DATASOURCES_INIT]: (state: DatasourceDataState) => {
return { ...state, loading: true };
},
2019-11-07 09:32:38 +00:00
[ReduxActionTypes.CREATE_DATASOURCE_INIT]: (state: DatasourceDataState) => {
return { ...state, loading: true };
},
2019-11-07 09:32:38 +00:00
[ReduxActionTypes.FETCH_DATASOURCES_SUCCESS]: (
state: DatasourceDataState,
action: ReduxAction<Datasource[]>,
) => {
return {
...state,
loading: false,
list: action.payload,
};
},
2019-11-07 09:32:38 +00:00
[ReduxActionTypes.CREATE_DATASOURCE_SUCCESS]: (
state: DatasourceDataState,
action: ReduxAction<Datasource>,
) => {
return {
...state,
loading: false,
list: state.list.concat(action.payload),
};
},
});
2019-11-07 09:32:38 +00:00
export default datasourceReducer;