Skip to content

Commit 5d9cdb9

Browse files
authoredApr 21, 2021
feat(framework): support sap-* config URL params (#3138)
The change will assist broader UI technology co-existence by allowing the app developers use the older sap-* params in order to configure the theme, language, etc. There are use-cases where the sap-* is still the preferred param. In case both sap-ui-* and sap-* params are set, the sap-ui-* ones will take precedence - the same way UI5 handles it. FIXES: #3114
1 parent 1c3481b commit 5d9cdb9

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed
 

‎packages/base/hash.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Ypwf1pcj/tFLkCFKDb5OPtwjd5A=
1+
KJ0tn0Kg8EEEQiQ6XKfqbAsP3eQ=

‎packages/base/src/InitialConfiguration.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,36 @@ const parseConfigurationScript = () => {
9292
const parseURLParameters = () => {
9393
const params = new URLSearchParams(window.location.search);
9494

95+
// Process "sap-*" params first
9596
params.forEach((value, key) => {
96-
if (!key.startsWith("sap-ui")) {
97+
const parts = key.split("sap-").length;
98+
if (parts === 0 || parts === key.split("sap-ui-").length) {
9799
return;
98100
}
99101

100-
const lowerCaseValue = value.toLowerCase();
101-
102-
const param = key.split("sap-ui-")[1];
102+
applyURLParam(key, value, "sap");
103+
});
103104

104-
if (booleanMapping.has(value)) {
105-
value = booleanMapping.get(lowerCaseValue);
105+
// Process "sap-ui-*" params
106+
params.forEach((value, key) => {
107+
if (!key.startsWith("sap-ui")) {
108+
return;
106109
}
107110

108-
initialConfig[param] = value;
111+
applyURLParam(key, value, "sap-ui");
109112
});
110113
};
111114

115+
const applyURLParam = (key, value, paramType) => {
116+
const lowerCaseValue = value.toLowerCase();
117+
const param = key.split(`${paramType}-`)[1];
118+
119+
if (booleanMapping.has(value)) {
120+
value = booleanMapping.get(lowerCaseValue);
121+
}
122+
initialConfig[param] = value;
123+
};
124+
112125
const applyOpenUI5Configuration = () => {
113126
const OpenUI5Support = getFeature("OpenUI5Support");
114127
if (!OpenUI5Support || !OpenUI5Support.isLoaded()) {

‎packages/base/test/specs/ConfigurationURL.spec.js

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require("chai").assert;
22

3-
describe("Some settings can be set via URL params", () => {
3+
describe("Some settings can be set via SAP UI URL params", () => {
44
before(() => {
55
browser.url("http://localhost:9191/test-resources/pages/Configuration.html?sap-ui-rtl=true&sap-ui-language=ja&sap-ui-calendarType=Japanese&sap-ui-theme=sap_belize_hcb&sap-ui-animationMode=basic");
66
});
@@ -45,3 +45,49 @@ describe("Some settings can be set via URL params", () => {
4545
assert.strictEqual(res, 'basic', "animationMode is basic");
4646
});
4747
});
48+
49+
50+
describe("Some settings can be set via SAP URL params", () => {
51+
before(() => {
52+
browser.url("http://localhost:9191/test-resources/pages/Configuration.html?sap-language=bg&sap-theme=sap_fiori_3_dark");
53+
});
54+
55+
it("Tests that language is applied", () => {
56+
const res = browser.execute( () => {
57+
const config = window['sap-ui-webcomponents-bundle'].configuration;
58+
return config.getLanguage();
59+
});
60+
assert.strictEqual(res, 'bg', "language is bulgarian");
61+
});
62+
63+
it("Tests that theme is applied", () => {
64+
const res = browser.execute( () => {
65+
const config = window['sap-ui-webcomponents-bundle'].configuration;
66+
return config.getTheme();
67+
});
68+
assert.strictEqual(res, 'sap_fiori_3_dark', "Thems is Fiori Dark");
69+
});
70+
});
71+
72+
73+
describe("SAP UI params take precedence over the SAP params", () => {
74+
before(() => {
75+
browser.url("http://localhost:9191/test-resources/pages/Configuration.html?sap-language=bg&sap-ui-language=de&sap-theme=sap_fiori_3_dark&sap-theme=sap_fiori_3_hcb");
76+
});
77+
78+
it("Tests that language is applied via sap-ui-language", () => {
79+
const res = browser.execute( () => {
80+
const config = window['sap-ui-webcomponents-bundle'].configuration;
81+
return config.getLanguage();
82+
});
83+
assert.strictEqual(res, 'de', "language is german");
84+
});
85+
86+
it("Tests that theme is applied via sap-ui-theme", () => {
87+
const res = browser.execute( () => {
88+
const config = window['sap-ui-webcomponents-bundle'].configuration;
89+
return config.getTheme();
90+
});
91+
assert.strictEqual(res, 'sap_fiori_3_hcb', "Thems is Fiori HCB");
92+
});
93+
});

0 commit comments

Comments
 (0)
Please sign in to comment.