cluedin-widget
Version:
This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.
70 lines (64 loc) • 2.07 kB
JavaScript
import constants from '../constants';
const initialState = {
widgetConfiguration: void 0,
token: '',
org: '',
connectedData: [],
unauthorized: false,
isFetchingConnectedData: true,
layout: void 0,
};
module.exports = function update(state = initialState, action = {}) {
switch (action.type) {
case '@@router/LOCATION_CHANGE':
if (action.payload.action === "REPLACE") {
return state;
}
return Object.assign({}, state, {
widgetConfiguration: void 0,
layout: void 0
});
case constants.generic.UNAUTHORIZED_REQUEST:
return Object.assign({}, state, {
token: void 0,
unauthorized: true,
});
case constants.core.RECEIVE_WIDGETCONFIGURATION:
return Object.assign({}, state, {
widgetConfiguration: Object.assign({}, action.data.widgetConfiguration),
layout: action.data.layout,
});
case constants.core.REQUEST_MOST_CONNECTED:
return Object.assign({}, state, {
connectedData: [],
isFetchingConnectedData: true
});
case constants.core.RECEIVE_MOST_CONNECTED:
return Object.assign({}, state, {
connectedData: action.data,
isFetchingConnectedData: false
});
case constants.core.UPDATE_TOKEN:
return Object.assign({}, state, {
token: action.data.token,
});
case constants.core.REMOVE_WIDGET:
let newWidgetConfiguration = state.widgetConfiguration;
let name = action.data.name;
let removeWidgetParameters = action.data;
if (removeWidgetParameters.tabIndex >= 0) {
state.widgetConfiguration.tabs[removeWidgetParameters.tabIndex].widgets.filter((w) => {
return w.name !== name;
});
} else {
newWidgetConfiguration.widgets = state.widgetConfiguration.widgets.filter((w) => {
return w.name !== name;
});
}
return Object.assign({}, state, {
widgetConfiguration: Object.assign({}, newWidgetConfiguration),
});
default :
return state;
}
};