UNPKG

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.

158 lines (128 loc) 3.7 kB
import constants from '../constants'; import { getWidgetConfiguration, getMostConnectedData } from '../data/index'; import config from '../config'; import { unauthorized } from './generic'; import { removeWidget as removeWidgetFromUserProfile } from '../userProfile/index'; export function goToLocation(location, param) { if (location === "addProvider") { window.location = config.location.goToAppProvider(); } if (location === "addProviderById") { window.location = config.location.gotToAppProvider(param); } if (location === "goToSearch") { window.location = config.location.goToSearch(param); } if (location === "entity") { window.location = config.location.goToEntity(param); } if (location === "entityWithTypeAndId") { window.location = config.location.goToEntityWithTypeAndId(param); } if (location === "goToInviteUser") { window.location = config.location.goToInviteUser(param); } if (location === "allConnectedProvider") { window.location = config.location.goToConnectedProvider(); } if (location === "signin") { window.location = config.location.goToSignInViaLogout(); } return { type: constants.core.GOTOLOCATION } } var requestWidgetConfiguration = () => { return { type: constants.core.REQUEST_WIDGETCONFIGURATION }; }; var receiveWidgetConfiguration = (widgetConfiguration, layout) => { return { type: constants.core.RECEIVE_WIDGETCONFIGURATION, data: { widgetConfiguration, layout } }; }; var invalidWidgetConfiguration = () => { return { type: constants.core.INVALID_WIDGETCONFIGURATION }; }; export function removeWidget(name, layoutInfo) { removeWidgetFromUserProfile(layoutInfo.type, name); return { type: constants.core.REMOVE_WIDGET, data: { name: name, type: layoutInfo.type, // type: option.type } }; } export function fetchWidgetConfiguration(type, org) { return function (dispatch) { dispatch(requestWidgetConfiguration()); return getWidgetConfiguration(type, org).then(function (result) { dispatch(receiveWidgetConfiguration(result.widget, result.layout)); }).catch(unauthorized(dispatch, invalidWidgetConfiguration)); }; } export function fetchWidgetConfigurationIfNeeded(type, org) { return (dispatch) => { return dispatch(fetchWidgetConfiguration(type, org)); } } var invalidMostConnected = () => { return (dispatch, getState) => { getState() }; }; var requestMostConnected = () => { return { type: constants.core.REQUEST_MOST_CONNECTED }; }; var shouldFetchMostConnected = (state)=> { return !(state.connectedData && state.connectedData.length > 0); }; var receiveMostConnected = (connectedData) => { return { type: constants.core.RECEIVE_MOST_CONNECTED, data: connectedData }; }; var fetchMostConnected = () => { return function (dispatch) { dispatch(requestMostConnected()); return getMostConnectedData().then(function (entities) { dispatch(receiveMostConnected(entities)); }).catch(unauthorized(dispatch, invalidMostConnected)); } }; export function fetchMostConnectedIfNeeded() { return (dispatch, getState) => { if (shouldFetchMostConnected(getState())) { return dispatch(fetchMostConnected()); } }; } export function shouldResetWidgetConfiguration() { return (dispatch) => { return dispatch({ type: constants.core.RESET_WIDGETCONFIGURATION }); }; } export function updateAuthToken(authInfo) { return (dispatch) => { return dispatch({ type: constants.core.UPDATE_TOKEN, data: { token: authInfo.access_token, }, }); }; }