2018-08-27 15:27:09 +00:00
|
|
|
import { combineReducers } from 'redux';
|
|
|
|
|
2018-08-29 01:52:21 +00:00
|
|
|
import { ActionType, IAction, IDataState } from './types';
|
2018-08-27 15:27:09 +00:00
|
|
|
|
|
|
|
const initialDataState = {
|
|
|
|
isLoadingInstances: false,
|
|
|
|
}
|
|
|
|
const data = (state: IDataState = initialDataState, action: IAction) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ActionType.REQUEST_INSTANCES:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
instances: [],
|
|
|
|
isLoadingInstances: true,
|
|
|
|
};
|
|
|
|
case ActionType.RECEIVE_INSTANCES:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
instances: action.payload,
|
|
|
|
isLoadingInstances: false,
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 01:52:21 +00:00
|
|
|
const currentInstanceName = (state: string | null = null, action: IAction): string | null => {
|
2018-08-27 15:27:09 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case ActionType.SELECT_INSTANCE:
|
|
|
|
return action.payload;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const rootReducer = combineReducers({
|
2018-08-29 01:52:21 +00:00
|
|
|
currentInstanceName,
|
2018-08-27 15:27:09 +00:00
|
|
|
data,
|
|
|
|
})
|