fix(dashboard): handle * (any events) for notifications
This commit is contained in:
@@ -34,7 +34,7 @@ function EventBadge({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Badge variant="outline" className="inline-flex">
|
<Badge variant="outline" className="inline-flex">
|
||||||
{event.name}
|
{event.name === '*' ? 'Any event' : event.name}
|
||||||
{Boolean(event.filters.length) && (
|
{Boolean(event.filters.length) && (
|
||||||
<FilterIcon className="size-2 ml-1" />
|
<FilterIcon className="size-2 ml-1" />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export function triggerNotification(notification: Notification) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function matchEventFilters(
|
function matchEventFilters(
|
||||||
event: IServiceCreateEventPayload,
|
payload: IServiceCreateEventPayload,
|
||||||
filters: IChartEventFilter[],
|
filters: IChartEventFilter[],
|
||||||
) {
|
) {
|
||||||
return filters.every((filter) => {
|
return filters.every((filter) => {
|
||||||
@@ -144,15 +144,15 @@ function matchEventFilters(
|
|||||||
|
|
||||||
if (name === 'has_profile') {
|
if (name === 'has_profile') {
|
||||||
if (value.includes('true')) {
|
if (value.includes('true')) {
|
||||||
return event.profileId !== event.deviceId;
|
return payload.profileId !== payload.deviceId;
|
||||||
}
|
}
|
||||||
return event.profileId === event.deviceId;
|
return payload.profileId === payload.deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const propertyValue = (
|
const propertyValue = (
|
||||||
name.startsWith('properties.')
|
name.startsWith('properties.')
|
||||||
? pathOr('', name.split('.'), event)
|
? pathOr('', name.split('.'), payload)
|
||||||
: pathOr('', [name], event)
|
: pathOr('', [name], payload)
|
||||||
).trim();
|
).trim();
|
||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
@@ -180,15 +180,15 @@ function matchEventFilters(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function matchEvent(
|
export function matchEvent(
|
||||||
event: IServiceCreateEventPayload,
|
payload: IServiceCreateEventPayload,
|
||||||
chartEvent: IChartEvent,
|
chartEvent: IChartEvent,
|
||||||
) {
|
) {
|
||||||
if (event.name !== chartEvent.name) {
|
if (payload.name !== chartEvent.name && chartEvent.name !== '*') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chartEvent.filters.length > 0) {
|
if (chartEvent.filters.length > 0) {
|
||||||
return matchEventFilters(event, chartEvent.filters);
|
return matchEventFilters(payload, chartEvent.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ export const zWebhookConfig = z.object({
|
|||||||
type: z.literal('webhook'),
|
type: z.literal('webhook'),
|
||||||
url: z.string().url(),
|
url: z.string().url(),
|
||||||
headers: z.record(z.string()),
|
headers: z.record(z.string()),
|
||||||
payload: z.record(z.string(), z.unknown()),
|
payload: z.record(z.string(), z.unknown()).optional(),
|
||||||
});
|
});
|
||||||
export type IWebhookConfig = z.infer<typeof zWebhookConfig>;
|
export type IWebhookConfig = z.infer<typeof zWebhookConfig>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user