Skip to content

Commit

Permalink
[data views] Remove regex for creating dot notation (elastic#193795)
Browse files Browse the repository at this point in the history
## Summary

Use basic string and array functions instead of regex to create short
dot field names.
  • Loading branch information
mattkime authored Sep 24, 2024
1 parent b3d28c8 commit ab9459c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/plugins/data_views/common/fields/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab9459c

Please sign in to comment.