Skip to content

Commit

Permalink
[8.x] [data views] Remove regex for creating dot notation (#193795) (#…
Browse files Browse the repository at this point in the history
…193809)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[data views] Remove regex for creating dot notation
(#193795)](#193795)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Matthew
Kime","email":"matt@mattki.me"},"sourceCommit":{"committedDate":"2024-09-24T00:30:52Z","message":"[data
views] Remove regex for creating dot notation (#193795)\n\n##
Summary\r\n\r\nUse basic string and array functions instead of regex to
create short\r\ndot field
names.","sha":"ab9459ca4358451614c3b4fb09380af9841e7a66","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Data
Views","release_note:skip","v9.0.0","Team:DataDiscovery","backport:all-open"],"title":"[data
views] Remove regex for creating dot
notation","number":193795,"url":"https://github.com/elastic/kibana/pull/193795","mergeCommit":{"message":"[data
views] Remove regex for creating dot notation (#193795)\n\n##
Summary\r\n\r\nUse basic string and array functions instead of regex to
create short\r\ndot field
names.","sha":"ab9459ca4358451614c3b4fb09380af9841e7a66"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193795","number":193795,"mergeCommit":{"message":"[data
views] Remove regex for creating dot notation (#193795)\n\n##
Summary\r\n\r\nUse basic string and array functions instead of regex to
create short\r\ndot field
names.","sha":"ab9459ca4358451614c3b4fb09380af9841e7a66"}}]}]
BACKPORT-->

Co-authored-by: Matthew Kime <matt@mattki.me>
  • Loading branch information
kibanamachine and mattkime authored Sep 24, 2024
1 parent 93ec7be commit 87ac87a
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 87ac87a

Please sign in to comment.