import { VIEW_BY_JOB_LABEL } from '../../explorer_constants' ; import { ActionPayload } from '../../explorer_dashboard_service' ; import { ExplorerState } from './state' ; export function setInfluencerFilterSettings ( state , payload ) { const { filterQuery : influencersFilterQuery , isAndOperator , filteredFields , queryString , tableQueryString , } = payload ; const { selectedCells , viewBySwimlaneOptions } = state ; let selectedViewByFieldName = state . viewBySwimlaneFieldName ; const filteredViewBySwimlaneOptions = viewBySwimlaneOptions . filter ( ( d ) => filteredFields . includes ( d ) ) ; if ( isAndOperator && selectedCells === undefined ) { selectedViewByFieldName = VIEW_BY_JOB_LABEL ; } else { for ( let i = 0 ; i < filteredFields . length ; i ++ ) { if ( filteredViewBySwimlaneOptions . includes ( filteredFields [ i ] ) && ( selectedCells === undefined || ( selectedCells && selectedCells . type === 'overall' ) ) ) { selectedViewByFieldName = filteredFields [ i ] ; break ; } } } return { ... state , filterActive : true , filteredFields , influencersFilterQuery , isAndOperator , queryString , tableQueryString , maskAll : selectedViewByFieldName === VIEW_BY_JOB_LABEL || filteredFields . includes ( selectedViewByFieldName ) === false , viewBySwimlaneFieldName : selectedViewByFieldName , viewBySwimlaneOptions : filteredViewBySwimlaneOptions , viewByFromPage : 1 , } ; }