Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): say when the Unknown filter could not be decided
Yudhi Armyndharis719bc15e2e12
diff --git a/dashboard/src/components/chats/ChatSidebar.tsx b/dashboard/src/components/chats/ChatSidebar.tsxindex fff9c2755..47c5620b4 100644--- a/dashboard/src/components/chats/ChatSidebar.tsx+++ b/dashboard/src/components/chats/ChatSidebar.tsx@@ -39,6 +39,8 @@ interface ChatSidebarProps {newChatPanel?: ReactNode;chatsTab: {loading: boolean;+ /** Set when the filter in use cannot be decided because the address book could not be read. */+ filterError?: { retrying: boolean; onRetry: () => void };chats: Chat[];filter: ChatListFilter;onFilterChange: (filter: ChatListFilter) => void;@@ -271,6 +273,22 @@ function ChatSidebar({<Loader2 className="animate-spin" size={24} /><span>{t('chats.loadingChats')}</span></div>+ ) : chatsTab.filterError ? (+ <div className="chats-list-empty">+ <AlertCircle size={24} className="text-warn" />+ <span>{t('chats.newChat.contactsError')}</span>+ {/* aria-disabled, not disabled, so the keyboard stays on the button while the read runs. */}+ <button+ type="button"+ className="btn-secondary"+ aria-disabled={chatsTab.filterError.retrying}+ onClick={() => {+ if (!chatsTab.filterError?.retrying) chatsTab.filterError?.onRetry();+ }}+ >+ {t('common.retry')}+ </button>+ </div>) : chatsTab.chats.length === 0 ? (<div className="chats-list-empty"><span>diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.tsindex 94a562781..d71be32b4 100644--- a/dashboard/src/pages/Chats.features.test.ts+++ b/dashboard/src/pages/Chats.features.test.ts@@ -2305,6 +2305,50 @@ test('the Unknown filter waits for the address book instead of listing nothing',assert.ok(!screen.queryByText('Alice'), 'a saved contact is listed as unknown');});+test('the Unknown filter says the address book could not be read, and Retry reads it again', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ listExtra = true;+ failContacts = true;+ renderPage();+ await screen.findByText('Bobby');+ fireEvent.click(screen.getByRole('button', { name: 'Unknown' }));++ await screen.findByText('Could not load contacts');+ assert.ok(!screen.queryByText('No chats match this filter'), 'a failed read was reported as no matching chat');+ assert.equal(contactReads().length, 1);++ // The retry keeps the keyboard where it was while the read runs, and says it is busy.+ failContacts = false;+ const release = hold('contacts');+ const retry = screen.getByRole('button', { name: 'Retry' });+ retry.focus();+ fireEvent.click(retry);+ await waitFor(() => assert.equal(contactReads().length, 2));+ assert.equal(document.activeElement === retry, true, `focus is on "${focusedName()}", not on Retry`);+ assert.equal(retry.getAttribute('aria-disabled'), 'true');++ release();+ await screen.findByText('Bobby');+ assert.ok(!screen.queryByText('Could not load contacts'), 'the failed state stayed after the read succeeded');+ assert.ok(!screen.queryByText('Alice'), 'a saved contact is listed as unknown');+});++test('a later address book read that fails keeps the Unknown list it already has', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ listExtra = true;+ renderPage();+ await screen.findByText('Bobby');+ fireEvent.click(screen.getByRole('button', { name: 'Unknown' }));+ await screen.findByText('Bobby');++ failContacts = true;+ await queryClients[0].invalidateQueries({ queryKey: ['contacts', SESSION.id] });+ await waitFor(() => assert.equal(contactReads().length, 2));+ await settle();+ assert.ok(screen.getByText('Bobby'), 'the list it had was dropped');+ assert.ok(!screen.queryByText('Could not load contacts'), 'a failed refresh hid a list that was still good');+});+test('the address book is not read again when the window regains focus, unless the last read failed', async () => {const { screen, fireEvent, act, waitFor } = rtl;renderPage();diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex 6808dbfaf..5bafc6338 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -1250,6 +1250,10 @@ export function Chats() {refetchOnWindowFocus: query => query.state.status === 'error',});const savedContactKeys = useMemo(() => savedContactKeySet(contactsQuery.data), [contactsQuery.data]);+ // A read that failed with nothing earlier to go by. The retry's own read is pending again, so the failure is+ // told by the query's error count rather than its status, which keeps the Retry button on screen throughout.+ const contactsFailed =+ chatFilter === 'unknown' && contactsQuery.data === undefined && contactsQuery.errorUpdateCount > 0;const searching = searchQuery.trim() !== '';const searchedChats = filterChats(chats, searchQuery);@@ -1689,9 +1693,14 @@ export function Chats() {}formatChatTime={formatChatTime}chatsTab={{- // Unknown is decided by the address book: until it loads the list would claim no chat matches.+ // Unknown is decided by the address book: until it loads the list would claim no chat matches, and+ // when it cannot be read the list says so instead.loading:- loadingChats || (chatFilter === 'unknown' && Boolean(selectedSessionId) && contactsQuery.isPending),+ loadingChats ||+ (chatFilter === 'unknown' && Boolean(selectedSessionId) && contactsQuery.isPending && !contactsFailed),+ filterError: contactsFailed+ ? { retrying: contactsQuery.isFetching, onRetry: () => void contactsQuery.refetch() }+ : undefined,chats: filteredChats,activeChatId: activeChat?.id,pictures: listPics.data,