[8.8] [Guided onboarding] Fix Kibana crashing on Safari (#158825) (#158952)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Guided onboarding] Fix Kibana crashing on Safari
(#158825)](https://github.com/elastic/kibana/pull/158825)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Yulia
Čech","email":"6585477+yuliacech@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-06-02T16:50:27Z","message":"[Guided
onboarding] Fix Kibana crashing on Safari
(#158825)","sha":"e2e03cac3b52fc590a93c3abb346d71af0b5eb6d","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","backport:prev-minor","Team:Journey/Onboarding","v8.9.0","v8.8.1"],"number":158825,"url":"https://github.com/elastic/kibana/pull/158825","mergeCommit":{"message":"[Guided
onboarding] Fix Kibana crashing on Safari
(#158825)","sha":"e2e03cac3b52fc590a93c3abb346d71af0b5eb6d"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/158825","number":158825,"mergeCommit":{"message":"[Guided
onboarding] Fix Kibana crashing on Safari
(#158825)","sha":"e2e03cac3b52fc590a93c3abb346d71af0b5eb6d"}},{"branch":"8.8","label":"v8.8.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Yulia Čech <6585477+yuliacech@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-06-02 13:56:33 -04:00 committed by GitHub
parent cb3763e935
commit 17559fa778
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,15 +9,21 @@
import { PluginState } from '../../common';
// regex matches everything between an opening and a closing curly braces
// without matching the braces themselves
const paramsBetweenCurlyBraces = /(?<=\{)[^\{\}]+(?=\})/g;
// and the braces themselves
const paramsWithBraces = /\{(.*?)\}/g;
// regex matches both curly braces
const curlyBraces = /[\{\}]/g;
export const getStepLocationPath = (path: string, pluginState: PluginState): string | undefined => {
if (pluginState.activeGuide?.params) {
let dynamicPath = path;
const matchedParams = path.match(paramsBetweenCurlyBraces);
const matchedParams = path.match(paramsWithBraces);
if (matchedParams) {
for (const param of matchedParams) {
dynamicPath = dynamicPath.replace(`{${param}}`, pluginState.activeGuide?.params[param]);
const paramWithoutBraces = param.replace(curlyBraces, '');
dynamicPath = dynamicPath.replace(
`${param}`,
pluginState.activeGuide?.params[paramWithoutBraces]
);
}
return dynamicPath;
}