Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): reach a message's actions from the keyboard
Yudhi Armyndharis0d921511b9ca
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c41c61f5e..ff8268633 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Stop a request left over from before logout from reloading the dashboard login form.- Stop a dashboard Logs export from downloading rows after sign-out when its last page was throttled.- Stop reopening a just-saved dashboard template from loading its old values, which a second save wrote back.+- Reach a chat message's reply, react and delete actions from the keyboard in the dashboard: the thread is one tab stop, the arrow keys move between messages, and the actions show while focus is inside the bubble.- Stop an operator ingress dead-letter redrive at its next row on shutdown, leaving the rows it did not reach unchanged.- Run a plugin's `onDisable` once when shutdown, uninstall or an update overlaps a disable already in progress.- Answer `503` and keep the previous version when shutdown begins before an update of a plugin the operator switched on has applied.diff --git a/dashboard/src/components/chats/ChatThread.test.ts b/dashboard/src/components/chats/ChatThread.test.tsindex 89456fa8c..de75eec13 100644--- a/dashboard/src/components/chats/ChatThread.test.ts+++ b/dashboard/src/components/chats/ChatThread.test.ts@@ -396,3 +396,55 @@ test('an archived sticker previews as an image and an archived voice note as audURL.revokeObjectURL = revokeOriginal;}});++// The message actions appear on hover, so a keyboard user reaches them through the bubble: one tab stop+// for the thread (the focused message, else the newest) and the arrow keys between messages.+test('the thread is one tab stop and the arrow keys move between messages that carry actions', () => {+ const second: ChatMessageView = {+ ...PROMPT,+ id: 'db-2',+ waMessageId: 'wamid.2',+ body: 'Second',+ metadata: undefined,+ };+ const noActions: ChatMessageView = {+ ...PROMPT,+ id: 'db-3',+ waMessageId: undefined,+ body: 'Third',+ direction: 'outgoing',+ status: 'pending',+ metadata: undefined,+ };+ const { container } = renderThread('operator', [PROMPT, second, noActions]);+ const stops = (): Array<string | null> =>+ [...container.querySelectorAll<HTMLElement>('[data-roving-message]')].map(el => el.getAttribute('tabindex'));++ // The bubble without a WhatsApp id offers no action, so it is no stop at all.+ assert.equal(container.querySelectorAll('[data-roving-message]').length, 2);+ // Nothing focused yet: the newest message that carries actions holds the tab stop.+ assert.deepEqual(stops(), ['-1', '0']);++ const bubbles = container.querySelectorAll<HTMLElement>('[data-roving-message]');+ bubbles[1].focus();+ rtl.fireEvent.keyDown(bubbles[1], { key: 'ArrowUp' });+ assert.equal(document.activeElement, bubbles[0]);+ assert.deepEqual(stops(), ['0', '-1']);++ rtl.fireEvent.keyDown(bubbles[0], { key: 'ArrowDown' });+ assert.equal(document.activeElement, bubbles[1]);+ rtl.fireEvent.keyDown(bubbles[1], { key: 'Home' });+ assert.equal(document.activeElement, bubbles[0]);+ rtl.fireEvent.keyDown(bubbles[0], { key: 'End' });+ assert.equal(document.activeElement, bubbles[1]);+});++test('a key pressed inside a message action keeps its own meaning', () => {+ const { container } = renderThread('operator', [PROMPT, { ...PROMPT, id: 'db-2', waMessageId: 'wamid.2' }]);+ const bubbles = container.querySelectorAll<HTMLElement>('[data-roving-message]');+ const reply = bubbles[1].querySelector<HTMLElement>('.action-btn');+ assert.ok(reply);+ reply.focus();+ rtl.fireEvent.keyDown(reply, { key: 'ArrowUp' });+ assert.equal(document.activeElement, reply);+});diff --git a/dashboard/src/components/chats/ChatThread.tsx b/dashboard/src/components/chats/ChatThread.tsxindex 3efbeabc5..88b6f58ad 100644--- a/dashboard/src/components/chats/ChatThread.tsx+++ b/dashboard/src/components/chats/ChatThread.tsx@@ -1,4 +1,4 @@-import { useCallback, useEffect, useMemo, useState, type RefObject } from 'react';+import { useCallback, useEffect, useMemo, useState, type KeyboardEvent, type RefObject } from 'react';import { useTranslation } from 'react-i18next';import { AlertCircle, ChevronDown, CornerUpLeft, Loader2, MessageSquare, Smile, Trash2 } from 'lucide-react';import { useRole } from '../../hooks/useRole';@@ -75,6 +75,42 @@ function ChatThread({// would only reach a 403.const { canWrite } = useRole();+ // The message actions sit behind hover, so a keyboard user reaches them through the bubble that carries+ // them: the thread is one tab stop (the focused message, else the newest), the arrow keys move between+ // messages, and the actions show while focus is inside the bubble (Chats.css).+ const hasActions = useCallback(+ (message: ChatMessageView) => canWrite && message.type !== 'revoked' && Boolean(message.waMessageId),+ [canWrite],+ );+ const [focusedMessageId, setFocusedMessageId] = useState<string | null>(null);+ const tabStopId = useMemo(() => {+ if (focusedMessageId && messages.some(m => m.id === focusedMessageId && hasActions(m))) return focusedMessageId;+ for (let i = messages.length - 1; i >= 0; i--) if (hasActions(messages[i])) return messages[i].id;+ return null;+ }, [messages, focusedMessageId, hasActions]);+ const onBubbleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {+ // Only the bubble itself: a key pressed on an action button, the reaction popover or a link keeps+ // its own meaning.+ if (event.target !== event.currentTarget) return;+ const stops = Array.from(+ messagesContainerRef.current?.querySelectorAll<HTMLElement>('[data-roving-message]') ?? [],+ );+ const at = stops.indexOf(event.currentTarget);+ const target =+ event.key === 'ArrowUp'+ ? stops[at - 1]+ : event.key === 'ArrowDown'+ ? stops[at + 1]+ : event.key === 'Home'+ ? stops[0]+ : event.key === 'End'+ ? stops[stops.length - 1]+ : undefined;+ if (!target) return;+ event.preventDefault();+ target.focus();+ };+// "@<digits>" in a message body only ever means something once resolved against a participant// this thread has already seen post (see buildMentionNameMap) — recomputed only when the message// list itself changes, not per-render.@@ -436,7 +472,17 @@ function ChatThread({data-wa-message-id={msg.waMessageId}data-scroll-anchor="">- <div className="message-bubble-container">+ <div+ className="message-bubble-container"+ {...(hasActions(msg)+ ? {+ 'data-roving-message': '',+ tabIndex: tabStopId === msg.id ? 0 : -1,+ onFocus: () => setFocusedMessageId(msg.id),+ onKeyDown: onBubbleKeyDown,+ }+ : {})}+ ><divclassName={`message-bubble ${isMe ? 'outgoing' : 'incoming'} ${msg.status} ${isMediaMessage ? 'media-type' : ''@@ -548,7 +594,7 @@ function ChatThread({)}</div>- {/* Message actions menu (hover). Every action addresses the message by its WhatsApp+ {/* Message actions menu (hover, or focus inside the bubble). Every action addresses the message by its WhatsAppid, so an optimistic bubble still on its local temp_ id (pending, or failed forgood) offers none: the gateway could never resolve it. */}{canWrite && !isRevoked && Boolean(msg.waMessageId) && (diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.cssindex 6b17c6a8b..642574203 100644--- a/dashboard/src/pages/Chats.css+++ b/dashboard/src/pages/Chats.css@@ -1113,10 +1113,18 @@z-index: 5;}-.chats-page .message-bubble-container:hover .message-actions-menu {+.chats-page .message-bubble-container:hover .message-actions-menu,+.chats-page .message-bubble-container:focus-within .message-actions-menu {display: flex;}+/* A bubble is a keyboard stop (ChatThread): the ring says which message the arrow keys act on. */+.chats-page .message-bubble-container:focus-visible {+ outline: 2px solid var(--primary);+ outline-offset: 2px;+ border-radius: 12px;+}+.chats-page .action-btn {background: transparent;border: none;@@ -1171,7 +1179,8 @@background: transparent;}-.chats-page .reaction-trigger-wrapper:hover .reaction-quick-popover {+.chats-page .reaction-trigger-wrapper:hover .reaction-quick-popover,+.chats-page .reaction-trigger-wrapper:focus-within .reaction-quick-popover {display: flex;}