import { IndexPattern } from '../../../../../opensearch_dashboards_services' ; import { shortenDottedString } from '../../../../helpers' ; export type SortOrder = [ string , string ] ; export interface ColumnProps { name : string ; displayName : string ; isSortable : boolean ; isRemoveable : boolean ; colLeftIdx : number ; colRightIdx : number ; } param timeFieldName export function getTimeColumn ( timeFieldName ) { return { name : timeFieldName , displayName : 'Time' , isSortable : true , isRemoveable : false , colLeftIdx : - 1 , colRightIdx : - 1 , } ; } param columns param indexPattern param hideTimeField param isShortDots export function getDisplayedColumns ( columns , indexPattern , hideTimeField , isShortDots ) { if ( ! Array . isArray ( columns ) || typeof indexPattern !== 'object' || ! indexPattern . getFieldByName ) { return [ ] ; } const columnProps = columns . map ( ( column , idx ) => { const field = indexPattern . getFieldByName ( column ) ; return { name : column , displayName : isShortDots ? shortenDottedString ( column ) : column , isSortable : field && field . sortable ? true : false , isRemoveable : column !== '_source' || columns . length > 1 , colLeftIdx : idx - 1 < 0 ? - 1 : idx - 1 , colRightIdx : idx + 1 >= columns . length ? - 1 : idx + 1 , } ; } ) ; return ! hideTimeField && indexPattern . timeFieldName ? [ getTimeColumn ( indexPattern . timeFieldName ) , ... columnProps ] : columnProps ; }