import { set } from '@elastic/safer-lodash-set' ; import { FormattedData } from '../../../../../plugins/inspector/public' ; import { TabbedTable } from '../../../common' ; import { FormatFactory } from '../../../common/field_formats/utils' ; import { createFilter } from './create_filter' ; deprecated todo export async function buildTabularInspectorData ( table , { queryFilter , deserializeFieldFormat , } ) { const aggConfigs = table . columns . map ( ( column ) => column . aggConfig ) ; const rows = table . rows . map ( ( row ) => { return table . columns . reduce < Record < string , FormattedData > > ( ( prev , cur , colIndex ) => { const value = row [ cur . id ] ; let format = cur . aggConfig . toSerializedFieldFormat ( ) ; if ( Object . keys ( format ) . length < 1 ) { format = { id : 'string' } ; } const fieldFormatter = deserializeFieldFormat ( format ) ; prev [ `col-${ colIndex }-${ cur . aggConfig . id }` ] = new FormattedData ( value , fieldFormatter . convert ( value ) ) ; return prev ; } , { } ) ; } ) ; const columns = table . columns . map ( ( col , colIndex ) => { const field = col . aggConfig . getField ( ) ; const isCellContentFilterable = col . aggConfig . isFilterable ( ) && ( ! field || field . filterable ) ; return { name : col . name , field : `col-${ colIndex }-${ col . aggConfig . id }` , filter : isCellContentFilterable && ( ( value ) => { const rowIndex = rows . findIndex ( ( row ) => row [ `col-${ colIndex }-${ col . aggConfig . id }` ] . raw === value . raw ) ; const filter = createFilter ( aggConfigs , table , colIndex , rowIndex , value . raw ) ; if ( filter ) { queryFilter . addFilters ( filter ) ; } } ) , filterOut : isCellContentFilterable && ( ( value ) => { const rowIndex = rows . findIndex ( ( row ) => row [ `col-${ colIndex }-${ col . aggConfig . id }` ] . raw === value . raw ) ; const filter = createFilter ( aggConfigs , table , colIndex , rowIndex , value . raw ) ; if ( filter ) { const notOther = value . raw !== '__other__' ; const notMissing = value . raw !== '__missing__' ; if ( Array . isArray ( filter ) ) { filter . forEach ( ( f ) => set ( f , 'meta.negate' , notOther && notMissing ) ) ; } else { set ( filter , 'meta.negate' , notOther && notMissing ) ; } queryFilter . addFilters ( filter ) ; } } ) , } ; } ) ; return { columns , rows } ; }