[APM] Guard saved objects against JSON.parse of undefined (#32479) (#32499)

# Conflicts:
#	x-pack/plugins/apm/public/services/kuery.ts
This commit is contained in:
Søren Louv-Jansen 2019-03-05 19:32:57 +01:00 committed by GitHub
parent d70a731ffc
commit 3cdc32f93f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 13 deletions

View file

@ -18,6 +18,7 @@
*/
import { KBN_FIELD_TYPES } from '../../../../utils/kbn_field_types';
import { get } from 'lodash';
const filterableTypes = KBN_FIELD_TYPES.filter(type => type.filterable).map(type => type.name);
@ -26,7 +27,7 @@ export function isFilterable(field) {
}
export function getFromSavedObject(savedObject) {
if (!savedObject) {
if (get(savedObject, 'attributes.fields') === undefined) {
return null;
}

View file

@ -6,7 +6,6 @@
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { getAutocompleteProvider } from 'ui/autocomplete_providers';
// @ts-ignore
import { getFromSavedObject } from 'ui/index_patterns/static_utils';
import { getAPMIndexPattern } from './rest/savedObjects';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { first, isEmpty, memoize } from 'lodash';
import { memoize } from 'lodash';
import chrome from 'ui/chrome';
import { callApi } from './callApi';
@ -34,15 +34,7 @@ export const getAPMIndexPattern = memoize(async () => {
}
});
if (isEmpty(res.saved_objects)) {
return;
}
const apmSavedObject = first(
res.saved_objects.filter(
savedObject => savedObject.attributes.title === apmIndexPatternTitle
)
return res.saved_objects.find(
savedObject => savedObject.attributes.title === apmIndexPatternTitle
);
return apmSavedObject;
});