Skip to main content

AlertConfig

AlertConfig

A configuration object for an Admin UI alert.

Signature
interface AlertConfig<T = any> {
id: string;
check: (context: AlertContext) => T | Promise<T> | Observable<T>;
recheck?: (context: AlertContext) => Observable<any>;
isAlert: (data: T, context: AlertContext) => boolean;
action: (data: T, context: AlertContext) => void;
label: (
data: T,
context: AlertContext,
) => { text: string; translationVars?: { [key: string]: string | number } };
requiredPermissions?: Permission[];
}

id

property
string

A unique identifier for the alert.

check

property
(context: AlertContext) => T | Promise<T> | Observable<T>

A function which is gets the data used to determine whether the alert should be shown. Typically, this function will query the server or some other remote data source.

This function will be called once when the Admin UI app bootstraps, and can be also set to run at regular intervals by setting the recheckIntervalMs property.

recheck

property
(context: AlertContext) => Observable<any>
default:
undefined

A function which returns an Observable which is used to determine when to re-run the check function. Whenever the observable emits, the check function will be called again.

A basic time-interval-based recheck can be achieved by using the interval function from RxJS.

Example

import { interval } from 'rxjs';

// ...
recheck: () => interval(60_000)

If this is not set, the check function will only be called once when the Admin UI app bootstraps.

isAlert

property
(data: T, context: AlertContext) => boolean

A function which determines whether the alert should be shown based on the data returned by the check function.

action

property
(data: T, context: AlertContext) => void

A function which is called when the alert is clicked in the Admin UI.

label

property
( data: T, context: AlertContext, ) => { text: string; translationVars?: { [key: string]: string | number } }

A function which returns the text used in the UI to describe the alert.

requiredPermissions

property

A list of permissions which the current Administrator must have in order. If the current Administrator does not have these permissions, none of the other alert functions will be called.