Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui/agg_response/tabify] update types for search/expressions/build_tabular_inspector_data.ts #58130

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 4 additions & 10 deletions src/legacy/core_plugins/data/public/search/tabify/get_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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 => {
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/data/public/search/tabify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

export { tabifyAggResponse } from './tabify';
export { tabifyGetColumns } from './get_columns';

export { TabbedTable, TabbedAggRow, TabbedAggColumn } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -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<TabbedAggColumn['id'], TabbedAggColumn['value']>;

/**
* 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;

Expand Down Expand Up @@ -79,7 +77,7 @@ export class TabbedAggResponseWriter {
}
}

response() {
response(): TabbedTable {
return {
columns: this.columns,
rows: this.rows,
Expand Down
17 changes: 17 additions & 0 deletions src/legacy/core_plugins/data/public/search/tabify/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { RangeFilterParams } from '../../../../../../plugins/data/public';
import { IAggConfig } from '../aggs';

/** @internal **/
export interface TabbedRangeFilterParams extends RangeFilterParams {
Expand All @@ -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<TabbedAggColumn['id'], string | number>;

/** @public **/
export interface TabbedTable {
columns: TabbedAggColumn[];
rows: TabbedAggRow[];
}