Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): let a cleared plugin config field clear the stored value

Yudhi Armyndharis8a9feb8725bd
diff --git a/dashboard/src/pages/Plugins.tsx b/dashboard/src/pages/Plugins.tsx
index 77e00fbc6..f9be2a6a2 100644
--- a/dashboard/src/pages/Plugins.tsx
+++ b/dashboard/src/pages/Plugins.tsx
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { localizePlugin } from '../utils/localizePlugin';
import { configUiSafeConfig, missingRequiredConfig, sparseSessionOverride } from '../utils/pluginConfigRules';
-import { coerceFieldInput, emptyForField } from '../utils/pluginConfigForm';
+import { coerceFieldInput, emptyForField, fillClearedFields } from '../utils/pluginConfigForm';
import { useQueryClient } from '@tanstack/react-query';
import {
Puzzle,
@@ -665,7 +665,10 @@ export default function Plugins() {
try {
// 200 + {success:false} is how a rejected save arrives; without this the modal closed on a
// "Saved!" toast and the operator's edit was silently gone on the next open.
- const res = await pluginsApi.updateConfig(configPlugin.id, schemaConfig);
+ const res = await pluginsApi.updateConfig(
+ configPlugin.id,
+ fillClearedFields(schemaConfig, configPlugin.config, configPlugin.configSchema?.properties ?? {}),
+ );
if (!res.success) throw new Error(res.message);
void queryClient.invalidateQueries({ queryKey: queryKeys.plugins });
toast.success(t('plugins.toasts.savedTitle'), t('plugins.toasts.savedDesc'));
diff --git a/dashboard/src/utils/pluginConfigForm.test.ts b/dashboard/src/utils/pluginConfigForm.test.ts
index 403a5e0a3..1e5b36962 100644
--- a/dashboard/src/utils/pluginConfigForm.test.ts
+++ b/dashboard/src/utils/pluginConfigForm.test.ts
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { coerceFieldInput, emptyForField } from './pluginConfigForm.ts';
+import { coerceFieldInput, emptyForField, fillClearedFields } from './pluginConfigForm.ts';
import type { PluginConfigField } from '../services/api';
const num: PluginConfigField = { type: 'number' };
@@ -26,3 +26,23 @@ test('emptyForField: a number field seeds to undefined, not an empty string', ()
test('emptyForField: a string field seeds to an empty string', () => {
assert.equal(emptyForField(str), '');
});
+
+// The save merges over the stored config and JSON drops an undefined key, so simply omitting a
+// cleared field would keep its old value.
+test('fillClearedFields: a cleared field saves its default, or null when it had a value and has none', () => {
+ const properties: Record<string, PluginConfigField> = {
+ cooldownSec: { type: 'number', default: 60 },
+ timeoutMs: { type: 'number' },
+ retries: { type: 'number' },
+ name: str,
+ };
+ const values = { cooldownSec: undefined, timeoutMs: undefined, retries: undefined, name: 'bot' };
+ const stored = { cooldownSec: 30, timeoutMs: 5000, name: 'bot' };
+
+ assert.deepEqual(fillClearedFields(values, stored, properties), {
+ cooldownSec: 60,
+ timeoutMs: null,
+ retries: undefined, // never stored: nothing to clear, so nothing is written
+ name: 'bot',
+ });
+});
diff --git a/dashboard/src/utils/pluginConfigForm.ts b/dashboard/src/utils/pluginConfigForm.ts
index 8d423aef5..7fc0252aa 100644
--- a/dashboard/src/utils/pluginConfigForm.ts
+++ b/dashboard/src/utils/pluginConfigForm.ts
@@ -31,3 +31,23 @@ export function coerceFieldInput(field: PluginConfigField, raw: string): unknown
if (field.type === 'number') return raw === '' ? undefined : Number(raw);
return raw;
}
+
+/**
+ * Fill each cleared top-level field for the save. The gateway merges the PUT body over the stored
+ * config and JSON drops an undefined key, so an omitted field keeps its old value: send the field's
+ * default instead, or null when it has none and a value is stored. A field that was never stored
+ * stays omitted.
+ */
+export function fillClearedFields(
+ values: Record<string, unknown>,
+ stored: Record<string, unknown>,
+ properties: Record<string, PluginConfigField>,
+): Record<string, unknown> {
+ const out = { ...values };
+ for (const [key, field] of Object.entries(properties)) {
+ if (out[key] !== undefined) continue;
+ if (field.default !== undefined) out[key] = field.default;
+ else if (stored[key] != null) out[key] = null;
+ }
+ return out;
+}