Skip to content

Commit

Permalink
tabify - support docs (#80351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Oct 22, 2020
1 parent bd94486 commit 62f34f2
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function create(id: string) {

return new IndexPattern({
spec: { id, type, version, timeFieldName, fields, title },
savedObjectsClient: {} as any,
fieldFormats: fieldFormatsMock,
shortDotsEnable: false,
metaFields: [],
Expand Down Expand Up @@ -214,7 +213,6 @@ describe('IndexPattern', () => {
const spec = indexPattern.toSpec();
const restoredPattern = new IndexPattern({
spec,
savedObjectsClient: {} as any,
fieldFormats: fieldFormatsMock,
shortDotsEnable: false,
metaFields: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import _, { each, reject } from 'lodash';
import { SavedObjectsClientCommon } from '../..';
import { DuplicateField } from '../../../../kibana_utils/common';

import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common';
Expand All @@ -31,10 +30,9 @@ import { SerializedFieldFormat } from '../../../../expressions/common';

interface IndexPatternDeps {
spec?: IndexPatternSpec;
savedObjectsClient: SavedObjectsClientCommon;
fieldFormats: FieldFormatsStartCommon;
shortDotsEnable: boolean;
metaFields: string[];
shortDotsEnable?: boolean;
metaFields?: string[];
}

interface SavedObjectBody {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ export class IndexPatternsService {

const indexPattern = new IndexPattern({
spec,
savedObjectsClient: this.savedObjectsClient,
fieldFormats: this.fieldFormats,
shortDotsEnable,
metaFields,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/plugins/data/common/search/tabify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@
* under the License.
*/

import { SearchResponse } from 'elasticsearch';
import { SearchSource } from '../search_source';
import { tabifyAggResponse } from './tabify';
import { tabifyDocs, TabifyDocsOptions } from './tabify_docs';
import { TabbedResponseWriterOptions } from './types';

export const tabify = (
searchSource: SearchSource,
esResponse: SearchResponse<unknown>,
opts: Partial<TabbedResponseWriterOptions> | TabifyDocsOptions
) => {
return !esResponse.aggregations
? tabifyDocs(esResponse, searchSource.getField('index'), opts as TabifyDocsOptions)
: tabifyAggResponse(
searchSource.getField('aggs'),
esResponse,
opts as Partial<TabbedResponseWriterOptions>
);
};

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

Expand Down
77 changes: 77 additions & 0 deletions src/plugins/data/common/search/tabify/tabify_docs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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 { tabifyDocs } from './tabify_docs';
import { IndexPattern } from '../../index_patterns/index_patterns';
import { SearchResponse } from 'elasticsearch';

describe('tabifyDocs', () => {
const fieldFormats = {
getInstance: (id: string) => ({ toJSON: () => ({ id }) }),
getDefaultInstance: (id: string) => ({ toJSON: () => ({ id }) }),
};

const index = new IndexPattern({
spec: {
id: 'test-index',
fields: {
sourceTest: { name: 'sourceTest', type: 'number', searchable: true, aggregatable: true },
fieldTest: { name: 'fieldTest', type: 'number', searchable: true, aggregatable: true },
'nested.field': {
name: 'nested.field',
type: 'number',
searchable: true,
aggregatable: true,
},
},
},
fieldFormats: fieldFormats as any,
});

const response = {
hits: {
hits: [
{
_source: { sourceTest: 123 },
fields: { fieldTest: 123, invalidMapping: 345, nested: [{ field: 123 }] },
},
],
},
} as SearchResponse<unknown>;

it('converts fields by default', () => {
const table = tabifyDocs(response, index);
expect(table).toMatchSnapshot();
});

it('converts source if option is set', () => {
const table = tabifyDocs(response, index, { source: true });
expect(table).toMatchSnapshot();
});

it('skips nested fields if option is set', () => {
const table = tabifyDocs(response, index, { shallow: true });
expect(table).toMatchSnapshot();
});

it('works without provided index pattern', () => {
const table = tabifyDocs(response);
expect(table).toMatchSnapshot();
});
});
Loading

0 comments on commit 62f34f2

Please sign in to comment.