Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show a failed catalog prefetch in the Catalog tab
Yudhi Armyndharisee87e5436952
diff --git a/dashboard/src/pages/Plugins.test.ts b/dashboard/src/pages/Plugins.test.tsindex d25d71904..a45349be3 100644--- a/dashboard/src/pages/Plugins.test.ts+++ b/dashboard/src/pages/Plugins.test.ts@@ -39,6 +39,10 @@ let putReply: { success: boolean; message?: string } = { success: false, messagelet putBodies: unknown[] = [];// When set, a PUT waits for it before answering, so a test can act while the request is in flight.let putGate: Promise<void> | undefined;+// Fields that replace the installed plugin's, and what the catalog route answers (and how often it was read).+let pluginOverride: Record<string, unknown> = {};+let catalogReply: () => Promise<Response> = () => Promise.resolve(jsonResponse([]));+let catalogReads = 0;function installFetchStub(): void {globalThis.fetch = ((input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {@@ -46,7 +50,14 @@ 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 }]));+ return Promise.resolve(jsonResponse([{ ...PLUGIN, sessionConfig, ...pluginOverride }]));+ }+ if (method === 'GET' && path === '/api/plugins/catalog') {+ catalogReads++;+ return catalogReply();+ }+ if (method === 'DELETE' && path === `/api/plugins/${PLUGIN.id}`) {+ return Promise.resolve(jsonResponse({ success: true, message: 'Uninstalled' }));}if (method === 'GET' && path === '/api/sessions') return Promise.resolve(jsonResponse([SESSION, SESSION_2]));const put = method === 'PUT' ? path.match(new RegExp(`^/api/plugins/${PLUGIN.id}/config/([^/]+)$`)) : null;@@ -99,13 +110,15 @@ afterEach(() => {putReply = { success: false, message: REJECTION };putBodies = [];putGate = undefined;+ pluginOverride = {};+ catalogReply = () => Promise.resolve(jsonResponse([]));+ catalogReads = 0;rtl.cleanup();queryClient?.clear();queryClient = undefined;});-async function openSessionOverride(sessionLabel: string): Promise<void> {- const { screen, fireEvent, findByText } = rtl;+function renderPlugins(): void {queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 1_000 } } });rtl.render(createElement(@@ -114,6 +127,11 @@ async function openSessionOverride(sessionLabel: string): Promise<void> {createElement(ToastProvider, null, createElement(Plugins)),),);+}++async function openSessionOverride(sessionLabel: string): Promise<void> {+ const { screen, fireEvent, findByText } = rtl;+ renderPlugins();fireEvent.click(await screen.findByTitle('Configure'));fireEvent.click(await screen.findByRole('button', { name: 'Sessions' }));@@ -170,3 +188,20 @@ test('a clear that answers after the operator switched sessions leaves the new sawait screen.findByText('Configuration Saved');assert.equal(screen.getByLabelText<HTMLInputElement>('Greeting').value, 'hey');});++test('a catalog prefetch that fails after the Catalog tab opened shows the error with a retry', async () => {+ const { screen, fireEvent } = rtl;+ let failCatalog!: () => void;+ catalogReply = () =>+ new Promise(resolve => (failCatalog = () => resolve(jsonResponse({ message: 'catalog unreachable' }, 502))));+ renderPlugins();+ await screen.findByTitle('Configure');+ fireEvent.click(screen.getByRole('button', { name: 'Install plugin' }));+ fireEvent.click(document.querySelectorAll<HTMLButtonElement>('.install-tab')[1]);+ await screen.findByText(/Install directly from the OpenWA plugin catalog/);++ failCatalog();+ const message = await screen.findByText(/catalog unreachable/);+ assert.ok(rtl.within(message).getByRole('button', { name: 'Refresh' }));+ assert.equal(screen.queryByText('No plugins in the catalog.'), null);+});diff --git a/dashboard/src/pages/Plugins.tsx b/dashboard/src/pages/Plugins.tsxindex 05b528ed9..983fdd379 100644--- a/dashboard/src/pages/Plugins.tsx+++ b/dashboard/src/pages/Plugins.tsx@@ -735,34 +735,35 @@ export default function Plugins() {}};- const loadCatalog = async (silent = false) => {+ const loadCatalog = async () => {setCatalogLoading(true);setCatalogError(null);try {setCatalog(await pluginsApi.catalog());} catch (err) {- // Silent mode is the page-mount prefetch that powers the update chips: a catalog that- // cannot be reached just means no chips, so the failure is not surfaced here — the- // drawer's own lazy-load effect (which skips while an error is set) retries loudly- // when the user actually opens the Catalog tab.- if (!silent) setCatalogError(err instanceof Error ? err.message : String(err));+ // The error renders only inside the Catalog tab, next to a Refresh button, so a failed+ // page-mount prefetch stays quiet on the page itself (it just means no update chips). It+ // must still be recorded: a tab opened while that prefetch was in flight would otherwise+ // settle on "No plugins in the catalog." with no way to retry.+ setCatalogError(err instanceof Error ? err.message : String(err));} finally {setCatalogLoading(false);}};- // Lazy-load the catalog the first time the Catalog tab is opened.+ // Load the catalog when the Catalog tab opens with nothing to show: the first time, or again+ // after an earlier load failed.useEffect(() => {- if (showInstallModal && installMode === 'catalog' && catalog.length === 0 && !catalogLoading && !catalogError) {+ if (showInstallModal && installMode === 'catalog' && catalog.length === 0 && !catalogLoading) {void loadCatalog();}// eslint-disable-next-line react-hooks/exhaustive-deps}, [showInstallModal, installMode]);// Prefetch once on mount so installed-plugin cards can flag newer catalog versions without the- // user having to open the Install drawer first. Silent: an unreachable catalog hides the chips.+ // user having to open the Install drawer first. An unreachable catalog just hides the chips.useEffect(() => {- void loadCatalog(true);+ void loadCatalog();}, []);// Catalog entries with a strictly newer version than the installed one, keyed by plugin id —