Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): do not call the sessions list empty after a failed read

Yudhi Armyndharis5337508ea4bc
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.ts
index 8538ca5e8..45aa4f8b8 100644
--- a/dashboard/src/pages/Sessions.test.ts
+++ b/dashboard/src/pages/Sessions.test.ts
@@ -97,6 +97,7 @@ function resetFetchCalls(): void {
sessionProxy = { enabled: false, proxyType: null, proxyHost: null, hasCredentials: false };
proxyGetFails = false;
sessionListFailures = 0;
+ sessionListEmpty = false;
distinctFailureMessages = false;
startFailure = null;
startGate = null;
@@ -127,6 +128,8 @@ let configPatchFails = false;
let proxyGetFails = false;
// How many of the next GET /api/sessions reads fail, as they do while the gateway is down.
let sessionListFailures = 0;
+// Whether GET /api/sessions answers with no sessions at all.
+let sessionListEmpty = false;
// Whether each failed read carries its own message, as a 502, a 504 and a dropped connection do.
let distinctFailureMessages = false;
// When set, POST .../start answers with this error, first applying `leaves` to the session's row: the
@@ -190,6 +193,7 @@ function installFetchStub(): void {
: 'gateway unavailable';
return Promise.resolve(jsonResponse({ message }, 503));
}
+ if (sessionListEmpty) return Promise.resolve(jsonResponse([]));
if (listGate) {
const until = listGate;
listGate = null;
@@ -490,6 +494,37 @@ test('a refused and then successful create leave a failed list read in the banne
assert.ok(screen.queryByText('gateway unavailable'), 'the create cleared the failed read banner');
});
+// A failed read says nothing about how many sessions there are: the banner is the only message, and the
+// page must not tell the operator there are none and invite them to create one.
+test('a failed first list read shows the error, not the empty state', async () => {
+ const { screen } = rtl;
+ resetFetchCalls();
+ sessionListFailures = 1;
+ // No connect, so the recovery effect does not re-read the list behind the test's back.
+ holdConnect();
+ renderSessions();
+
+ await screen.findByText('gateway unavailable');
+ assert.equal(screen.queryByText('No sessions found') === null, true, 'a failed read claimed there are no sessions');
+});
+
+test('an empty list shows the empty state, and a refused create does not take it away', async () => {
+ const { screen, fireEvent, within } = rtl;
+ resetFetchCalls();
+ sessionListEmpty = true;
+ createFailure = { status: 409, message: 'Session name already in use' };
+ renderSessions();
+
+ await screen.findByText('No sessions found');
+ fireEvent.click(screen.getByRole('button', { name: 'New Session' }));
+ const dialog = await screen.findByRole('dialog');
+ fireEvent.change(within(dialog).getByPlaceholderText('e.g., marketing-bot'), { target: { value: 'retry-bot' } });
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Create' }));
+ await screen.findAllByText('Session name already in use');
+
+ assert.equal(screen.queryByText('No sessions found') === null, false, 'the refused create hid the empty state');
+});
+
test('Enter in the name field follows the same gate as the Create button', async () => {
const { screen, fireEvent, waitFor, within } = rtl;
resetFetchCalls();
diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsx
index 963c07b42..02ae8e33f 100644
--- a/dashboard/src/pages/Sessions.tsx
+++ b/dashboard/src/pages/Sessions.tsx
@@ -82,6 +82,8 @@ export function Sessions() {
// The full-page spinner belongs to the FIRST load only (see fetchSessions).
const initialLoadDone = useRef(false);
const [error, setError] = useState<string | null>(null);
+ // Whether the last list read failed. `error` also carries a refused create, which says nothing about the list.
+ const [listFailed, setListFailed] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [statusFilter, setStatusFilter] = useState('all');
// Only the id: the detail modal renders the row as it is in `sessions` now, so a status push or a
@@ -171,6 +173,7 @@ export function Sessions() {
// The list is current again, so an error left by an earlier failed read (or a create, whose toast
// already reported it) no longer describes the page, and the recovery retry is available again.
setError(null);
+ setListFailed(false);
retriedThisConnect.current = false;
// Keep the shared React Query cache (read by the Dashboard via useSessionsQuery /
// useSessionStatsQuery) in sync after this page's mutations reload local state — otherwise the
@@ -186,6 +189,7 @@ export function Sessions() {
if (request < listApplied.current) return sessionsRef.current;
listReadFailed.current = true;
setError(err instanceof Error ? err.message : t('sessions.create.errorDefault'));
+ setListFailed(true);
return [];
} finally {
initialLoadDone.current = true;
@@ -641,6 +645,8 @@ export function Sessions() {
};
const filteredSessions = filterSessions(sessions, searchQuery, statusFilter);
+ // A failed read says nothing about how many sessions there are: with none held, the banner is the only message.
+ const listUnknown = listFailed && sessions.length === 0;
const existingSessionNames = sessions.map(s => s.name);
// Empty is a disabled button, not a message: the form stays quiet until the user types something.
const nameIssues = newSessionName ? sessionNameIssues(newSessionName, existingSessionNames) : [];
@@ -1229,7 +1235,7 @@ export function Sessions() {
)}
<div className="sessions-grid">
- {filteredSessions.length === 0 ? (
+ {filteredSessions.length === 0 && !listUnknown ? (
<div className="empty-state">
<QrCode size={48} />
<h3>{t('sessions.empty.title')}</h3>