Skip to content

Commit cfce7a8

Browse files
dismissKey optional in closeAlert (#4106)
1 parent faf1009 commit cfce7a8

File tree

7 files changed

+26
-11
lines changed

7 files changed

+26
-11
lines changed

container/src/LuigiContainer.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
}
146146
};
147147
148-
thisComponent.closeAlert = (id: string, dismissKey: string) => {
148+
thisComponent.closeAlert = (id: string, dismissKey?: string) => {
149149
ContainerAPI.closeAlert(id, dismissKey, iframeHandle);
150150
};
151151

container/src/api/container-api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ export class ContainerAPIFunctions {
9595
/**
9696
* Send a message to the microfrontend notifying the alert has been closed
9797
* @param id the id of the alert being closed
98-
* @param dismissKey the dismiss key being sent if any
99-
* @param iframeHandle the handle of the iframe to send the message to
98+
* @param dismissKey the dismiss key being sent if any (optional)
99+
* @param iframeHandle the handle of the iframe to send the message to (optional)
100100
*/
101-
closeAlert(id: string, dismissKey: string, iframeHandle: IframeHandle) {
102-
containerService.sendCustomMessageToIframe(iframeHandle, { id, dismissKey }, LuigiInternalMessageID.ALERT_CLOSED);
101+
closeAlert(id: string, dismissKey?: string, iframeHandle?: IframeHandle) {
102+
const message = dismissKey ? { id, dismissKey } : { id };
103+
containerService.sendCustomMessageToIframe(iframeHandle, message, LuigiInternalMessageID.ALERT_CLOSED);
103104
}
104105
}
105106

container/src/services/container.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ContainerService {
2424
sendCustomMessageToIframe(iframeHandle: IframeHandle, msg: object, msgName?: string) {
2525
const messageName = msgName || 'custom';
2626

27-
if (iframeHandle.iframe.contentWindow) {
27+
if (iframeHandle?.iframe?.contentWindow) {
2828
const iframeUrl = new URL(iframeHandle.iframe.src);
2929
if (messageName === 'custom') {
3030
iframeHandle.iframe.contentWindow.postMessage({ msg: messageName, data: msg }, iframeUrl.origin);

container/test/api/container-api.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ describe('Container Service', () => {
218218

219219
expect(spy).toHaveBeenCalledWith(iframeHandle, { id, dismissKey }, LuigiInternalMessageID.ALERT_CLOSED);
220220
});
221+
222+
it('internal method properly called if no dismisskey', () => {
223+
// mock and spy
224+
const id = 'some-id';
225+
const iframeHandle = {
226+
data: 'test'
227+
} as unknown as IframeHandle;
228+
containerService.sendCustomMessageToIframe = jest.fn();
229+
const spy = jest.spyOn(containerService, 'sendCustomMessageToIframe');
230+
231+
containerAPI.closeAlert(id, undefined, iframeHandle);
232+
233+
expect(spy).toHaveBeenCalledWith(iframeHandle, { id }, LuigiInternalMessageID.ALERT_CLOSED);
234+
});
221235
});
222236

223237
describe('sendCustomMessage', () => {

container/typings/LuigiContainer.svelte.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ export default class LuigiContainer extends HTMLElement {
246246
/**
247247
* A function that notifies the microfrontend that the opened alert has been closed.
248248
* @param id the id of the opened alert
249-
* @param dismissKey the key specifying which dismiss link was clicked on the alert message
249+
* @param dismissKey the key specifying which dismiss link was clicked on the alert message (optional)
250250
* @example
251251
* containerElement.closeAlert('my-alert-id', 'my-dismiss-key')
252252
* @since 1.0.0
253253
*/
254-
closeAlert(id: string, dismissKey: string): void;
254+
closeAlert(id: string, dismissKey?: string): void;
255255

256256
/**
257257
* Manually triggers the micro frontend rendering process when using defer-init attribute.

docs/luigi-container-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ A function that notifies the microfrontend that the opened alert has been closed
536536
#### Parameters
537537

538538
* `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the id of the opened alert
539-
* `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
539+
* `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)
540540

541541
#### Examples
542542

docs/luigi-element-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Base class for Luigi web component micro frontends.
6262

6363
#### afterInit
6464

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

6868
##### Parameters
@@ -101,7 +101,7 @@ Query selector operating on shadow root.
101101

102102
### html
103103

104-
Html string processing according to luigi functionality.
104+
Html string processing according to luigi functionality.
105105
Also useful in combination with LitElement VS Code plugins.
106106

107107
#### Parameters

0 commit comments

Comments
 (0)