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.

219 lines (180 loc) • 5.22 kB
import constants from '../constants'; import { unauthorized } from './generic'; import { suggestedSearch, search } from '../data/search'; var requestSuggestedSearch = () => { return { type: constants.search.REQUEST_SUGGESTED_SEARCH }; }; var receiveGenericLastTasks = ( query, suggested ) => { return { type: constants.search.RECEIVE_SUGGESTED_SEARCH, data: { suggestedSearches: suggested, suggestedSearchQuery: query } }; }; var invalidGenericLastTasks = () => { return { type: constants.search.INVALID_SUGGESTED_SEARCH }; }; export function shouldFetchSuggestedSearch( q ) { return function( dispatch ) { dispatch( requestSuggestedSearch() ); return suggestedSearch( q ).then( ( resp ) => { dispatch( receiveGenericLastTasks( q, resp ) ); } ).catch( unauthorized( dispatch, invalidGenericLastTasks ) ); }; } var requestSearch = ( q, sortingDirection, filters ) => { return { type: constants.search.REQUEST_SEARCH, data: { q, sortingDirection, filters } }; }; var receiveSearch = ( searchResult ) => { return { type: constants.search.RECEIVE_SEARCH, data: { searchResult: searchResult } }; }; var invalidSearch = () => { return { type: constants.search.INVALID_SEARCH }; }; export function shouldFetchSearch( q, sortingDirection, filters ) { return function( dispatch ) { dispatch( requestSearch( q, sortingDirection, filters ) ); return search( q, sortingDirection, filters ).then( ( resp ) => { dispatch( receiveSearch( resp ) ); } ).catch( unauthorized( dispatch, invalidSearch ) ); }; } var requestInitialSearch = ( q ) => { return { type: constants.search.REQUEST_INITIAL_SEARCH, data: { q } }; }; var receiveInitialSearch = ( searchResult, q ) => { return { type: constants.search.RECEIVE_INITIAL_SEARCH, data: { searchResult, q } }; }; var invalidInitialSearch = () => { return { type: constants.search.INVALID_INITIAL_SEARCH }; }; export function shouldFetchInitialSearch( q ) { return function( dispatch ) { dispatch( requestInitialSearch( q ) ); return search( q ).then( ( resp ) => { dispatch( receiveInitialSearch( resp, q ) ); } ).catch( unauthorized( dispatch, invalidInitialSearch ) ); } } var requestSearchWithFilter = ( q, searchFilter ) => { return { type: constants.search.REQUEST_SEARCH_WITH_FILTER, data: { q, searchFilter } }; }; var receiveSearchWithFilter = ( searchResult ) => { return { type: constants.search.RECEIVE_SEARCH_WITH_FILTER, data: { searchResult } } }; var invalidSearchWithFilter = () => { return { type: constants.search.INVALID_SEARCH_WITH_FILTER }; }; export function addSearchFilter( q, sortDirection, searchFilter ) { return function( dispatch, getState ) { dispatch( requestSearchWithFilter( q, searchFilter ) ); const { selectedFilters } = getState().search; return search( q, sortDirection, selectedFilters ).then( ( resp )=> { dispatch( receiveSearchWithFilter( resp ) ); } ).catch( unauthorized( dispatch, invalidSearchWithFilter ) ); }; } var requestRemoveFilter = ( filterType ) => { return { type: constants.search.REQUEST_REMOVE_FILTER_SEARCH, data: { filterType } }; }; var receiveRemoveFilter = ( searchResult ) => { return { type: constants.search.RECEIVE_REMOVE_FILTER_SEARCH, data: { searchResult } }; }; var invalidRemoveFilter = () => { return { type: constants.search.INVALID_REMOVE_FILTER_SEARCH }; }; export function removeFilter( q, sortDirection, filterType ) { return function( dispatch, getState ) { dispatch( requestRemoveFilter( filterType ) ); return search( q, sortDirection ).then( ( resp )=> { dispatch( receiveRemoveFilter( resp ) ); } ).catch( unauthorized( dispatch, invalidRemoveFilter ) ); }; } var requestNextPage = ( pageNumber ) => { return { type: constants.search.REQUEST_NEXT_PAGE_NUMBER, data: { pageNumber } } }; var receiveNextPage = ( searchResult ) => { return { type: constants.search.RECEIVE_NEXT_PAGE_NUMBER, data: { searchResult } }; }; var invalidNextPage = () => { return { type: constants.search.INVALID_NEXT_PAGE_NUMBER } }; export function nextPage( q, sortDirection, selectedFilters, pageNumber ) { return function( dispatch ) { dispatch( requestNextPage( pageNumber ) ); return search( q, sortDirection, selectedFilters, pageNumber ).then( ( resp )=> { dispatch( receiveNextPage( resp ) ); } ).catch( unauthorized( dispatch, invalidNextPage ) ); }; }