-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetVisualBuilderRedirectionUrl.ts
More file actions
44 lines (37 loc) · 1.32 KB
/
getVisualBuilderRedirectionUrl.ts
File metadata and controls
44 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Config from "../../configManager/configManager";
import { extractDetailsFromCslp } from "../../cslp";
/**
* Returns the redirection URL for the Visual builder.
* @returns {URL} The redirection URL.
*/
export default function getVisualBuilderRedirectionUrl(): URL {
const { stackDetails, clientUrlParams } = Config.get();
const { branch, apiKey, environment, locale } = stackDetails;
const { url: appUrl } = clientUrlParams;
const searchParams = new URLSearchParams();
if (branch) {
searchParams.set("branch", branch);
}
if (environment) {
searchParams.set("environment", environment);
}
searchParams.set("target-url", window.location.href);
// get the locale from the data cslp attribute
const elementWithDataCslp = document.querySelector(`[data-cslp]`);
let localeToUse = locale;
if (elementWithDataCslp) {
const cslpData = elementWithDataCslp.getAttribute("data-cslp");
if (cslpData) {
const { locale: cslpLocale } = extractDetailsFromCslp(cslpData);
localeToUse = cslpLocale;
}
}
if (localeToUse) {
searchParams.set("locale", localeToUse);
}
const completeURL = new URL(
`/#!/stack/${apiKey}/visual-editor?${searchParams.toString()}`,
appUrl
);
return completeURL;
}