import { LayerValue , SeriesIdentifier } from '@elastic/charts' ; import { Datatable , DatatableColumn } from '../../../../expressions/public' ; import { DataPublicPluginStart } from '../../../../data/public' ; import { ClickTriggerEvent } from '../../../../charts/public' ; import { ValueClickContext } from '../../../../embeddable/public' ; import type { FieldFormat } from '../../../../field_formats/common' ; import { BucketColumns } from '../../common/types' ; export const canFilter = async ( event , actions ) : Promise < boolean > => { if ( ! event ) { return false ; } const filters = await actions . createFiltersFromValueClickAction ( event . data ) ; return Boolean ( filters . length ) ; } ; export const getFilterClickData = ( clickedLayers , bucketColumns , visData , splitChartDimension ? , splitChartFormatter ? ) : ValueClickContext [ 'data' ] [ 'data' ] => { const data = [ ] ; const matchingIndex = visData . rows . findIndex ( ( row ) => clickedLayers . every ( ( layer , index ) => { const columnId = bucketColumns [ index ] . id ; if ( ! columnId ) return ; const isCurrentLayer = row [ columnId ] === layer . groupByRollup ; if ( ! splitChartDimension ) { return isCurrentLayer ; } const value = splitChartFormatter ?. convert ( row [ splitChartDimension . id ] ) || row [ splitChartDimension . id ] ; return isCurrentLayer && value === layer . smAccessorValue ; } ) ) ; data . push ( ... clickedLayers . map ( ( clickedLayer , index ) => ( { column : visData . columns . findIndex ( ( col ) => col . id === bucketColumns [ index ] . id ) , row : matchingIndex , value : clickedLayer . groupByRollup , table : visData , } ) ) ) ; if ( splitChartDimension ) { data . push ( { column : visData . columns . findIndex ( ( col ) => col . id === splitChartDimension . id ) , row : matchingIndex , table : visData , value : clickedLayers [ 0 ] . smAccessorValue , } ) ; } return data ; } ; export const getFilterEventData = ( visData , series ) : ValueClickContext [ 'data' ] [ 'data' ] => { return visData . columns . reduce < ValueClickContext [ 'data' ] [ 'data' ] > ( ( acc , { id } , column ) => { const value = series . key ; const row = visData . rows . findIndex ( ( r ) => r [ id ] === value ) ; if ( row > - 1 ) { acc . push ( { table : visData , column , row , value , } ) ; } return acc ; } , [ ] ) ; } ;