@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
115 lines (113 loc) • 5.07 kB
JavaScript
import { NotificationState } from './notification-state';
/**
* Utility class to manage client notification
*/
export class ClientNotificationInstance {
notificationConnection;
nodeName;
notification;
/**
* Creates a new ClientNotificationInstance
* @param notificationConnection reference to NotificationConnection, can be found at AppContextService.notification
* @param nodeName the node name for the notification
*/
constructor(notificationConnection, nodeName) {
this.notificationConnection = notificationConnection;
this.nodeName = nodeName;
this.notification = {
id: MsftSme.newGuid(),
state: NotificationState.InProgress,
title: '',
message: ''
};
}
/**
* Gets the notification ID to recycle.
* Sets this ID to the Work Item ID to share the notification.
*/
get id() {
return this.notification.id;
}
/**
* Shows an in progress notification
* This should be used for all started, submitted, in progress, or status update notifications
* @param title localized title for the notification. Should be like "Executing some action"
* @param message localized message for the notification. Should be natural language like "Executing some action on target 'name'"
* @param link optional custom link for notification
*/
showInProgress(title, message, link) {
this.showNotification(title, message, link, NotificationState.InProgress);
}
/**
* Shows a critical notification
* @param title localized title for the notification.
* @param message localized message for the notification
* @param link optional custom link for notification
* @param solutionMessage optional solution message to address error
*/
showCritical(title, message, link, solutionMessage) {
this.showNotification(title, message, link, NotificationState.Critical, solutionMessage);
}
/**
* Shows an error notification
* @param title localized title for the notification. Should be like "Failed to execute some action"
* @param message localized message for the notification.
* Should be natural language like "Failed to execute some action on target 'name'. Error: <error message>"
* @param link optional custom link for notification
* @param solutionMessage optional solution message to address error
*/
showError(title, message, link, solutionMessage) {
this.showNotification(title, message, link, NotificationState.Error, solutionMessage);
}
/**
* Shows a warning notification
* @param title localized title for the notification.
* @param message localized message for the notification
* @param link optional custom link for notification
*/
showWarning(title, message, link) {
this.showNotification(title, message, link, NotificationState.Warning);
}
/**
* Shows a success notification
* @param title localized title for the notification. Should be like "Successfully executed some action"
* @param message localized message for the notification.
* Should be natural language like "Successfully executed some action on target 'name'"
* @param link optional custom link for notification
*/
showSuccess(title, message, link) {
this.showNotification(title, message, link, NotificationState.Success);
}
/**
* Shows an informational notification
* If the information is relative to an action currently in progress or already started, use showInProgressNotification
* @param title localized title for the notification.
* @param message localized message for the notification
* @param link optional custom link for notification
*/
showInformation(title, message, link) {
this.showNotification(title, message, link, NotificationState.Informational);
}
/**
* show notification of given state
* @param title the localized title
* @param message the localized message
* @param link the link
* @param state the state
* @param solutionMessage optional solution message for error or critical notification
*/
showNotification(title, message, link, state, solutionMessage) {
if (MsftSme.isNullOrWhiteSpace(title) || MsftSme.isNullOrWhiteSpace(message)) {
throw new Error('Notification title and message must be defined and nonempty');
}
this.notification.state = state;
this.notification.title = title;
this.notification.message = message;
this.notification.solutionMessage = solutionMessage ? solutionMessage : null;
this.notification.link = link ? link.link : null;
this.notification.linkText = link ? link.linkText : null;
this.notification.linkType = link ? link.linkType : null;
this.notificationConnection.notify(this.nodeName, this.notification);
}
}
//# sourceMappingURL=client-notification-instance.js.map