Skip to content

Commit

Permalink
feat(modal): removed the modal type enum, updated the modal request f…
Browse files Browse the repository at this point in the history
…unction and the message class
  • Loading branch information
S-Dingley-Genesys committed Jul 2, 2021
1 parent 194df85 commit 48aa888
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
21 changes: 8 additions & 13 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
LabeledEnvInit,
Lifecycle
} from './messages/Lifecycle';
import { ModalRequest } from './messages/ModalRequest';
import { NavRequest } from './messages/NavRequest';
import { Notification } from './messages/Notification';
import { Publication } from './messages/Publication';
Expand All @@ -38,6 +39,7 @@ export {
EnvData,
Publication,
EnvDataHandler,
ModalRequest,
NavRequest,
Notification
};
Expand Down Expand Up @@ -66,13 +68,6 @@ export class Client {
private _registeredKeys: KeyData[];
private _assignedRoute: string | null;

/**
* Supported modal types, will be used in web-dir to know which modal to launch
*/
public modalTypes = {
WEM_COACHING_UI: 'wemCoachingUi'
};

/**
* Creates a new client.
*/
Expand Down Expand Up @@ -428,18 +423,18 @@ bad input into one of the iframe-coordinator client methods.
}

/**
* Asks the host application to launch an instance of a global modal
* Asks the host application to open a modal dialog.
*
* Currently the only available one is WEM Coaching UI
* This is identified by the ModalRequest's `modalId` property.
* Data passed via the `modalData` property can be used by the host application to set up initial state specific to that modal.
*
* @param modalType the type of modal to be used.
* @param modalData any data you wish to be sent to the modal, Conversation IDs etc.
* @param modalRequest the ID and any data specific to the modal instance required
*
*/
public requestModal(modalType: any, modalData: any) {
public requestModal(modalRequest: ModalRequest) {
this._sendToHost({
msgType: 'modalRequest',
msg: { modalType, modalData }
msg: modalRequest
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/messages/ClientToHost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dispatch, guard } from 'decoders';
import { decoder as keyDownDecoder, LabeledKeyDown } from './KeyDown';
import { LabeledStarted, startedDecoder } from './Lifecycle';
import { decoder as modalDecoder, LabeledModal } from './Modal';
import { decoder as modalDecoder, LabeledModalRequest } from './ModalRequest';
import { decoder as navRequestDecoder, LabeledNavRequest } from './NavRequest';
import { decoder as notifyDecoder, LabeledNotification } from './Notification';
import {
Expand All @@ -19,7 +19,7 @@ export type ClientToHost =
| LabeledNavRequest
| LabeledStarted
| LabeledKeyDown
| LabeledModal;
| LabeledModalRequest;

/**
* Validates correctness of messages being sent from
Expand Down
18 changes: 0 additions & 18 deletions src/messages/Modal.ts

This file was deleted.

35 changes: 35 additions & 0 deletions src/messages/ModalRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { constant, Decoder, mixed, object, string } from 'decoders';
import { labeledDecoder, LabeledMsg } from './LabeledMsg';

/**
* The modal request data.
*/
export interface ModalRequest {
/** The ID of the modal the client wishes to launch */
modalId: string;

/** Any data that the client wishes to send to the modal */
modalData: any;
}

/**
* A message used to publish a generic messages
* between the clients and the host application.
*/
export interface LabeledModalRequest
extends LabeledMsg<'modalRequest', ModalRequest> {
/** Message identifier */
msgType: 'modalRequest';
/** Modal request details (type and data) */
msg: ModalRequest;
}

const decoder: Decoder<LabeledModalRequest> = labeledDecoder(
constant<'modalRequest'>('modalRequest'),
object({
modalId: string,
modalData: mixed
})
);

export { decoder };

0 comments on commit 48aa888

Please sign in to comment.