import { isEqual } from 'lodash' ; import { ActionPayload } from '../../explorer_dashboard_service' ; import { getDefaultSwimlaneData , getInfluencers } from '../../explorer_utils' ; import { getIndexPattern } from './get_index_pattern' ; import { ExplorerState } from './state' ; export const jobSelectionChange = ( state , payload ) : ExplorerState => { const { selectedJobs } = payload ; const stateUpdate = { ... state , noInfluencersConfigured : getInfluencers ( selectedJobs ) . length === 0 , overallSwimlaneData : getDefaultSwimlaneData ( ) , selectedJobs , viewByFromPage : ! state . selectedJobs || isEqual ( state . selectedJobs , selectedJobs ) ? state . viewByFromPage : 1 , } ; if ( stateUpdate . noInfluencersConfigured === true ) { const noFilterState = { filterActive : false , filteredFields : [ ] , influencersFilterQuery : undefined , maskAll : false , queryString : '' , tableQueryString : '' , } ; Object . assign ( stateUpdate , noFilterState ) ; } else { stateUpdate . indexPattern = getIndexPattern ( selectedJobs ) ; } stateUpdate . loading = true ; return stateUpdate ; } ;