Skip to content

Commit

Permalink
Merge branch 'main' into showAlert-promise
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer committed Jan 17, 2025
2 parents 39d9971 + cfce7a8 commit 0cbb701
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
10 changes: 5 additions & 5 deletions container/src/LuigiContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@
}
};
thisComponent.closeAlert = (id: string, dismissKey: string) => {
//check if thisComponent is in dom
if(thisComponent.isConnected){
if(webcomponent){
thisComponent.closeAlert = (id: string, dismissKey?: string) => {
// check if thisComponent is in dom
if (thisComponent.isConnected) {
if (webcomponent) {
webcomponentService.resolveAlert(id, dismissKey);
}else{
} else {
ContainerAPI.closeAlert(id, dismissKey, iframeHandle);
}
}
Expand Down
9 changes: 5 additions & 4 deletions container/src/api/container-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ export class ContainerAPIFunctions {
/**
* Send a message to the microfrontend notifying the alert has been closed
* @param id the id of the alert being closed
* @param dismissKey the dismiss key being sent if any
* @param iframeHandle the handle of the iframe to send the message to
* @param dismissKey the dismiss key being sent if any (optional)
* @param iframeHandle the handle of the iframe to send the message to (optional)
*/
closeAlert(id: string, dismissKey: string, iframeHandle: IframeHandle) {
containerService.sendCustomMessageToIframe(iframeHandle, { id, dismissKey }, LuigiInternalMessageID.ALERT_CLOSED);
closeAlert(id: string, dismissKey?: string, iframeHandle?: IframeHandle) {
const message = dismissKey ? { id, dismissKey } : { id };
containerService.sendCustomMessageToIframe(iframeHandle, message, LuigiInternalMessageID.ALERT_CLOSED);
}
}

Expand Down
2 changes: 1 addition & 1 deletion container/src/services/container.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ContainerService {
sendCustomMessageToIframe(iframeHandle: IframeHandle, msg: object, msgName?: string) {
const messageName = msgName || 'custom';

if (iframeHandle.iframe.contentWindow) {
if (iframeHandle?.iframe?.contentWindow) {
const iframeUrl = new URL(iframeHandle.iframe.src);
if (messageName === 'custom') {
iframeHandle.iframe.contentWindow.postMessage({ msg: messageName, data: msg }, iframeUrl.origin);
Expand Down
14 changes: 14 additions & 0 deletions container/test/api/container-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ describe('Container Service', () => {

expect(spy).toHaveBeenCalledWith(iframeHandle, { id, dismissKey }, LuigiInternalMessageID.ALERT_CLOSED);
});

it('internal method properly called if no dismisskey', () => {
// mock and spy
const id = 'some-id';
const iframeHandle = {
data: 'test'
} as unknown as IframeHandle;
containerService.sendCustomMessageToIframe = jest.fn();
const spy = jest.spyOn(containerService, 'sendCustomMessageToIframe');

containerAPI.closeAlert(id, undefined, iframeHandle);

expect(spy).toHaveBeenCalledWith(iframeHandle, { id }, LuigiInternalMessageID.ALERT_CLOSED);
});
});

describe('sendCustomMessage', () => {
Expand Down
4 changes: 2 additions & 2 deletions container/typings/LuigiContainer.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ export default class LuigiContainer extends HTMLElement {
/**
* A function that notifies the microfrontend that the opened alert has been closed.
* @param id the id of the opened alert
* @param dismissKey the key specifying which dismiss link was clicked on the alert message
* @param dismissKey the key specifying which dismiss link was clicked on the alert message (optional)
* @example
* containerElement.closeAlert('my-alert-id', 'my-dismiss-key')
* @since 1.0.0
*/
closeAlert(id: string, dismissKey: string): void;
closeAlert(id: string, dismissKey?: string): void;

/**
* Manually triggers the micro frontend rendering process when using defer-init attribute.
Expand Down
2 changes: 1 addition & 1 deletion docs/luigi-container-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ A function that notifies the microfrontend that the opened alert has been closed
#### Parameters

* `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the id of the opened alert
* `dismissKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the key specifying which dismiss link was clicked on the alert message
* `dismissKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the key specifying which dismiss link was clicked on the alert message (optional)

#### Examples

Expand Down
4 changes: 2 additions & 2 deletions docs/luigi-element-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Base class for Luigi web component micro frontends.

#### afterInit

Override to execute logic after initialization of the web component, i.e.
Override to execute logic after initialization of the web component, i.e.
after internal rendering and all context data set.

##### Parameters
Expand Down Expand Up @@ -101,7 +101,7 @@ Query selector operating on shadow root.

### html

Html string processing according to luigi functionality.
Html string processing according to luigi functionality.
Also useful in combination with LitElement VS Code plugins.

#### Parameters
Expand Down

0 comments on commit 0cbb701

Please sign in to comment.