Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): name enum values in the webhook filter summary
Yudhi Armyndharis5859f41896b1
diff --git a/dashboard/src/components/FilterBuilder.tsx b/dashboard/src/components/FilterBuilder.tsxindex 548452ea1..d570d98b4 100644--- a/dashboard/src/components/FilterBuilder.tsx+++ b/dashboard/src/components/FilterBuilder.tsx@@ -9,7 +9,7 @@ import {type WebhookFilterCondition,type WebhookFilterOperator,} from '../services/api';-import { messageTypeLabelKey } from '../utils/enumLabels';+import { filterValueLabel } from '../utils/enumLabels';import './FilterBuilder.css';type FieldKind = 'id' | 'idArray' | 'text' | 'enum' | 'boolean';@@ -19,8 +19,6 @@ interface FieldDescriptor {kind: FieldKind;operators: WebhookFilterOperator[];enumValues?: readonly string[];- /** i18n key that names an enum value; the value itself is what the filter sends. */- enumLabel?: (value: string) => string;}// Mirrors the backend message-family field registry (src/modules/webhook/filters/filter-types.ts).@@ -29,21 +27,9 @@ const MESSAGE_FIELDS: FieldDescriptor[] = [{ field: 'recipient', kind: 'id', operators: ['is', 'isNot'] },{ field: 'chatId', kind: 'id', operators: ['is', 'isNot'] },{ field: 'body', kind: 'text', operators: ['contains', 'equals'] },- {- field: 'type',- kind: 'enum',- operators: ['is', 'isNot'],- enumValues: MESSAGE_TYPES,- enumLabel: messageTypeLabelKey,- },+ { field: 'type', kind: 'enum', operators: ['is', 'isNot'], enumValues: MESSAGE_TYPES },{ field: 'isGroup', kind: 'boolean', operators: ['is'] },- {- field: 'kind',- kind: 'enum',- operators: ['is', 'isNot'],- enumValues: CHAT_KINDS,- enumLabel: kind => `chats.kind.${kind}`,- },+ { field: 'kind', kind: 'enum', operators: ['is', 'isNot'], enumValues: CHAT_KINDS },{ field: 'fromMe', kind: 'boolean', operators: ['is'] },{ field: 'hasMedia', kind: 'boolean', operators: ['is'] },{ field: 'mentions', kind: 'idArray', operators: ['is', 'isNot'] },@@ -246,7 +232,7 @@ export function FilterBuilder({ filters, onChange, chats }: FilterBuilderProps)});}}>- {def.enumLabel ? t(def.enumLabel(option), { defaultValue: option }) : option}+ {filterValueLabel(t, def.field, option)}</button>);})}diff --git a/dashboard/src/pages/Webhooks.test.ts b/dashboard/src/pages/Webhooks.test.tsindex 7d1efc7ac..f823905d5 100644--- a/dashboard/src/pages/Webhooks.test.ts+++ b/dashboard/src/pages/Webhooks.test.ts@@ -99,3 +99,35 @@ test('a failed refetch keeps the cached list and flags the error above it', asynawait rtl.screen.findByText('Failed to load data');rtl.screen.getByText('https://example.test/hook');});++test('the filter badge popover names enum values in words, like the filter builder', async () => {+ webhooksStatus = 200;+ webhookList = [+ {+ id: 'w1',+ sessionId: 'sess-1',+ url: 'https://example.test/hook',+ events: ['message.received'],+ active: true,+ filters: {+ conditions: [+ { field: 'type', operator: 'is', value: ['image', 'unknown', 'future-type'] },+ { field: 'kind', operator: 'isNot', value: ['individual'] },+ { field: 'sender', operator: 'is', value: ['[email protected]'] },+ ],+ },+ },+ ];+ renderWebhooks();+ const badge = (await rtl.screen.findByText('3 filters')).closest('.filter-badge') as HTMLElement;+ rtl.fireEvent.focus(badge);++ const rows = Array.from(document.querySelectorAll('.filter-popover-row')).map(r => r.textContent);+ assert.deepEqual(rows, [+ // An unmapped value stays raw rather than disappearing.+ 'Message type is Image, Unknown type, future-type',+ 'Chat kind is not Individual',+ // A contact field has no labels; its JIDs are shown as they are.+ 'Sender is [email protected]',+ ]);+});diff --git a/dashboard/src/pages/Webhooks.tsx b/dashboard/src/pages/Webhooks.tsxindex 089fc8133..f70ed025c 100644--- a/dashboard/src/pages/Webhooks.tsx+++ b/dashboard/src/pages/Webhooks.tsx@@ -15,6 +15,7 @@ import {import { webhookApi, type Webhook, type WebhookFilters, type WebhookFilterCondition } from '../services/api';import { useDocumentTitle } from '../hooks/useDocumentTitle';import { availableEventNames } from '../utils/webhookEvents';+import { filterValueLabel } from '../utils/enumLabels';import { useRole } from '../hooks/useRole';import { useToast } from '../hooks/useToast';import {@@ -43,7 +44,7 @@ function conditionSummary(c: WebhookFilterCondition, t: TFn): string {if (typeof c.value === 'boolean') {value = c.value ? t('webhooks.filters.yes') : t('webhooks.filters.no');} else if (Array.isArray(c.value)) {- value = c.value.join(', ');+ value = c.value.map(v => filterValueLabel(t, c.field, v)).join(', ');} else {value = `"${c.value}"`;}diff --git a/dashboard/src/utils/enumLabels.ts b/dashboard/src/utils/enumLabels.tsindex 9fd58efc5..fc38fbab8 100644--- a/dashboard/src/utils/enumLabels.ts+++ b/dashboard/src/utils/enumLabels.ts@@ -1,4 +1,5 @@// i18n keys for enum values the API sends as raw keys.+import type { TFunction } from 'i18next';/*** The key naming a message type where the type is a category: a chart slice, a webhook filter@@ -7,3 +8,12 @@*/export const messageTypeLabelKey = (type: string): string =>type === 'unknown' ? 'chats.messageType.unknownType' : `chats.messageType.${type}`;++/**+ * A webhook filter value in words, for the enum fields (message type, chat kind). Any other field,+ * or a value with no label, reads as the raw value the filter sends.+ */+export function filterValueLabel(t: TFunction, field: string, value: string): string {+ const key = field === 'type' ? messageTypeLabelKey(value) : field === 'kind' ? `chats.kind.${value}` : undefined;+ return key ? t(key, { defaultValue: value }) : value;+}