From 87ac87ad71d367123fe09e36024bc7af78158b8a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:19:51 +1000 Subject: [PATCH] [8.x] [data views] Remove regex for creating dot notation (#193795) (#193809) # Backport This will backport the following commits from `main` to `8.x`: - [[data views] Remove regex for creating dot notation (#193795)](https://github.com/elastic/kibana/pull/193795) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Matthew Kime --- src/plugins/data_views/common/fields/utils.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plugins/data_views/common/fields/utils.ts b/src/plugins/data_views/common/fields/utils.ts index 380493ed07668..23f0bf3a8651d 100644 --- a/src/plugins/data_views/common/fields/utils.ts +++ b/src/plugins/data_views/common/fields/utils.ts @@ -26,14 +26,22 @@ export const isMultiField = isDataViewFieldSubtypeMulti; export const getFieldSubtypeMulti = getDataViewFieldSubtypeMulti; export const getFieldSubtypeNested = getDataViewFieldSubtypeNested; -const DOT_PREFIX_RE = /(.).+?\./g; - /** * Convert a dot.notated.string into a short * version (d.n.string) */ export function shortenDottedString(input: string): string { - return typeof input !== 'string' ? input : input.replace(DOT_PREFIX_RE, '$1.'); + if (typeof input === 'string') { + const split = input.split('.'); + return split.reduce((acc, part, i) => { + if (i === split.length - 1) { + return acc + part; + } + return acc + part[0] + '.'; + }, ''); + } + + return input; } // Note - this code is duplicated from @kbn/es-query