Adding new alert types
You can extend the default alerts implementation in Sterling Store Engagement to add new alert types and custom alert components.
Procedure
-
Create the following folder structure under SCREEN_EXTENSIONS_HOME, if not
already present:
SCREEN_EXTENSIONS_HOME/features/alert
- Navigate to the SCREEN_EXTENSIONS_HOME/features/alert folder.
- Copy
alert-extension.module.ts
from<WORKSPACE>/store-frontend/src/app/features/alert
to<WORKSPACE>/store-frontend/store-extensions-src/app/features/alert
folder.Ifalert-extension.module.ts
is already present, do not copy the file. Custom alert components and providers are declared in this file. - To create a new alert component, perform the following steps:
- Run the following command:
ng g c <componentName> --project=store-extensions --skip-import
- Update the alert component class name in declarations and
entryComponents
property of@NgModule
decorator inalert-extension.module.ts
. - After the custom component is created, you can access the alert configuration object
and alert (Inbox) details object that is returned by the
getExceptionList
API, by injecting them in the constructor of the component as shown in the following code snippet:constructor( @Inject('config') public config, @Inject('data') public data, @Inject('parentComponentId') public parentComponentId ) { }
The following table provides descriptions of each input binding:Binding Description config
The alertType
configuration object that is associated with its matchingalertType
. This is defined inextensionAlertConfig
property.data
The alert (Inbox) record details. parentComponentId
Unique ID of the alert container component AlertContainerComponent
. - You can define actions such as pick order, pack order, confirm, or delete in the custom alert component based on your business needs.
- After completing these actions, to close the alert panel, emit an event with action as
AlertCloseAction.CLOSE
as shown in the following code snippet. This ensures that the alert panel is closed.@Output() eventEmitter: EventEmitter<any> = new EventEmitter<any>(); this.eventEmitter.emit(AlertCloseAction.CLOSE);
- Run the following command:
- To create a service or provider for the new alert component, perform the following
steps:
- Run the following command:
ng g s <serviceName> --project=store-extensions
- Update the service or provider name in providers of
@NgModule
decorator inalert-extension.module.ts
.
Note:- It is mandatory to pass the argument
--project=store-extensions
. Failing to do so will create the component in the application-provided src folder (<WORKSPACE>/store-frontend/src). The files created here are ignored and not rendered on browser. - Ensure that you import the newly created custom alert component, service, or provider classes
into
alert-extension.module.ts
from store-extensions-src and not from the store-app-build folder. - Ensure that you import the out-of-the-box services, component, and type files by using
@sim-app
,@sim-core
, or@sim-shared
notations.
- Run the following command:
- Register the alert to a view in one of the following ways. For more information, see
View-Alert registration.
- Register the alert to an existing view. For example, if you want to add a custom alert,
YCD_BACKORDER_NOTICE
, to an existing view,Order_Fulfillment
, the JSON specification will look like:{ personaName: 'Order_Fulfillment', alertTypes: [ { tid: 'YCD_BACKORDER_NOTICE', exceptionType: 'YCD_BACKORDER_NOTICE', component: ExtnBackOrderNoticeAlertComponent, descBundleKey: 'alerts.LABEL_BackorderNotice' } ] }
- In the
store-customization-impl.ts
file, update theextensionAlertConfig
property in thealert-persona
JSON specification as follows:static extensionAlertConfig: IAlertsConfig = { alertConfigList: [ { personaName: 'Order_Fulfillment', alertTypes: [ { tid: 'YCD_BACKORDER_NOTICE', exceptionType: 'YCD_BACKORDER_NOTICE', component: ExtnBackOrderNoticeAlertComponent, descBundleKey: 'alerts.LABEL_BackorderNotice' } ] } ] }
- Register the alert to an existing view.