From ab9459ca4358451614c3b4fb09380af9841e7a66 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Mon, 23 Sep 2024 19:30:52 -0500 Subject: [PATCH] [data views] Remove regex for creating dot notation (#193795) ## Summary Use basic string and array functions instead of regex to create short dot field names. --- 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