Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): track plugin actions in flight per plugin

Yudhi Armyndharisd183db46eb60
diff --git a/dashboard/src/pages/Plugins.test.ts b/dashboard/src/pages/Plugins.test.ts
index 3a2f899a6..6c2a2d383 100644
--- a/dashboard/src/pages/Plugins.test.ts
+++ b/dashboard/src/pages/Plugins.test.ts
@@ -43,6 +43,9 @@ let putGate: Promise<void> | undefined;
let pluginOverride: Record<string, unknown> = {};
let catalogReply: () => Promise<Response> = () => Promise.resolve(jsonResponse([]));
let catalogReads = 0;
+// Further installed plugins listed after PLUGIN, and a gate a POST /disable waits for before answering.
+let extraPlugins: Record<string, unknown>[] = [];
+let disableGate: Promise<void> | undefined;
function installFetchStub(): void {
globalThis.fetch = ((input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
@@ -50,8 +53,12 @@ function installFetchStub(): void {
const path = url.replace(/^https?:\/\/[^/]+/, '');
const method = init?.method ?? 'GET';
if (method === 'GET' && path === '/api/plugins') {
- return Promise.resolve(jsonResponse([{ ...PLUGIN, sessionConfig, ...pluginOverride }]));
+ return Promise.resolve(jsonResponse([{ ...PLUGIN, sessionConfig, ...pluginOverride }, ...extraPlugins]));
}
+ if (method === 'POST' && path.endsWith('/disable')) {
+ return (disableGate ?? Promise.resolve()).then(() => jsonResponse({ success: true, message: 'Disabled' }));
+ }
+ if (method === 'GET' && path.endsWith('/health')) return Promise.resolve(jsonResponse({ healthy: true }));
if (method === 'GET' && path === '/api/plugins/catalog') {
catalogReads++;
return catalogReply();
@@ -114,6 +121,8 @@ afterEach(() => {
pluginOverride = {};
catalogReply = () => Promise.resolve(jsonResponse([]));
catalogReads = 0;
+ extraPlugins = [];
+ disableGate = undefined;
rtl.cleanup();
queryClient?.clear();
queryClient = undefined;
@@ -266,3 +275,23 @@ test('a fractional value in a bounded number field does not block the override s
await waitFor(() => assert.equal(putBodies.length, 1));
assert.deepEqual(putBodies, [{ config: { threshold: 0.5 } }]);
});
+
+test("another plugin's action settling first keeps a pending plugin's buttons disabled", async () => {
+ const { screen, fireEvent, within } = rtl;
+ extraPlugins = [{ ...PLUGIN, id: 'echo', name: 'Echo', configSchema: undefined, sessionScoped: false }];
+ let releaseDisable!: () => void;
+ disableGate = new Promise(resolve => (releaseDisable = resolve));
+ renderPlugins();
+ await rtl.waitFor(() => assert.equal(document.querySelectorAll('.plugin-card').length, 2));
+ const [greeter, echo] = Array.from(document.querySelectorAll<HTMLElement>('.plugin-card'));
+ const greeterToggle = within(greeter).getByRole<HTMLButtonElement>('button', { name: 'Disable' });
+
+ fireEvent.click(greeterToggle);
+ assert.equal(greeterToggle.disabled, true);
+ fireEvent.click(within(echo).getByTitle('Health Check'));
+ await screen.findByText('Health Check Passed');
+ assert.equal(greeterToggle.disabled, true);
+ assert.equal(within(greeter).getByTitle<HTMLButtonElement>('Uninstall').disabled, true);
+
+ releaseDisable();
+});
diff --git a/dashboard/src/pages/Plugins.tsx b/dashboard/src/pages/Plugins.tsx
index f33dcc547..dacf38b74 100644
--- a/dashboard/src/pages/Plugins.tsx
+++ b/dashboard/src/pages/Plugins.tsx
@@ -594,7 +594,16 @@ export default function Plugins() {
const { data: plugins = [], isLoading: loadingPlugins, error: queryError } = usePluginsQuery();
const loading = loadingPlugins;
const error = queryError instanceof Error ? queryError.message : null;
- const [actionLoading, setActionLoading] = useState<string | null>(null);
+ // Ids of plugins with a lifecycle action in flight. One per plugin, so another plugin's action
+ // settling first does not re-enable this plugin's buttons while its own request is pending.
+ const [actionLoading, setActionLoading] = useState<ReadonlySet<string>>(new Set());
+ const startAction = (id: string) => setActionLoading(s => new Set(s).add(id));
+ const endAction = (id: string) =>
+ setActionLoading(s => {
+ const next = new Set(s);
+ next.delete(id);
+ return next;
+ });
const schemaFormRef = useRef<HTMLFormElement>(null);
const [showConfigModal, setShowConfigModal] = useState(false);
@@ -638,7 +647,7 @@ export default function Plugins() {
return;
}
}
- setActionLoading(plugin.id);
+ startAction(plugin.id);
try {
// Both endpoints report lifecycle failures as 200 + {success:false} — surface them instead of
// silently refetching. The card flips to ERROR either way, but without the message the operator
@@ -658,12 +667,12 @@ export default function Plugins() {
err instanceof Error ? err.message : t('plugins.toasts.errorDefault'),
);
} finally {
- setActionLoading(null);
+ endAction(plugin.id);
}
};
const handleHealthCheck = async (pluginId: string) => {
- setActionLoading(pluginId);
+ startAction(pluginId);
try {
const result = await pluginsApi.healthCheck(pluginId);
if (result.healthy) {
@@ -674,7 +683,7 @@ export default function Plugins() {
} catch (err) {
toast.error(t('plugins.toasts.healthError'), err instanceof Error ? err.message : t('common.unknownError'));
} finally {
- setActionLoading(null);
+ endAction(pluginId);
}
};
@@ -822,7 +831,7 @@ export default function Plugins() {
const handleUninstall = async (plugin: Plugin) => {
if (!window.confirm(t('plugins.uninstallConfirm', { name: localizePlugin(plugin, i18n.language).name }))) return;
- setActionLoading(plugin.id);
+ startAction(plugin.id);
try {
await pluginsApi.uninstall(plugin.id);
refetchAll();
@@ -831,7 +840,7 @@ export default function Plugins() {
} catch (err) {
toast.error(t('plugins.toasts.uninstallFailed', 'Uninstall failed'), err instanceof Error ? err.message : '');
} finally {
- setActionLoading(null);
+ endAction(plugin.id);
}
};
@@ -918,7 +927,7 @@ export default function Plugins() {
<div className="plugins-grid">
{visiblePlugins.map(plugin => {
const TypeIcon = pluginTypeIcons[plugin.type as PluginType] || Puzzle;
- const isLoading = actionLoading === plugin.id;
+ const isLoading = actionLoading.has(plugin.id);
const lz = localizePlugin(plugin, i18n.language);
return (