2019-04-17 10:44:48 +00:00
|
|
|
import { combineReducers } from "redux";
|
2018-08-27 15:27:09 +00:00
|
|
|
|
2019-04-17 10:44:48 +00:00
|
|
|
import { ActionType, IAction, ICurrentInstanceState, IDataState } from "./types";
|
2018-08-27 15:27:09 +00:00
|
|
|
|
|
|
|
const initialDataState = {
|
2019-04-17 10:44:48 +00:00
|
|
|
error: false,
|
|
|
|
isLoadingGraph: false,
|
|
|
|
isLoadingInstances: false
|
|
|
|
};
|
2018-08-27 15:27:09 +00:00
|
|
|
const data = (state: IDataState = initialDataState, action: IAction) => {
|
2019-04-17 10:44:48 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case ActionType.REQUEST_INSTANCES:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
instances: [],
|
|
|
|
isLoadingInstances: true
|
|
|
|
};
|
|
|
|
case ActionType.RECEIVE_INSTANCES:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
instances: action.payload,
|
|
|
|
isLoadingInstances: false
|
|
|
|
};
|
|
|
|
case ActionType.REQUEST_GRAPH:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isLoadingGraph: true
|
|
|
|
};
|
|
|
|
case ActionType.RECEIVE_GRAPH:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
graph: action.payload,
|
|
|
|
isLoadingGraph: false
|
|
|
|
};
|
|
|
|
case ActionType.GRAPH_LOAD_ERROR:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
error: true,
|
|
|
|
isLoadingGraph: false,
|
|
|
|
isLoadingInstances: false
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2018-08-27 15:27:09 +00:00
|
|
|
|
2018-09-01 17:24:05 +00:00
|
|
|
const initialCurrentInstanceState = {
|
2019-04-17 10:44:48 +00:00
|
|
|
currentInstanceDetails: null,
|
|
|
|
currentInstanceName: null,
|
|
|
|
error: false,
|
|
|
|
isLoadingInstanceDetails: false
|
|
|
|
};
|
|
|
|
const currentInstance = (state = initialCurrentInstanceState, action: IAction): ICurrentInstanceState => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ActionType.SELECT_INSTANCE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentInstanceName: action.payload,
|
|
|
|
isLoadingInstanceDetails: true
|
|
|
|
};
|
|
|
|
case ActionType.RECEIVE_INSTANCE_DETAILS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentInstanceDetails: action.payload,
|
|
|
|
isLoadingInstanceDetails: false
|
|
|
|
};
|
|
|
|
case ActionType.DESELECT_INSTANCE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentInstanceDetails: null,
|
|
|
|
currentInstanceName: null
|
|
|
|
};
|
|
|
|
case ActionType.INSTANCE_LOAD_ERROR:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
error: true,
|
|
|
|
isLoadingInstanceDetails: false
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2018-09-01 17:24:05 +00:00
|
|
|
};
|
2018-08-27 15:27:09 +00:00
|
|
|
|
|
|
|
export const rootReducer = combineReducers({
|
2019-04-17 10:44:48 +00:00
|
|
|
currentInstance,
|
|
|
|
data
|
|
|
|
});
|