From 396a2b63d461102cb312168adf9303265919c16c Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Thu, 4 May 2023 11:11:18 +0200 Subject: [PATCH] [Discover] Switch from "at" to "charAt" for better browser support (#156474) From the community forum: users can't access Discover on older browsers. ``` TypeError: t.at is not a function at http://xxx:5601/61109/bundles/plugin/data/kibana/data.plugin.js:1:312992 at Array.forEach () at n (http://xxx:5601/61109/bundles/plugin/data/kibana/data.plugin.js:1:312956) at s (http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:10138) at http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:10215 at Array.map () at a (http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:10207) at http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:8442 at http://xxx:5601/61109/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:334:27724 at t.s._next (http://xxx:5601/61109/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:6:33456) ``` - https://discuss.elastic.co/t/update-to-8-7-0/329525 - https://discuss.elastic.co/t/elastic-8-7-0-error-in-discover-tab/332329/2 ## Summary This PR replaces `String` `.at` usage with `.charAt` so it does not require a polyfill for older browsers. --- src/plugins/data/common/search/tabify/tabify_docs.test.ts | 3 ++- src/plugins/data/common/search/tabify/tabify_docs.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/common/search/tabify/tabify_docs.test.ts b/src/plugins/data/common/search/tabify/tabify_docs.test.ts index fd61995705c86..0026fd1734b50 100644 --- a/src/plugins/data/common/search/tabify/tabify_docs.test.ts +++ b/src/plugins/data/common/search/tabify/tabify_docs.test.ts @@ -200,6 +200,7 @@ describe('tabify_docs', () => { _size: 12, _score: 77, _source: {}, + invalid_meta: 'test', }, ], }, @@ -216,7 +217,7 @@ describe('tabify_docs', () => { }, }, }, - metaFields: ['_id', '_index', '_score', '_type', '_size'], + metaFields: ['_id', '_index', '_score', '_type', '_size', 'invalid_meta'], fieldFormats: fieldFormats as any, }); const table = tabifyDocs(responsePlugin, dataView); diff --git a/src/plugins/data/common/search/tabify/tabify_docs.ts b/src/plugins/data/common/search/tabify/tabify_docs.ts index 471d472577a96..f57346917d286 100644 --- a/src/plugins/data/common/search/tabify/tabify_docs.ts +++ b/src/plugins/data/common/search/tabify/tabify_docs.ts @@ -107,7 +107,8 @@ export function flattenHit(hit: Hit, indexPattern?: DataView, params?: TabifyDoc // Merge all valid meta fields into the flattened object indexPattern?.metaFields?.forEach((fieldName) => { - const isExcludedMetaField = EXCLUDED_META_FIELDS.includes(fieldName) || fieldName.at(0) !== '_'; + const isExcludedMetaField = + EXCLUDED_META_FIELDS.includes(fieldName) || fieldName.charAt(0) !== '_'; if (isExcludedMetaField) { return; }