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.
127 lines (104 loc) • 3.05 kB
JavaScript
import constants from '../constants';
import {
getCurrentProvider,
getAllProvider,
reAuthProvider as reAuthProviderRequest,
} from '../data/provider';
import { unauthorized } from './generic';
import config from '../config';
import * as userProfile from '../userProfile';
const invalidActiveProviders = () => ({
type: constants.provider.INVALID_PROVIDER,
});
const requestActiveProviders = () => ({
type: constants.provider.REQUEST_ACTIVE_PROVIDERS,
});
const receiveActiveProviders = (providers) => ({
type: constants.provider.RECEIVE_ACTIVE_PROVIDERS,
data: {
providers,
},
});
const fetchActiveProviders = () => (
(dispatch) => {
dispatch(requestActiveProviders());
getCurrentProvider().then((resp) => {
dispatch(receiveActiveProviders(resp.body));
}).catch(unauthorized(dispatch, invalidActiveProviders));
}
);
const requestActiveProvidersForUpdate = () => ({
type: constants.provider.REQUEST_ACTIVE_PROVIDERS_FOR_UPDATE,
});
const receiveActiveProvidersForUpdate = (providers) => ({
type: constants.provider.RECEIVE_ACTIVE_PROVIDERS_FOR_UPDATE,
data: {
providers,
},
});
const invalidActiveProvidersForUpdate = () => ({
type: constants.provider.INVALID_ACTIVE_PROVIDERS_FOR_UPDATE,
});
export function fetchActiveProvidersForUpdate() {
return (dispatch) => {
dispatch(requestActiveProvidersForUpdate());
getCurrentProvider().then((resp) => {
dispatch(receiveActiveProvidersForUpdate(resp.body));
}).catch(unauthorized(dispatch, invalidActiveProvidersForUpdate));
};
}
export function fetchActiveProvidersIfNeeded() {
return (dispatch) => {
dispatch(fetchActiveProviders());
};
}
export const receiveCrawlerStats = (crawlerStats) => ({
type: constants.provider.RECEIVE_CRAWLER_STATS,
data: {
crawlerStats,
},
});
const requestAllProviders = () => ({
type: constants.provider.REQUEST_ALL_PROVIDERS,
});
const receiveAllProviders = (allProviders) => ({
type: constants.provider.RECEIVE_ALL_PROVIDERS,
data: {
allProviders,
},
});
const invalidProviders = () => ({
type: constants.provider.INVALID_ALL_PROVIDERS,
});
const fetchAllProviders = () => (
(dispatch) => {
dispatch(requestAllProviders());
getAllProvider().then((resp) => {
dispatch(receiveAllProviders(resp.body));
}).catch(unauthorized(dispatch, invalidProviders));
}
);
function shouldFetchProviders(state) {
return !(state.provider.allProviders && state.provider.allProviders.length > 0);
}
export function fetchAllProvidersIfNeeded() {
return (dispatch, getState) => {
if (shouldFetchProviders(getState())) {
dispatch(fetchAllProviders());
}
};
}
export function reAuthProvider(provider) {
userProfile.setProviderId(provider.Name.toLowerCase(), provider.ProviderId);
return reAuthProviderRequest(provider).then((url) => {
config.location.redirectToUrl(url);
});
}
export function skipBusy() {
return {
type: constants.provider.RECEIVE_SKIP_BUSY,
data: {
skipBusy: true,
},
};
}