[ML] Data frames: Fix source table for cells of type object. (#41234) (#41319)

- Fixes a possible crash of the data frames source index table.
- While the source document field structure was already flattened to avoid displaying nested objects in table cells, this failed to catch if a field itself was of type object, for example geo fields.
- Similar to how complex arrays were already handled, this adds a check to display a object badge with a tooltip if the cell value is of type object and not suitable to display the raw value.
- This fixes an issue reported when the full raw object structure of tweets was used as a source index to create a data frame.
This commit is contained in:
Walter Rafelsberger 2019-07-17 09:37:48 +02:00 committed by GitHub
parent 081b3940ad
commit 18479b0a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 117 additions and 1 deletions

View file

@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Data Frame: <SourceIndexPreview /> Minimal initialization 1`] = `
<div>
<ContextProvider
value={
Object {
"combinedQuery": Object {},
"currentIndexPattern": Object {
"fields": Array [],
"id": "the-index-pattern-id",
"title": "the-index-pattern-title",
},
"currentSavedSearch": Object {},
"indexPatterns": Object {},
"kbnBaseUrl": "url",
"kibanaConfig": Object {},
}
}
>
<Component
query={
Object {
"query_string": Object {
"default_operator": "AND",
"query": "the-query",
},
}
}
/>
</ContextProvider>
</div>
`;

View file

@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { shallow } from 'enzyme';
import React from 'react';
import { getPivotQuery, KibanaContext } from '../../common';
import { SourceIndexPreview } from './source_index_preview';
// workaround to make React.memo() work with enzyme
jest.mock('react', () => {
const r = jest.requireActual('react');
return { ...r, memo: (x: any) => x };
});
describe('Data Frame: <SourceIndexPreview />', () => {
test('Minimal initialization', () => {
const currentIndexPattern = {
id: 'the-index-pattern-id',
title: 'the-index-pattern-title',
fields: [],
};
const props = {
query: getPivotQuery('the-query'),
};
// Using a wrapping <div> element because shallow() would fail
// with the Provider being the outer most component.
const wrapper = shallow(
<div>
<KibanaContext.Provider
value={{
combinedQuery: {},
currentIndexPattern,
currentSavedSearch: {},
indexPatterns: {},
kbnBaseUrl: 'url',
kibanaConfig: {},
}}
>
<SourceIndexPreview {...props} />
</KibanaContext.Provider>
</div>
);
expect(wrapper).toMatchSnapshot();
});
});

View file

@ -245,7 +245,37 @@ export const SourceIndexPreview: React.SFC<Props> = React.memo(({ cellClick, que
}
)}
>
<EuiBadge>array</EuiBadge>
<EuiBadge>
{i18n.translate(
'xpack.ml.dataframe.sourceIndexPreview.dataFrameSourceIndexArrayBadgeContent',
{
defaultMessage: 'array',
}
)}
</EuiBadge>
</EuiToolTip>
);
} else if (typeof d === 'object' && d !== null) {
// If the cells data is an object, display a 'object' badge with a
// tooltip that explains that this type of field is not supported in this table.
return (
<EuiToolTip
content={i18n.translate(
'xpack.ml.dataframe.sourceIndexPreview.dataFrameSourceIndexObjectToolTipContent',
{
defaultMessage:
'The full content of this object based column is available in the expanded row.',
}
)}
>
<EuiBadge>
{i18n.translate(
'xpack.ml.dataframe.sourceIndexPreview.dataFrameSourceIndexObjectBadgeContent',
{
defaultMessage: 'object',
}
)}
</EuiBadge>
</EuiToolTip>
);
}