Skip to content

Commit

Permalink
tabifyAggResponse should return datatable
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Oct 15, 2020
1 parent f2bc40e commit 08256ae
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/common/search/expressions/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export * from './courier_inspector_stats';
export * from './serialize_agg_config';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { KibanaDatatableColumnMeta } from '../../../../../expressions/common';
import { IAggConfig } from '../../../index';

/** @internal */
export const serializeAggConfig = (aggConfig: IAggConfig): KibanaDatatableColumnMeta => {
return {
type: aggConfig.type.name,
indexPatternId: aggConfig.getIndexPattern().id,
aggConfigParams: aggConfig.serialize().params,
};
};
20 changes: 17 additions & 3 deletions src/plugins/data/common/search/tabify/response_writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import { isEmpty } from 'lodash';
import { IAggConfigs } from '../aggs';
import { tabifyGetColumns } from './get_columns';

import { TabbedResponseWriterOptions, TabbedAggColumn, TabbedAggRow, TabbedTable } from './types';
import { TabbedResponseWriterOptions, TabbedAggColumn, TabbedAggRow } from './types';
import { serializeAggConfig } from '../expressions/utils';
import {
KibanaDatatable,
KibanaDatatableColumn,
} from '../../../../expressions/common/expression_types/specs';

interface BufferColumn {
id: string;
Expand Down Expand Up @@ -76,9 +81,18 @@ export class TabbedAggResponseWriter {
}
}

response(): TabbedTable {
response(): KibanaDatatable {
return {
columns: this.columns,
type: 'kibana_datatable',
columns: this.columns.map((column) => {
const cleanedColumn: KibanaDatatableColumn = {
id: column.id,
name: column.name,
meta: serializeAggConfig(column.aggConfig),
formatHint: column.aggConfig.toSerializedFieldFormat(),
};
return cleanedColumn;
}),
rows: this.rows,
};
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/common/search/tabify/tabify_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export function flattenHit(
}

export interface TabifyDocsOptions {
formatted: boolean;
deep: boolean;
source: boolean;
}
Expand Down
20 changes: 1 addition & 19 deletions src/plugins/data/public/search/expressions/esaggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { get, hasIn } from 'lodash';
import { i18n } from '@kbn/i18n';
import { KibanaDatatable, KibanaDatatableColumn } from 'src/plugins/expressions/public';
import { PersistedState } from '../../../../../plugins/visualizations/public';
import { Adapters } from '../../../../../plugins/inspector/public';

Expand Down Expand Up @@ -49,7 +48,6 @@ import {
getSearchService,
} from '../../services';
import { buildTabularInspectorData } from './build_tabular_inspector_data';
import { serializeAggConfig } from './utils';

export interface RequestHandlerParams {
searchSource: ISearchSource;
Expand Down Expand Up @@ -279,22 +277,6 @@ export const esaggs = (): EsaggsExpressionFunctionDefinition => ({
abortSignal: (abortSignal as unknown) as AbortSignal,
});

const table: KibanaDatatable = {
type: 'kibana_datatable',
rows: response.rows,
columns: response.columns.map((column: any) => {
const cleanedColumn: KibanaDatatableColumn = {
id: column.id,
name: column.name,
meta: serializeAggConfig(column.aggConfig),
};
if (args.includeFormatHints) {
cleanedColumn.formatHint = column.aggConfig.toSerializedFieldFormat();
}
return cleanedColumn;
}),
};

return table;
return response;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,9 @@
* under the License.
*/

import { KibanaDatatableColumnMeta } from '../../../../../../plugins/expressions/public';
import { IAggConfig } from '../../../../common';
import { IndexPattern } from '../../../index_patterns';
import { getSearchService } from '../../../../public/services';

/** @internal */
export const serializeAggConfig = (aggConfig: IAggConfig): KibanaDatatableColumnMeta => {
return {
type: aggConfig.type.name,
indexPatternId: aggConfig.getIndexPattern().id,
aggConfigParams: aggConfig.serialize().params,
};
};

interface DeserializeAggConfigParams {
type: string;
aggConfigParams: Record<string, any>;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/expressions/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './serialize_agg_config';
export * from './deserialize_agg_config';

0 comments on commit 08256ae

Please sign in to comment.