UNPKG

cluedin-widget

Version:

This is the project for creating and managing widgets in CluedIn.

50 lines (46 loc) 1.54 kB
const constants = require( '../constants' ); const initialState = { layout: {}, token: '', org: '', connectedData: [] }; module.exports = function update( state = initialState, action = {} ) { switch( action.type ) { case constants.generic.UNAUTHORIZED_REQUEST: return Object.assign( {}, { layout: state.layout, token: void 0, org: state.org, connectedData: state.connectedData } ); case constants.core.RECEIVE_LAYOUT: return Object.assign( {}, { layout: action.data.layout, token: state.token, org: state.org, connectedData: state.connectedData } ); case constants.core.RECEIVE_MOST_CONNECTED: return Object.assign( {}, { connectedData: action.data, layout: state.layout, token: state.token, org: state.org } ); case constants.core.REMOVE_WIDGET: var newLayout = state.layout; newLayout.widgets = [ ...state.widgets.slice( 0, action.data.index ), ...state.widgets.slice( action.data.index + 1 ) ]; return Object.assign( {}, { connectedData: action.data, layout: newLayout, token: state.token, org: state.org } ); default : return state; } };