Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Retain webhook drafts until notification saves are acknowledged

pulse-triage[bot]c4fa4669ce0e
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index 44d19f48f2..ffbbab04bb 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -1155,6 +1155,34 @@ inspectability, or convert missing/stale evidence into health.
## Current State
+### Webhook drafts survive unconfirmed persistence
+
+The existing Notifications editor awaits an explicit successful acknowledgement
+from its add/update owner before clearing a draft. The owner returns success
+only after the API responds and the returned destination replaces or joins the
+displayed inventory. A rejected or interrupted save keeps the same inputs,
+masked fields, template, mention and tag/severity policy. Fixed inline guidance
+does not claim the write was rejected: an interrupted response can follow a
+committed create, so the operator checks saved destinations in another tab
+before explicitly retrying. There is no editor-triggered automatic replay.
+
+One pending editor save locks the draft, Cancel and the conflicting local list
+controls, and subsequent Save calls do not invoke another mutation. Success
+closes the editor; failure unlocks it for correction or deliberate cancellation.
+The API, encrypted persistence/publication ordering, saved-value masking, Test
+payload parity, delivery policy, SSRF/TLS and existing shared API-client retry
+rules are unchanged. This is draft recovery, not exactly-once creation or proof
+that ordinary notifications arrive.
+
+`WebhookConfig.persistence.test.tsx` exercises the actual editor and mutation
+owner through deferred create/update responses, failure, explicit retry,
+canonical accepted response, cancellation and fixed callback-error guidance.
+`WebhookConfig.test.tsx` now acknowledges successful saves before expecting
+editor dismissal. The local `webhook-save-acknowledgement` browser fixture
+checks the same components with synthetic API transport, including desktop and
+phone keyboard/touch journeys and another-tab reconciliation after a lost
+response. It sends no real notification and establishes no installed outcome.
+
### Active Docker update pending age survives restart
A positive Docker image-update report reuses the matching active occurrence's
diff --git a/frontend-modern/browser-tests/webhook-composed.tsx b/frontend-modern/browser-tests/webhook-composed.tsx
index 031b934b28..43471431bc 100644
--- a/frontend-modern/browser-tests/webhook-composed.tsx
+++ b/frontend-modern/browser-tests/webhook-composed.tsx
@@ -7,7 +7,10 @@ import '../src/index.css';
function Fixture() {
const [operations, setOperations] = createSignal(0);
- const unexpectedOperation = () => setOperations((count) => count + 1);
+ const unexpectedOperation = () => {
+ setOperations((count) => count + 1);
+ return false;
+ };
return (
<main class="mx-auto min-h-screen max-w-4xl space-y-4 bg-surface p-4 text-base-content">
<h1 class="text-lg font-semibold">Webhook setup</h1>
diff --git a/frontend-modern/browser-tests/webhook-save-acknowledgement.cjs b/frontend-modern/browser-tests/webhook-save-acknowledgement.cjs
new file mode 100644
index 0000000000..b79e308579
--- /dev/null
+++ b/frontend-modern/browser-tests/webhook-save-acknowledgement.cjs
@@ -0,0 +1,381 @@
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const path = require('node:path');
+const crypto = require('node:crypto');
+const { chromium, webkit } = require('playwright');
+const root = '/workspace/frontend-modern';
+const output = '/workspace/tmp/webhook-save-proof/browser';
+const hash = (file) => crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
+
+(async () => {
+ const binding = JSON.parse(
+ fs.readFileSync('/workspace/tmp/webhook-save-proof/browser-binding.json'),
+ );
+ for (const [file, digest] of Object.entries(binding.content_sha256)) {
+ assert.equal(hash(path.join('/workspace', file)), digest);
+ }
+ const playwrightVersion = require('playwright/package.json').version;
+ assert.equal(
+ playwrightVersion,
+ JSON.parse(fs.readFileSync('/workspace/tests/integration/package-lock.json')).packages[
+ 'node_modules/@playwright/test'
+ ].version,
+ );
+ fs.mkdirSync(output, { recursive: true });
+ process.chdir(root);
+ const { createServer } = await import(path.join(root, 'node_modules/vite/dist/node/index.js'));
+ const server = await createServer({
+ root,
+ configFile: path.join(root, 'vite.config.ts'),
+ cacheDir: path.join(output, 'vite-cache'),
+ server: { host: '127.0.0.1', port: 5310, strictPort: true, watch: null },
+ });
+ const origin = 'http://127.0.0.1:5310';
+ const results = [],
+ screenshots = [],
+ browserVersions = [];
+ let browser,
+ phase = 'server',
+ browserClosed = false,
+ serverClosed = false,
+ passed = false;
+ try {
+ await server.listen();
+ for (const [name, engine, width, height, dark] of [
+ ['desktop-light', chromium, 1365, 900, false],
+ ['desktop-dark', chromium, 1365, 900, true],
+ ['phone-dark', webkit, 390, 844, true],
+ ['narrow-light', webkit, 320, 740, false],
+ ]) {
+ browserClosed = false;
+ browser = await engine.launch(
+ engine === chromium
+ ? { headless: true, channel: 'chromium', args: ['--no-sandbox'] }
+ : { headless: true },
+ );
+ browserVersions.push({
+ name,
+ engine: engine === chromium ? 'chromium' : 'webkit',
+ version: browser.version(),
+ });
+ const context = await browser.newContext({
+ viewport: { width, height },
+ isMobile: width < 500,
+ hasTouch: width < 500,
+ locale: 'en-GB',
+ });
+ await context.addInitScript((dark) => {
+ const apply = () => document.documentElement.classList.toggle('dark', dark);
+ if (document.documentElement) apply();
+ else document.addEventListener('DOMContentLoaded', apply, { once: true });
+ }, dark);
+ const saved = {
+ id: 'saved-hook',
+ name: 'Existing destination',
+ url: 'https://example.test/receiver',
+ method: 'POST',
+ enabled: true,
+ service: 'generic',
+ headers: { Authorization: '********' },
+ customFields: { team: 'ops' },
+ template: '{"message":"{{message}}"}',
+ mention: 'operators',
+ tagFilter: ['department-a'],
+ tagFilterMode: 'any',
+ minimumSeverity: 'warning',
+ };
+ let inventory = [saved],
+ mode = 'pending',
+ release;
+ const writes = [],
+ unexpected = [],
+ errors = [],
+ checks = [];
+ await context.routeWebSocket(/.*/, (socket) => {
+ const url = new URL(socket.url());
+ if (url.origin === 'ws://127.0.0.1:5310' && url.pathname === '/') socket.connectToServer();
+ else {
+ unexpected.push({ type: 'websocket' });
+ socket.close();
+ }
+ });
+ await context.route('**/*', async (route) => {
+ const req = route.request(),
+ url = new URL(req.url());
+ if (url.origin !== origin) {
+ unexpected.push({ type: 'off-origin' });
+ return route.abort();
+ }
+ if (!url.pathname.startsWith('/api/')) return route.continue();
+ if (req.method() === 'GET') {
+ if (url.pathname === '/api/health') return route.fulfill({ json: { status: 'healthy' } });
+ if (url.pathname === '/api/notifications/webhooks')
+ return route.fulfill({ json: inventory });
+ if (url.pathname === '/api/notifications/webhook-templates')
+ return route.fulfill({ json: [] });
+ }
+ if (
+ (req.method() === 'POST' && url.pathname === '/api/notifications/webhooks') ||
+ (req.method() === 'PUT' && url.pathname === '/api/notifications/webhooks/saved-hook')
+ ) {
+ const write = { method: req.method(), path: url.pathname, payload: req.postDataJSON() };
+ writes.push(write);
+ if (mode === 'pending')
+ await new Promise((resolve) => {
+ release = resolve;
+ });
+ if (mode === 'failure')
+ return route.fulfill({
+ status: 500,
+ json: { error: 'Synthetic configuration save unavailable' },
+ });
+ const accepted = {
+ ...write.payload,
+ id: req.method() === 'POST' ? 'new-hook' : 'saved-hook',
+ headers: { Authorization: '********' },
+ };
+ inventory =
+ req.method() === 'POST'
+ ? [...inventory, accepted]
+ : inventory.map((hook) => (hook.id === accepted.id ? accepted : hook));
+ if (mode === 'lost-response') return route.abort('failed');
+ return route.fulfill({ json: accepted });
+ }
+ unexpected.push({ method: req.method(), path: url.pathname });
+ return route.fulfill({
+ status: 403,
+ json: { error: 'Fixture refuses Test, deletion and unrelated operations' },
+ });
+ });
+ results.push({ name, checks, writes, unexpected, errors });
+ const page = await context.newPage();
+ page.on('pageerror', (error) => errors.push(error.message));
+ page.setDefaultTimeout(8000);
+ page.setDefaultNavigationTimeout(45000);
+ const check = async (label, action) => {
+ phase = `${name}: ${label}`;
+ await action();
+ checks.push(label);
+ };
+ const click = async (locator) => {
+ if (width < 500) await locator.tap();
+ else {
+ await locator.focus();
+ await page.keyboard.press('Enter');
+ }
+ };
+ const capture = async (state) => {
+ const file = `${name}-${state}.png`;
+ await page.screenshot({ path: path.join(output, file) });
+ screenshots.push({
+ file,
+ state,
+ sha256: hash(path.join(output, file)),
+ viewport: { width, height },
+ });
+ };
+ const noOverflow = async () =>
+ assert.ok(
+ await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1),
+ );
+ phase = `${name}: load actual editor`;
+ await page.goto(`${origin}/browser-tests/webhook-save-acknowledgement.html`);
+ await page.getByText('Existing destination', { exact: true }).first().waitFor();
+ await click(page.getByRole('button', { name: '+ Add Webhook', exact: true }));
+ await page.getByLabel('Name', { exact: true }).fill('New destination');
+ await page.getByLabel('Webhook URL', { exact: true }).fill('https://example.test/new');
+ await page
+ .getByLabel('Custom header 1 value', { exact: true })
+ .fill('application/custom+json');
+ await page.getByLabel('Minimum alert severity', { exact: true }).selectOption('warning');
+ await click(page.getByRole('button', { name: 'Add Webhook', exact: true }));
+ await check(
+ 'pending save keeps draft, locks conflicting actions and admits one write',
+ async () => {
+ await page.getByRole('button', { name: 'Saving…', exact: true }).waitFor();
+ assert.equal(
+ await page.getByLabel('Name', { exact: true }).inputValue(),
+ 'New destination',
+ );
+ assert.equal(await page.getByLabel('Name', { exact: true }).isEnabled(), false);
+ for (const label of ['Saving…', 'Cancel', 'Edit', 'Delete', 'Enabled', 'Disable All'])
+ assert.equal(
+ await page.getByRole('button', { name: label, exact: true }).isEnabled(),
+ false,
+ );
+ await page.getByRole('button', { name: 'Saving…' }).evaluate((button) => {
+ button.click();
+ button.click();
+ });
+ await page.waitForFunction(
+ () => document.querySelector('fieldset')?.getAttribute('aria-busy') === 'true',
+ );
+ assert.equal(writes.length, 1);
+ await noOverflow();
+ },
+ );
+ await capture('pending');
+ mode = 'failure';
+ release();
+ await check(
+ 'failed create retains values and announces fixed uncertainty, without a replay',
+ async () => {
+ await page.getByRole('alert').waitFor();
+ assert.ok((await page.getByRole('alert').innerText()).includes('another tab'));
+ assert.equal(
+ await page.getByLabel('Custom header 1 value').inputValue(),
+ 'application/custom+json',
+ );
+ assert.equal(
+ await page.getByLabel('Minimum alert severity', { exact: true }).inputValue(),
+ 'warning',
+ );
+ assert.equal(await page.getByLabel('Name', { exact: true }).isEnabled(), true);
+ assert.equal(writes.length, 1);
+ await noOverflow();
+ },
+ );
+ await page.getByRole('alert').scrollIntoViewIfNeeded();
+ await capture('failed-create');
+ mode = 'success';
+ await click(page.getByRole('button', { name: 'Add Webhook', exact: true }));
+ await check('explicit create retry closes only after accepted response', async () => {
+ await page.getByRole('button', { name: '+ Add Webhook', exact: true }).waitFor();
+ assert.equal(
+ await page.getByLabel('Saved destination names').innerText(),
+ 'Existing destination, New destination',
+ );
+ assert.equal(writes.length, 2);
+ assert.deepEqual(writes[0].payload, writes[1].payload);
+ assert.equal(await page.getByRole('alert').count(), 0);
+ });
+ await click(page.getByRole('button', { name: 'Edit', exact: true }).first());
+ await page.getByLabel('Name', { exact: true }).fill('Edited destination');
+ mode = 'failure';
+ await click(page.getByRole('button', { name: 'Update Webhook', exact: true }));
+ await check('failed edit keeps masking, template, tag and severity policy', async () => {
+ await page.getByRole('alert').waitFor();
+ assert.equal(await page.getByLabel('Custom header 1 value').inputValue(), '********');
+ assert.equal(
+ await page.getByLabel('Name', { exact: true }).inputValue(),
+ 'Edited destination',
+ );
+ assert.equal(
+ await page.getByLabel('Minimum alert severity', { exact: true }).inputValue(),
+ 'warning',
+ );
+ const payload = writes[2].payload;
+ for (const key of [
+ 'headers',
+ 'customFields',
+ 'template',
+ 'mention',
+ 'tagFilter',
+ 'tagFilterMode',
+ 'minimumSeverity',
+ ])
+ assert.deepEqual(payload[key], saved[key]);
+ assert.equal(
+ await page.getByLabel('Saved destination names').innerText(),
+ 'Existing destination, New destination',
+ );
+ await noOverflow();
+ });
+ await page.getByRole('alert').scrollIntoViewIfNeeded();
+ await capture('failed-edit');
+ mode = 'success';
+ await click(page.getByRole('button', { name: 'Update Webhook', exact: true }));
+ await check('accepted edit replaces inventory with acknowledged response', async () => {
+ await page.getByRole('button', { name: '+ Add Webhook', exact: true }).waitFor();
+ assert.equal(
+ await page.getByLabel('Saved destination names').innerText(),
+ 'Edited destination, New destination',
+ );
+ assert.deepEqual(writes[2].payload, writes[3].payload);
+ });
+ await click(page.getByRole('button', { name: '+ Add Webhook', exact: true }));
+ await page.getByLabel('Name', { exact: true }).fill('Unconfirmed destination');
+ await page
+ .getByLabel('Webhook URL', { exact: true })
+ .fill('https://example.test/unconfirmed');
+ mode = 'lost-response';
+ await click(page.getByRole('button', { name: 'Add Webhook', exact: true }));
+ await check('lost response leaves the draft and makes no unrequested duplicate', async () => {
+ await page.getByRole('alert').waitFor();
+ assert.equal(
+ await page.getByLabel('Name', { exact: true }).inputValue(),
+ 'Unconfirmed destination',
+ );
+ assert.equal(writes.length, 5);
+ assert.ok(!(await page.getByRole('alert').innerText()).includes('not saved'));
+ const other = await context.newPage();
+ await other.goto(`${origin}/browser-tests/webhook-save-acknowledgement.html`);
+ await other.getByText('Unconfirmed destination', { exact: true }).first().waitFor();
+ assert.ok(
+ (await other.getByLabel('Saved destination names').innerText()).includes(
+ 'Unconfirmed destination',
+ ),
+ );
+ await other.close();
+ assert.equal(writes.length, 5);
+ await noOverflow();
+ });
+ await page.getByRole('alert').scrollIntoViewIfNeeded();
+ await capture('lost-response');
+ await click(page.getByRole('button', { name: 'Cancel', exact: true }));
+ await click(page.getByRole('button', { name: '+ Add Webhook', exact: true }));
+ await check(
+ 'deliberate Cancel clears old draft and error without another write',
+ async () => {
+ assert.equal(await page.getByLabel('Name', { exact: true }).inputValue(), '');
+ assert.equal(await page.getByRole('alert').count(), 0);
+ assert.equal(writes.length, 5);
+ assert.deepEqual(unexpected, []);
+ assert.deepEqual(errors, []);
+ await noOverflow();
+ },
+ );
+
+ await browser.close();
+ browserClosed = true;
+ }
+ passed = true;
+ } catch (error) {
+ fs.writeFileSync(
+ path.join(output, 'failure.json'),
+ JSON.stringify({ phase, error: String(error) }, null, 2),
+ );
+ throw error;
+ } finally {
+ if (browser && !browserClosed) {
+ await browser.close();
+ browserClosed = true;
+ }
+ await server.close();
+ serverClosed = true;
+ fs.writeFileSync(
+ path.join(output, 'result.json'),
+ JSON.stringify(
+ {
+ result: passed ? 'passed' : 'failed',
+ phase,
+ base_sha: binding.base_sha,
+ content_sha256: binding.content_sha256,
+ playwrightVersion,
+ browserVersions,
+ results,
+ screenshots,
+ browserClosed,
+ serverClosed,
+ scope:
+ 'Actual existing Webhook section/editor/mutation owner and API client with synthetic transport. No provider/notification, native persistence, deployment or release acceptance.',
+ },
+ null,
+ 2,
+ ),
+ );
+ }
+})().catch((error) => {
+ process.stderr.write(`${error.stack || error}\n`);
+ process.exitCode = 1;
+});
diff --git a/frontend-modern/browser-tests/webhook-save-acknowledgement.html b/frontend-modern/browser-tests/webhook-save-acknowledgement.html
new file mode 100644
index 0000000000..760e19d8d0
--- /dev/null
+++ b/frontend-modern/browser-tests/webhook-save-acknowledgement.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Webhook save acknowledgement verification</title>
+ </head>
+ <body>
+ <div id="root"></div>
+ <script type="module" src="./webhook-save-acknowledgement.tsx"></script>
+ </body>
+</html>
diff --git a/frontend-modern/browser-tests/webhook-save-acknowledgement.tsx b/frontend-modern/browser-tests/webhook-save-acknowledgement.tsx
new file mode 100644
index 0000000000..e485040ba5
--- /dev/null
+++ b/frontend-modern/browser-tests/webhook-save-acknowledgement.tsx
@@ -0,0 +1,32 @@
+// Actual destination section, editor, API client and mutation owner. The runner
+// supplies synthetic local responses; no notification, provider or saved host.
+import { render } from 'solid-js/web';
+import { AlertWebhookDestinationsSection } from '../src/features/alerts/AlertWebhookDestinationsSection';
+import { useAlertWebhookDestinationsState } from '../src/features/alerts/useAlertWebhookDestinationsState';
+import '../src/index.css';
+
+function Fixture() {
+ const state = useAlertWebhookDestinationsState();
+ return (
+ <main class="mx-auto min-h-screen max-w-4xl space-y-4 bg-surface p-4 text-base-content">
+ <h1 class="text-lg font-semibold">Notification destinations</h1>
+ <p class="text-sm text-muted">Offline save-recovery check. No notification is sent.</p>
+ <AlertWebhookDestinationsSection
+ webhooks={state.webhooks()}
+ addWebhook={state.addWebhook}
+ updateWebhook={state.updateWebhook}
+ deleteWebhook={state.deleteWebhook}
+ testWebhook={state.testWebhook}
+ testingWebhook={state.testingWebhook()}
+ />
+ <output aria-label="Saved destination names" class="block text-sm">
+ {state
+ .webhooks()
+ .map((hook) => hook.name)
+ .join(', ')}
+ </output>
+ </main>
+ );
+}
+
+render(() => <Fixture />, document.getElementById('root')!);
diff --git a/frontend-modern/browser-verification/ca7dfc37d900399f.json b/frontend-modern/browser-verification/ca7dfc37d900399f.json
new file mode 100644
index 0000000000..803cadf46f
--- /dev/null
+++ b/frontend-modern/browser-verification/ca7dfc37d900399f.json
@@ -0,0 +1,52 @@
+{
+ "version": 1,
+ "base_sha": "fcaaabe25bbd8766c2eea6f72fbac62b92ea26a0",
+ "result": "passed",
+ "verified_at": "2026-10-10T02:54:43Z",
+ "changed_paths": [
+ "frontend-modern/src/components/Alerts/WebhookConfig.tsx",
+ "frontend-modern/src/components/Alerts/WebhookConfigForm.tsx",
+ "frontend-modern/src/components/Alerts/WebhookConfigList.tsx",
+ "frontend-modern/src/components/Alerts/useWebhookConfigState.ts",
+ "frontend-modern/src/features/alerts/AlertWebhookDestinationsSection.tsx",
+ "frontend-modern/src/features/alerts/useAlertWebhookDestinationsState.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/components/Alerts/WebhookConfig.tsx": "bdc26fd7e7ff60c4e5dee07e65a684cd730e1b840c0a4074c40a3d3127f8734f",
+ "frontend-modern/src/components/Alerts/WebhookConfigForm.tsx": "97ca12ed9c7e7c0fe93a6d5c9eb0daed596ce859fd884f2f56316ab2d91512d3",
+ "frontend-modern/src/components/Alerts/WebhookConfigList.tsx": "3caf78928a5b28947eaba68a335aa7404262d0cafba3a37cefb8095fafc9b545",
+ "frontend-modern/src/components/Alerts/useWebhookConfigState.ts": "b3f3888bc6a87c2894ccf40dd936a4076a7b910982743037deb57730f294996f",
+ "frontend-modern/src/features/alerts/AlertWebhookDestinationsSection.tsx": "002609ca384cec8e6275392ce1c0617088ad64c9f06e621edf93bfe11818ad5b",
+ "frontend-modern/src/features/alerts/useAlertWebhookDestinationsState.ts": "50e7843784251c2d47cdb20886df9f94b1a066f2dac788234a129bd4ae1a7184"
+ },
+ "routes": [
+ "Existing Notifications webhook section in local /browser-tests/webhook-save-acknowledgement.html",
+ "Existing Notifications editor and real mutation owner/API client; no shipped new route"
+ ],
+ "states": [
+ "Pending create, disabled editor/conflicting list controls, one request",
+ "Failed create/update preserves the same draft and masks/template/routing",
+ "Accepted create/update incorporates canonical response before clearing draft",
+ "Accepted synthetic create followed by lost response: draft retained, another tab confirms stored fixture without duplicate",
+ "Explicit retry and deliberate cancellation; desktop light/dark and phone dark/narrow light"
+ ],
+ "interactions": [
+ "28 assertion groups: keyboard Enter and phone touch saves/cancel, request counts/payloads, failed-save recovery, masked update, another-tab reconciliation",
+ "16 inspected screenshots; fixed inline warning readable, fieldsets/controls remain within 320px viewport; lower phone footer reached by scrolling before each interaction"
+ ],
+ "viewports": [
+ {
+ "width": 1365,
+ "height": 900
+ },
+ {
+ "width": 390,
+ "height": 844
+ },
+ {
+ "width": 320,
+ "height": 740
+ }
+ ],
+ "notes": "Playwright 1.56.1; Chromium 141.0.7390.37 and WebKit 26.0; browser/server closed. Actual existing components with synthetic local API responses. No notification/native persistence/provider/delivery/release acceptance. Earlier label/CSRF-setup fixture failures retained separately."
+}
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx
index db539db324..94ffd60035 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.persistence.test.tsx
@@ -185,7 +185,9 @@ describe('webhook persistence acknowledgement', () => {
render(() => (
<WebhookConfig
webhooks={[]}
- onAdd={async () => { throw new Error(privateDetail); }}
+ onAdd={async () => {
+ throw new Error(privateDetail);
+ }}
onUpdate={async () => false}
onDelete={() => {}}
onTest={() => {}}
@@ -193,19 +195,26 @@ describe('webhook persistence acknowledgement', () => {
));
openNewDraft();
fireEvent.click(screen.getByRole('button', { name: 'Add Webhook', exact: true }));
- await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Check the configured destinations'));
+ await waitFor(() =>
+ expect(screen.getByRole('alert')).toHaveTextContent('Check the configured destinations'),
+ );
expect(screen.getByRole('alert')).not.toHaveTextContent(privateDetail);
expect(screen.getByLabelText('Name')).toHaveValue('New destination');
});
it('returns true only after an accepted create or update and false on failure', async () => {
- const { result: owner } = renderHook(() => useAlertWebhookDestinationsState({ autoLoad: false }));
+ const { result: owner } = renderHook(() =>
+ useAlertWebhookDestinationsState({ autoLoad: false }),
+ );
vi.mocked(NotificationsAPI.createWebhook).mockResolvedValue(savedWebhook);
expect(await owner.addWebhook(savedWebhook)).toBe(true);
vi.mocked(NotificationsAPI.updateWebhook).mockRejectedValue(new Error('Save unavailable'));
expect(await owner.updateWebhook(savedWebhook)).toBe(false);
expect(owner.webhooks()).toEqual([savedWebhook]);
- vi.mocked(NotificationsAPI.updateWebhook).mockResolvedValue({ ...savedWebhook, enabled: false });
+ vi.mocked(NotificationsAPI.updateWebhook).mockResolvedValue({
+ ...savedWebhook,
+ enabled: false,
+ });
expect(await owner.updateWebhook(savedWebhook)).toBe(true);
});
});
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx
index b58eb327c7..18c8d4a3a5 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.test.tsx
@@ -110,8 +110,8 @@ describe('WebhookConfig', () => {
let onTestMock: ReturnType<typeof vi.fn<(...args: any[]) => any>>;
beforeEach(() => {
- onAddMock = vi.fn();
- onUpdateMock = vi.fn();
+ onAddMock = vi.fn().mockResolvedValue(true);
+ onUpdateMock = vi.fn().mockResolvedValue(true);
onDeleteMock = vi.fn();
onTestMock = vi.fn();
getWebhookTemplatesMock.mockReset();
@@ -630,7 +630,7 @@ describe('WebhookConfig', () => {
expect(onAddMock).not.toHaveBeenCalled();
});
- it('resets form and closes panel after adding a webhook', () => {
+ it('resets form and closes panel after adding a webhook', async () => {
render(() => (
<WebhookConfig
webhooks={[]}
@@ -651,8 +651,8 @@ describe('WebhookConfig', () => {
fireEvent.click(screen.getByText('Add Webhook'));
- // Form should close, "+ Add Webhook" should reappear
- expect(screen.getByText('+ Add Webhook')).toBeInTheDocument();
+ // Form closes only after the owner acknowledges the save.
+ await waitFor(() => expect(screen.getByText('+ Add Webhook')).toBeInTheDocument());
expect(screen.queryByText('Service Type')).not.toBeInTheDocument();
});
diff --git a/frontend-modern/src/components/Alerts/WebhookConfig.tsx b/frontend-modern/src/components/Alerts/WebhookConfig.tsx
index a2be7425a9..b7a3cde737 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfig.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfig.tsx
@@ -9,8 +9,8 @@ import { useWebhookConfigState } from './useWebhookConfigState';
export interface WebhookConfigProps {
webhooks: Webhook[];
- onAdd: (webhook: Omit<Webhook, 'id'>) => void;
- onUpdate: (webhook: Webhook) => void;
+ onAdd: (webhook: Omit<Webhook, 'id'>) => boolean | Promise<boolean>;
+ onUpdate: (webhook: Webhook) => boolean | Promise<boolean>;
onDelete: (id: string) => void;
onTest: (id: string, webhookData?: Omit<Webhook, 'id'>) => void;
testing?: string | null;
@@ -26,6 +26,7 @@ export function WebhookConfig(props: WebhookConfigProps) {
webhooks={props.webhooks}
templates={state.templates}
testing={props.testing}
+ saving={state.saving()}
allEnabled={state.allEnabled}
someEnabled={state.someEnabled}
toggleAllWebhooks={state.toggleAllWebhooks}
@@ -58,12 +59,15 @@ export function WebhookConfig(props: WebhookConfigProps) {
testWebhookForm={state.testWebhookForm}
saveWebhook={state.saveWebhook}
testing={props.testing}
+ saving={state.saving}
+ saveError={state.saveError}
/>
</Show>
<Show when={!state.adding()}>
<button
onClick={state.openAddForm}
+ disabled={state.saving()}
class="min-h-11 w-full border border-dashed border-border px-2 py-1 text-xs text-muted hover:bg-surface-hover sm:min-h-0"
>
+ {ALERT_WEBHOOK_ADD_LABEL}
diff --git a/frontend-modern/src/components/Alerts/WebhookConfigForm.tsx b/frontend-modern/src/components/Alerts/WebhookConfigForm.tsx
index a81e82549e..5efdbf63ca 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfigForm.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfigForm.tsx
@@ -73,11 +73,18 @@ interface WebhookConfigFormProps {
testWebhookForm: () => void;
saveWebhook: () => void;
testing?: string | null;
+ saving: Accessor<boolean>;
+ saveError: Accessor<string | null>;
}
export function WebhookConfigForm(props: WebhookConfigFormProps) {
return (
- <div class="space-y-4 text-sm">
+ <fieldset
+ class="min-w-0 space-y-4 border-0 p-0 text-sm"
+ disabled={props.saving()}
+ aria-busy={props.saving()}
+ >
+ <legend class="sr-only">Webhook configuration</legend>
<div>
<div class="flex items-center justify-between mb-4">
<span class="text-sm font-medium text-base-content">Service Type</span>
@@ -408,6 +415,12 @@ export function WebhookConfigForm(props: WebhookConfigFormProps) {
</label>
</div>
+ <Show when={props.saveError()}>
+ <p role="alert" class="text-sm text-red-700 dark:text-red-300">
+ {props.saveError()}
+ </p>
+ </Show>
+
<div class="flex justify-end gap-2 text-xs">
<button
onClick={props.cancelForm}
@@ -429,12 +442,12 @@ export function WebhookConfigForm(props: WebhookConfigFormProps) {
</Show>
<button
onClick={props.saveWebhook}
- disabled={!props.formData().name || !props.formData().url}
+ disabled={props.saving() || !props.formData().name || !props.formData().url}
class="min-h-11 px-3 py-1.5 bg-blue-600 text-white text-xs rounded-sm hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed sm:min-h-0"
>
- {getAlertWebhookSubmitLabel(Boolean(props.editingId()))}
+ {props.saving() ? 'Saving…' : getAlertWebhookSubmitLabel(Boolean(props.editingId()))}
</button>
</div>
- </div>
+ </fieldset>
);
}
diff --git a/frontend-modern/src/components/Alerts/WebhookConfigList.tsx b/frontend-modern/src/components/Alerts/WebhookConfigList.tsx
index e910e04ed5..04aa8c4487 100644
--- a/frontend-modern/src/components/Alerts/WebhookConfigList.tsx
+++ b/frontend-modern/src/components/Alerts/WebhookConfigList.tsx
@@ -17,6 +17,7 @@ interface WebhookConfigListProps {
webhooks: Webhook[];
templates: Accessor<WebhookTemplate[]>;
testing?: string | null;
+ saving: boolean;
allEnabled: Accessor<boolean>;
someEnabled: Accessor<boolean>;
toggleAllWebhooks: (enabled: boolean) => void;
@@ -39,14 +40,14 @@ export function WebhookConfigList(props: WebhookConfigListProps) {
<div class="flex flex-wrap gap-2 sm:flex-nowrap">
<button
onClick={() => props.toggleAllWebhooks(false)}
- disabled={!props.someEnabled()}
+ disabled={props.saving || !props.someEnabled()}
class="min-h-11 w-full rounded-sm border px-3 py-1 text-xs transition-colors hover:bg-surface-hover sm:min-h-0 sm:w-auto"
>
{getAlertWebhookToggleAllLabel(false)}
</button>
<button
onClick={() => props.toggleAllWebhooks(true)}
- disabled={props.allEnabled()}
+ disabled={props.saving || props.allEnabled()}
class="min-h-11 w-full rounded-sm border border-green-500 px-3 py-1 text-xs text-green-700 transition-colors hover:bg-green-50 sm:min-h-0 sm:w-auto dark:border-green-600 dark:text-green-400 dark:hover:bg-green-900/25"
>
{getAlertWebhookToggleAllLabel(true)}
@@ -61,6 +62,7 @@ export function WebhookConfigList(props: WebhookConfigListProps) {
<span class="font-medium text-base-content">{webhook.name}</span>
<button
onClick={() => props.onToggleWebhook(webhook)}
+ disabled={props.saving}
class={`min-h-11 rounded-sm border px-3 py-1 text-xs font-medium transition-colors sm:min-h-0 ${webhook.enabled ? 'border-green-500 text-green-700 hover:bg-green-50 dark:border-green-600 dark:text-green-400 dark:hover:bg-green-900/25' : 'border-border text-muted hover:bg-surface-hover'}`}
>
{getAlertWebhookToggleLabel(webhook.enabled)}
@@ -100,19 +102,21 @@ export function WebhookConfigList(props: WebhookConfigListProps) {
<div class="mt-3 flex flex-wrap gap-2 border-t border-border-subtle pt-2 sm:justify-end w-full">
<button
onClick={() => props.onTestWebhook(webhook)}
- disabled={props.testing === webhook.id || !webhook.enabled}
+ disabled={props.saving || props.testing === webhook.id || !webhook.enabled}
class="min-h-11 rounded-sm border px-3 py-1 text-xs text-base-content transition-colors hover:bg-surface-hover disabled:opacity-50 sm:min-h-0"
>
{getAlertWebhookTestLabel(props.testing === webhook.id)}
</button>
<button
onClick={() => props.onEditWebhook(webhook)}
+ disabled={props.saving}
class="min-h-11 rounded-sm border border-blue-300 px-3 py-1 text-xs text-blue-600 transition-colors hover:bg-blue-50 sm:min-h-0 dark:border-blue-500 dark:text-blue-300 dark:hover:bg-blue-900/25"
>
{ALERT_WEBHOOK_EDIT_LABEL}
</button>
<button
onClick={() => props.onDeleteWebhook(webhook)}
+ disabled={props.saving}
class="min-h-11 rounded-sm border border-red-300 px-3 py-1 text-xs text-red-600 transition-colors hover:bg-red-50 sm:min-h-0 dark:border-red-500 dark:text-red-300 dark:hover:bg-red-900/25"
>
{ALERT_WEBHOOK_DELETE_LABEL}
diff --git a/frontend-modern/src/components/Alerts/useWebhookConfigState.ts b/frontend-modern/src/components/Alerts/useWebhookConfigState.ts
index d0a9d703d2..7a4b5b12e2 100644
--- a/frontend-modern/src/components/Alerts/useWebhookConfigState.ts
+++ b/frontend-modern/src/components/Alerts/useWebhookConfigState.ts
@@ -72,6 +72,8 @@ const createCustomFieldInput = (
export interface WebhookConfigState {
adding: Accessor<boolean>;
+ saving: Accessor<boolean>;
+ saveError: Accessor<string | null>;
editingId: Accessor<string | null>;
formData: Accessor<WebhookConfigFormData>;
templates: Accessor<WebhookTemplate[]>;
@@ -87,7 +89,7 @@ export interface WebhookConfigState {
cancelForm: () => void;
editWebhook: (webhook: Webhook) => void;
selectService: (service: string) => void;
- saveWebhook: () => void;
+ saveWebhook: () => Promise<void>;
testWebhookForm: () => void;
toggleAllWebhooks: (enabled: boolean) => void;
updateHeaderInput: (index: number, patch: Partial<HeaderInput>) => void;
@@ -100,6 +102,8 @@ export interface WebhookConfigState {
export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigState {
const [adding, setAdding] = createSignal(false);
+ const [saving, setSaving] = createSignal(false);
+ const [saveError, setSaveError] = createSignal<string | null>(null);
const [editingId, setEditingId] = createSignal<string | null>(null);
const [formData, setFormData] = createSignal<WebhookConfigFormData>(createDefaultFormData());
const [templates, setTemplates] = createSignal<WebhookTemplate[]>([]);
@@ -127,6 +131,7 @@ export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigS
};
const resetForm = () => {
+ setSaveError(null);
setAdding(false);
setEditingId(null);
setFormData(createDefaultFormData());
@@ -157,6 +162,8 @@ export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigS
const someEnabled = () => props.webhooks.some((webhook) => webhook.enabled);
const openAddForm = () => {
+ if (saving()) return;
+ setSaveError(null);
setAdding(true);
setEditingId(null);
setFormData(createDefaultFormData());
@@ -168,10 +175,13 @@ export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigS
};
const cancelForm = () => {
+ if (saving()) return;
resetForm();
};
const editWebhook = (webhook: Webhook) => {
+ if (saving()) return;
+ setSaveError(null);
if (webhook.id) {
setEditingId(webhook.id);
}
@@ -242,7 +252,8 @@ export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigS
setShowServiceDropdown(false);
};
- const saveWebhook = () => {
+ const saveWebhook = async () => {
+ if (saving()) return;
const data = formData();
if (!data.name || !data.url) return;
@@ -250,38 +261,49 @@ export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigS
const customFields = buildMapFromInputs(customFieldInputs());
const normalizedCustomFields = normalizeAlertWebhookCustomFields(data.service, customFields);
- if (editingId()) {
- props.onUpdate({
- ...data,
- id: editingId()!,
- headers,
- service: data.service,
- template: data.payloadTemplate,
- customFields: normalizedCustomFields,
- mention: data.mention,
- });
- resetForm();
- return;
+ setSaving(true);
+ setSaveError(null);
+ // The owner updates inventory only after an acknowledged API write. Do
+ // not discard this draft (including masked saved fields) on an unconfirmed
+ // result, and never retry a potentially accepted create automatically.
+ const failureMessage =
+ 'Could not confirm the save. Your changes are still here. Check the configured destinations in another tab before trying again.';
+ try {
+ const accepted = editingId()
+ ? await props.onUpdate({
+ ...data,
+ id: editingId()!,
+ headers,
+ service: data.service,
+ template: data.payloadTemplate,
+ customFields: normalizedCustomFields,
+ mention: data.mention,
+ })
+ : await props.onAdd({
+ name: data.name,
+ url: data.url,
+ method: data.method,
+ headers,
+ enabled: data.enabled,
+ service: data.service,
+ template: data.payloadTemplate,
+ customFields: normalizedCustomFields,
+ mention: data.mention,
+ tagFilter: data.tagFilter ?? [],
+ tagFilterMode: data.tagFilterMode === 'any' ? 'any' : 'all',
+ minimumSeverity:
+ data.minimumSeverity === 'critical' || data.minimumSeverity === 'warning'
+ ? data.minimumSeverity
+ : 'all',
+ });
+ if (accepted === true) resetForm();
+ else setSaveError(failureMessage);
+ } catch {
+ // Callback/provider text can contain submitted destination details.
+ setSaveError(failureMessage);
+ } finally {
+ setSaving(false);
}
-
- props.onAdd({
- name: data.name,
- url: data.url,
- method: data.method,
- headers,
- enabled: data.enabled,
- service: data.service,
- template: data.payloadTemplate,
- customFields: normalizedCustomFields,
- mention: data.mention,
- tagFilter: data.tagFilter ?? [],
- tagFilterMode: data.tagFilterMode === 'any' ? 'any' : 'all',
- minimumSeverity:
- data.minimumSeverity === 'critical' || data.minimumSeverity === 'warning'
- ? data.minimumSeverity
- : 'all',
- });
- resetForm();
};
const testWebhookForm = () => {
@@ -336,6 +358,8 @@ export function useWebhookConfigState(props: WebhookConfigProps): WebhookConfigS
return {
adding,
+ saving,
+ saveError,
editingId,
formData,
templates,
diff --git a/frontend-modern/src/features/alerts/AlertWebhookDestinationsSection.tsx b/frontend-modern/src/features/alerts/AlertWebhookDestinationsSection.tsx
index 11afd982c6..e37b413d37 100644
--- a/frontend-modern/src/features/alerts/AlertWebhookDestinationsSection.tsx
+++ b/frontend-modern/src/features/alerts/AlertWebhookDestinationsSection.tsx
@@ -1,4 +1,4 @@
-import { WebhookConfig } from '@/components/Alerts/WebhookConfig';
+import { WebhookConfig, type WebhookConfigProps } from '@/components/Alerts/WebhookConfig';
import { SettingsPanel } from '@/components/shared/SettingsPanel';
import type { Webhook } from '@/api/notifications';
import {
@@ -8,8 +8,8 @@ import {
interface AlertWebhookDestinationsSectionProps {
webhooks: Webhook[];
- addWebhook: (webhook: Omit<Webhook, 'id'>) => void;
- updateWebhook: (webhook: Webhook) => void;
+ addWebhook: WebhookConfigProps['onAdd'];
+ updateWebhook: WebhookConfigProps['onUpdate'];
deleteWebhook: (id: string) => void;
testWebhook: (webhookId: string, webhookData?: Omit<Webhook, 'id'>) => void;
testingWebhook: string | null;
diff --git a/frontend-modern/src/features/alerts/useAlertWebhookDestinationsState.ts b/frontend-modern/src/features/alerts/useAlertWebhookDestinationsState.ts
index 68bbae0707..bf0689e218 100644
--- a/frontend-modern/src/features/alerts/useAlertWebhookDestinationsState.ts
+++ b/frontend-modern/src/features/alerts/useAlertWebhookDestinationsState.ts
@@ -81,11 +81,13 @@ export function useAlertWebhookDestinationsState(
const created = await NotificationsAPI.createWebhook(webhook);
setWebhooks((current) => [...current, normalizeWebhook(created)]);
notificationStore.success(getAlertWebhookMutationSuccess('add'));
+ return true;
} catch (error) {
logger.error('Failed to add webhook:', error);
notificationStore.error(
error instanceof Error ? error.message : getAlertWebhookMutationFailure('add'),
);
+ return false;
}
};
@@ -96,11 +98,13 @@ export function useAlertWebhookDestinationsState(
current.map((entry) => (entry.id === webhook.id ? normalizeWebhook(updated) : entry)),
);
notificationStore.success(getAlertWebhookMutationSuccess('update'));
+ return true;
} catch (error) {
logger.error('Failed to update webhook:', error);
notificationStore.error(
error instanceof Error ? error.message : getAlertWebhookMutationFailure('update'),
);
+ return false;
}
};