diff --git a/src/legacy/core_plugins/data/public/search/expressions/build_tabular_inspector_data.ts b/src/legacy/core_plugins/data/public/search/expressions/build_tabular_inspector_data.ts index 8f7953c408a97..e85e9deff6ddf 100644 --- a/src/legacy/core_plugins/data/public/search/expressions/build_tabular_inspector_data.ts +++ b/src/legacy/core_plugins/data/public/search/expressions/build_tabular_inspector_data.ts @@ -22,20 +22,8 @@ import { set } from 'lodash'; import { FormattedData } from '../../../../../../plugins/inspector/public'; // @ts-ignore import { createFilter } from './create_filter'; -interface Column { - id: string; - name: string; - aggConfig: any; -} - -interface Row { - [key: string]: any; -} -interface Table { - columns: Column[]; - rows: Row[]; -} +import { TabbedTable } from '../tabify'; /** * @deprecated @@ -52,7 +40,7 @@ interface Table { * inspector. It will only be called when the data view in the inspector is opened. */ export async function buildTabularInspectorData( - table: Table, + table: TabbedTable, queryFilter: { addFilters: (filter: any) => void } ) { const aggConfigs = table.columns.map(column => column.aggConfig); diff --git a/src/legacy/core_plugins/data/public/search/tabify/get_columns.test.ts b/src/legacy/core_plugins/data/public/search/tabify/get_columns.test.ts index 0328e87d8b832..cfd4cd7de640b 100644 --- a/src/legacy/core_plugins/data/public/search/tabify/get_columns.test.ts +++ b/src/legacy/core_plugins/data/public/search/tabify/get_columns.test.ts @@ -17,8 +17,9 @@ * under the License. */ -import { tabifyGetColumns, AggColumn } from './get_columns'; +import { tabifyGetColumns } from './get_columns'; import { AggConfigs, AggGroupNames, Schemas } from '../aggs'; +import { TabbedAggColumn } from './types'; jest.mock('ui/new_platform'); @@ -140,7 +141,7 @@ describe('get columns', () => { false ); - function checkColumns(column: AggColumn, i: number) { + function checkColumns(column: TabbedAggColumn, i: number) { expect(column).toHaveProperty('aggConfig'); switch (i) { diff --git a/src/legacy/core_plugins/data/public/search/tabify/get_columns.ts b/src/legacy/core_plugins/data/public/search/tabify/get_columns.ts index 54f09f6c6364f..8bffca65b4ae2 100644 --- a/src/legacy/core_plugins/data/public/search/tabify/get_columns.ts +++ b/src/legacy/core_plugins/data/public/search/tabify/get_columns.ts @@ -19,14 +19,8 @@ import { groupBy } from 'lodash'; import { IAggConfig } from '../aggs'; - -export interface AggColumn { - aggConfig: IAggConfig; - id: string; - name: string; -} - -const getColumn = (agg: IAggConfig, i: number): AggColumn => { +import { TabbedAggColumn } from './types'; +const getColumn = (agg: IAggConfig, i: number): TabbedAggColumn => { return { aggConfig: agg, id: `col-${i}-${agg.id}`, @@ -40,14 +34,14 @@ const getColumn = (agg: IAggConfig, i: number): AggColumn => { * @param {AggConfigs} aggs - the agg configs object to which the aggregation response correlates * @param {boolean} minimalColumns - setting to true will only return a column for the last bucket/metric instead of one for each level */ -export function tabifyGetColumns(aggs: IAggConfig[], minimalColumns: boolean): AggColumn[] { +export function tabifyGetColumns(aggs: IAggConfig[], minimalColumns: boolean): TabbedAggColumn[] { // pick the columns if (minimalColumns) { return aggs.map((agg, i) => getColumn(agg, i)); } // supposed to be bucket,...metrics,bucket,...metrics - const columns: AggColumn[] = []; + const columns: TabbedAggColumn[] = []; // separate the metrics const grouped = groupBy(aggs, agg => { diff --git a/src/legacy/core_plugins/data/public/search/tabify/index.ts b/src/legacy/core_plugins/data/public/search/tabify/index.ts index be8d64510033c..90ac3f2fb730b 100644 --- a/src/legacy/core_plugins/data/public/search/tabify/index.ts +++ b/src/legacy/core_plugins/data/public/search/tabify/index.ts @@ -19,3 +19,5 @@ export { tabifyAggResponse } from './tabify'; export { tabifyGetColumns } from './get_columns'; + +export { TabbedTable, TabbedAggRow, TabbedAggColumn } from './types'; diff --git a/src/legacy/core_plugins/data/public/search/tabify/response_writer.ts b/src/legacy/core_plugins/data/public/search/tabify/response_writer.ts index 4c4578e505b71..c910eda024540 100644 --- a/src/legacy/core_plugins/data/public/search/tabify/response_writer.ts +++ b/src/legacy/core_plugins/data/public/search/tabify/response_writer.ts @@ -19,26 +19,24 @@ import { isEmpty } from 'lodash'; import { IAggConfigs } from '../aggs/agg_configs'; -import { AggColumn, tabifyGetColumns } from './get_columns'; +import { tabifyGetColumns } from './get_columns'; -import { TabbedResponseWriterOptions } from './types'; +import { TabbedResponseWriterOptions, TabbedAggColumn, TabbedAggRow, TabbedTable } from './types'; -interface TabbedAggColumn { +interface BufferColumn { id: string; value: string | number; } -type TabbedAggRow = Record; - /** * Writer class that collects information about an aggregation response and * produces a table, or a series of tables. */ export class TabbedAggResponseWriter { - columns: AggColumn[]; + columns: TabbedAggColumn[]; rows: TabbedAggRow[] = []; - bucketBuffer: TabbedAggColumn[] = []; - metricBuffer: TabbedAggColumn[] = []; + bucketBuffer: BufferColumn[] = []; + metricBuffer: BufferColumn[] = []; private readonly partialRows: boolean; @@ -79,7 +77,7 @@ export class TabbedAggResponseWriter { } } - response() { + response(): TabbedTable { return { columns: this.columns, rows: this.rows, diff --git a/src/legacy/core_plugins/data/public/search/tabify/types.ts b/src/legacy/core_plugins/data/public/search/tabify/types.ts index 3a02a2b64f0c3..964a9d2080e7b 100644 --- a/src/legacy/core_plugins/data/public/search/tabify/types.ts +++ b/src/legacy/core_plugins/data/public/search/tabify/types.ts @@ -18,6 +18,7 @@ */ import { RangeFilterParams } from '../../../../../../plugins/data/public'; +import { IAggConfig } from '../aggs'; /** @internal **/ export interface TabbedRangeFilterParams extends RangeFilterParams { @@ -30,3 +31,19 @@ export interface TabbedResponseWriterOptions { partialRows: boolean; timeRange?: { [key: string]: RangeFilterParams }; } + +/** @public **/ +export interface TabbedAggColumn { + aggConfig: IAggConfig; + id: string; + name: string; +} + +/** @public **/ +export type TabbedAggRow = Record; + +/** @public **/ +export interface TabbedTable { + columns: TabbedAggColumn[]; + rows: TabbedAggRow[]; +}