From c54dda88727350370d5f671ce64713508ee83b10 Mon Sep 17 00:00:00 2001 From: Ndricim Date: Mon, 30 Sep 2024 18:37:37 +0200 Subject: [PATCH] Add locale prop to Compound Container (#3935) --- .../test-app/compound/wc-compound-container.cy.js | 12 ++++++++++++ container/src/LuigiCompoundContainer.svelte | 3 +++ .../test-app/compound/compoundClientAPI.html | 1 + container/test-app/compound/helloWorldWC.js | 15 +++++++++++++++ .../typings/LuigiCompoundContainer.svelte.d.ts | 7 +++++++ docs/luigi-compound-container-api.md | 10 ++++++++++ 6 files changed, 48 insertions(+) diff --git a/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js b/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js index a8f824c24d..3fca178d08 100644 --- a/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js +++ b/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js @@ -32,6 +32,18 @@ describe('Compound Container Tests', () => { }); }); + it('LuigiClient API - getCurrentLocale', () => { + cy.on('window:alert', stub); + + cy.get(containerSelector) + .shadow() + .contains('getCurrentLocale') + .click() + .then(() => { + expect(stub.getCall(0)).to.be.calledWith('LuigiClient.getCurrentLocale()=en'); + }); + }); + it('LuigiClient API - getDirtyStatus', () => { cy.on('window:alert', stub); diff --git a/container/src/LuigiCompoundContainer.svelte b/container/src/LuigiCompoundContainer.svelte index d3f2abc28d..80dc657322 100644 --- a/container/src/LuigiCompoundContainer.svelte +++ b/container/src/LuigiCompoundContainer.svelte @@ -20,6 +20,7 @@ dirtyStatus: { type: 'Boolean', reflect: false, attribute: 'dirty-status'}, documentTitle: {type: 'String', reflect: false, attribute: 'document-title'}, hasBack: { type: 'Boolean', reflect: false, attribute: 'has-back'}, + locale: { type: 'String', reflect: false, attribute: 'locale' }, noShadow: { type: 'Boolean', attribute: 'no-shadow', reflect: false }, nodeParams: { type: 'Object', reflect: false, attribute: 'node-params' }, pathParams: { type: 'Object', reflect: false, attribute: 'path-params' }, @@ -75,6 +76,7 @@ export let dirtyStatus: boolean; export let documentTitle: string; export let hasBack: boolean; + export let locale: string; export let noShadow: boolean; export let nodeParams: any; export let pathParams: any; @@ -100,6 +102,7 @@ dirtyStatus && documentTitle && hasBack && + locale && noShadow && nodeParams && pathParams && diff --git a/container/test-app/compound/compoundClientAPI.html b/container/test-app/compound/compoundClientAPI.html index 85eefa9a37..df52da4a2a 100644 --- a/container/test-app/compound/compoundClientAPI.html +++ b/container/test-app/compound/compoundClientAPI.html @@ -37,6 +37,7 @@

defer-init="false" webcomponent="true" theme="sap_fiori_3" + locale="en" > diff --git a/container/test-app/compound/helloWorldWC.js b/container/test-app/compound/helloWorldWC.js index 0598bdd4df..846e741773 100644 --- a/container/test-app/compound/helloWorldWC.js +++ b/container/test-app/compound/helloWorldWC.js @@ -13,6 +13,9 @@ export default class extends HTMLElement { const templateBtn = document.createElement('template'); templateBtn.innerHTML = ''; + const current_locale = document.createElement('template'); + current_locale.innerHTML = ''; + const templateBtn2 = document.createElement('template'); templateBtn2.innerHTML = ''; @@ -112,10 +115,22 @@ export default class extends HTMLElement { this._shadowRoot.appendChild(linkManagerOpenAsRequestsBtn.content.cloneNode(true)); this._shadowRoot.appendChild(linkManagerUpdateTopPathExistsBackBtn.content.cloneNode(true)); this._shadowRoot.appendChild(setViewGroupDataBtn.content.cloneNode(true)); + this._shadowRoot.appendChild(current_locale.content.cloneNode(true)); this._shadowRoot.appendChild(empty.content.cloneNode(true)); + this.$currentLocaleButton = this._shadowRoot.querySelector('#current_locale'); + this.$currentLocaleButton.addEventListener('click', () => { + if (this.LuigiClient) { + this.LuigiClient.uxManager().showAlert({ + text: 'LuigiClient.getCurrentLocale()=' + this.LuigiClient.getCurrentLocale(), + type: 'info' + }); + } + }); + this.$paragraph = this._shadowRoot.querySelector('p'); + this.$button = this._shadowRoot.querySelector('#aButton'); this.$button.addEventListener('click', () => { if (this.LuigiClient) { diff --git a/container/typings/LuigiCompoundContainer.svelte.d.ts b/container/typings/LuigiCompoundContainer.svelte.d.ts index d519a26d71..86bc479218 100644 --- a/container/typings/LuigiCompoundContainer.svelte.d.ts +++ b/container/typings/LuigiCompoundContainer.svelte.d.ts @@ -24,6 +24,13 @@ export default class LuigiCompoundContainer extends HTMLElement { */ deferInit: boolean; + /** + * + * The locale to be passed to the compound micro frontend. + * @since NEXT_RELEASE_CONTAINER + */ + locale: string; + /** * The parameters to be passed to the compound micro frontend. Will not be passed to the compound children. * @since 1.0.0 diff --git a/docs/luigi-compound-container-api.md b/docs/luigi-compound-container-api.md index 86e7c8f921..613404f32d 100644 --- a/docs/luigi-compound-container-api.md +++ b/docs/luigi-compound-container-api.md @@ -49,6 +49,16 @@ Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob * **since**: 1.0.0 +### locale + +The locale to be passed to the compound micro frontend. + +Type: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) + +**Meta** + +* **since**: NEXT_RELEASE_CONTAINER + ### nodeParams The parameters to be passed to the compound micro frontend. Will not be passed to the compound children.