Skip to content

Commit

Permalink
Remove buildTabularInspectorData dependency on aggConfig.getFieldForm…
Browse files Browse the repository at this point in the history
…atter.
  • Loading branch information
lukeelmers committed Jun 23, 2020
1 parent 731505b commit 78c97c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { set } from 'lodash';
import { FormattedData } from '../../../../../plugins/inspector/public';
import { FormatFactory } from '../../../common/field_formats/utils';
import { TabbedTable } from '../tabify';
import { createFilter } from './create_filter';

Expand All @@ -38,14 +39,30 @@ import { createFilter } from './create_filter';
*/
export async function buildTabularInspectorData(
table: TabbedTable,
queryFilter: { addFilters: (filter: any) => void }
{
queryFilter,
deserializeFieldFormat,
}: {
queryFilter: { addFilters: (filter: any) => void };
deserializeFieldFormat: FormatFactory;
}
) {
const aggConfigs = table.columns.map((column) => column.aggConfig);
const rows = table.rows.map((row) => {
return table.columns.reduce<Record<string, FormattedData>>((prev, cur, colIndex) => {
const value = row[cur.id];
const fieldFormatter = cur.aggConfig.fieldFormatter('text');
prev[`col-${colIndex}-${cur.aggConfig.id}`] = new FormattedData(value, fieldFormatter(value));

let format = cur.aggConfig.toSerializedFieldFormat();
if (Object.keys(format).length < 1) {
// If no format exists, fall back to string as a default
format = { id: 'string' };
}
const fieldFormatter = deserializeFieldFormat(format);

prev[`col-${colIndex}-${cur.aggConfig.id}`] = new FormattedData(
value,
fieldFormatter.convert(value)
);
return prev;
}, {});
});
Expand Down
13 changes: 11 additions & 2 deletions src/plugins/data/public/search/expressions/esaggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ import { ISearchSource } from '../search_source';
import { tabifyAggResponse } from '../tabify';
import { Filter, Query, TimeRange, IIndexPattern, isRangeFilter } from '../../../common';
import { FilterManager, calculateBounds, getTime } from '../../query';
import { getSearchService, getQueryService, getIndexPatterns } from '../../services';
import {
getFieldFormats,
getIndexPatterns,
getQueryService,
getSearchService,
} from '../../services';
import { buildTabularInspectorData } from './build_tabular_inspector_data';
import { getRequestInspectorStats, getResponseInspectorStats, serializeAggConfig } from './utils';

Expand Down Expand Up @@ -220,7 +225,11 @@ const handleCourierRequest = async ({
}

inspectorAdapters.data.setTabularLoader(
() => buildTabularInspectorData((searchSource as any).tabifiedResponse, filterManager),
() =>
buildTabularInspectorData((searchSource as any).tabifiedResponse, {
queryFilter: filterManager,
deserializeFieldFormat: getFieldFormats().deserialize,
}),
{ returnsFormattedValues: true }
);

Expand Down

0 comments on commit 78c97c8

Please sign in to comment.