Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): do not call the plugin list empty after a failed read
Yudhi Armyndharis0943b6dd7ce2
diff --git a/dashboard/src/pages/Plugins.test.ts b/dashboard/src/pages/Plugins.test.tsindex 318469a8d..4b57cecbf 100644--- a/dashboard/src/pages/Plugins.test.ts+++ b/dashboard/src/pages/Plugins.test.ts@@ -46,6 +46,8 @@ 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;+// Whether GET /api/plugins answers with a server error, as it does while the plugin registry is unavailable.+let pluginListFails = false;function installFetchStub(): void {globalThis.fetch = ((input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {@@ -53,6 +55,7 @@ function installFetchStub(): void {const path = url.replace(/^https?:\/\/[^/]+/, '');const method = init?.method ?? 'GET';if (method === 'GET' && path === '/api/plugins') {+ if (pluginListFails) return Promise.resolve(jsonResponse({ message: 'plugin registry unavailable' }, 500));return Promise.resolve(jsonResponse([{ ...PLUGIN, sessionConfig, ...pluginOverride }, ...extraPlugins]));}if (method === 'POST' && path.endsWith('/disable')) {@@ -127,6 +130,7 @@ afterEach(() => {catalogReads = 0;extraPlugins = [];disableGate = undefined;+ pluginListFails = false;rtl.cleanup();queryClient?.clear();queryClient = undefined;@@ -154,6 +158,34 @@ async function openSessionOverride(sessionLabel: string): Promise<void> {fireEvent.change(select, { target: { value: SESSION.id } });}+// A failed read says nothing about what is installed: the banner is the only message, and the page must not+// count zero plugins or tell the operator to install one.+test('a failed first plugin read shows the error, not an empty install base', async () => {+ const { screen } = rtl;+ pluginListFails = true;+ renderPlugins();++ await screen.findByText('plugin registry unavailable');+ assert.equal(screen.queryByText('No plugins installed') === null, true, 'a failed read claimed nothing is installed');+ assert.equal(screen.queryByText('None enabled yet') === null, true, 'a failed read claimed nothing is enabled');+ const counts = Array.from(document.querySelectorAll('.rail-stat-num')).map(node => node.textContent);+ assert.deepEqual(counts, ['-', '-'], 'the rail counted plugins it could not read');+});++test('a failed refetch keeps the installed plugins and their counts', async () => {+ const { screen, act } = rtl;+ renderPlugins();+ await screen.findByTitle('Configure');++ pluginListFails = true;+ await act(() => queryClient!.refetchQueries({ queryKey: ['plugins'] }));++ await screen.findByText('plugin registry unavailable');+ assert.ok(screen.queryByTitle('Configure'), 'the failed refetch dropped the installed plugin');+ const counts = Array.from(document.querySelectorAll('.rail-stat-num')).map(node => node.textContent);+ assert.deepEqual(counts, ['1', '1']);+});+test('a per-session override the server rejects reports the failure, not "Saved"', async () => {const { screen, fireEvent } = rtl;await openSessionOverride('Main');diff --git a/dashboard/src/pages/Plugins.tsx b/dashboard/src/pages/Plugins.tsxindex 626348e46..d5bd5e213 100644--- a/dashboard/src/pages/Plugins.tsx+++ b/dashboard/src/pages/Plugins.tsx@@ -592,7 +592,13 @@ export default function Plugins() {useDocumentTitle(t('plugins.title'));const toast = useToast();const queryClient = useQueryClient();- const { data: plugins = [], isLoading: loadingPlugins, error: queryError } = usePluginsQuery();+ const {+ data: plugins = [],+ isLoading: loadingPlugins,+ error: queryError,+ // A read that never produced a list says nothing about what is installed. A failed refetch keeps its data.+ isLoadingError: neverLoaded,+ } = usePluginsQuery();const loading = loadingPlugins;const error = queryError instanceof Error ? queryError.message : null;// Ids of plugins with a lifecycle action in flight. One per plugin, so another plugin's action@@ -897,18 +903,18 @@ export default function Plugins() {<aside className="plugins-rail"><div className="rail-stats"><div className="rail-stat">- <span className="rail-stat-num">{enabledCount}</span>+ <span className="rail-stat-num">{neverLoaded ? '-' : enabledCount}</span><span className="rail-stat-label">{t('plugins.rail.enabled', 'enabled')}</span></div><div className="rail-stat">- <span className="rail-stat-num">{visiblePlugins.length}</span>+ <span className="rail-stat-num">{neverLoaded ? '-' : visiblePlugins.length}</span><span className="rail-stat-label">{t('plugins.rail.installed', 'installed')}</span></div></div><div className="rail-section"><p className="rail-label">{t('plugins.rail.active', 'Active plugins')}</p>- {activePlugins.length === 0 ? (+ {neverLoaded ? null : activePlugins.length === 0 ? (<p className="rail-empty">{t('plugins.rail.none', 'None enabled yet')}</p>) : (<ul className="rail-active-list">@@ -1051,7 +1057,7 @@ export default function Plugins() {</main></div>- {visiblePlugins.length === 0 && !loading && (+ {visiblePlugins.length === 0 && !loading && !neverLoaded && (<div className="empty-state"><Puzzle size={64} /><h3>{t('plugins.empty.title')}</h3>