import { groupBy } from 'lodash' ; import { IAggConfig } from '../aggs' ; import { TabbedAggColumn } from './types' ; const getColumn = ( agg , i ) : TabbedAggColumn => { let name = '' ; try { name = agg . makeLabel ( ) ; } catch ( e ) { } return { aggConfig : agg , id : `col-${ i }-${ agg . id }` , name , } ; } ; param { AggConfigs } aggs param { boolean } minimalColumns export function tabifyGetColumns ( aggs , minimalColumns ) { if ( minimalColumns ) { return aggs . map ( ( agg , i ) => getColumn ( agg , i ) ) ; } const columns = [ ] ; const grouped = groupBy ( aggs , ( agg ) => { return agg . type . type ; } ) ; if ( ! grouped . buckets ) { return grouped . metrics . map ( ( agg , i ) => getColumn ( agg , i ) ) ; } let columnIndex = 0 ; grouped . buckets . forEach ( ( agg ) => { columns . push ( getColumn ( agg , columnIndex ++ ) ) ; grouped . metrics . forEach ( ( metric ) => { columns . push ( getColumn ( metric , columnIndex ++ ) ) ; } ) ; } ) ; return columns ; }