Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): shift the reaction popover back inside the thread
Yudhi Armyndharisd2c0397fb0f8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c958084f6..defba11d3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -53,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Bound each webhook and ingress queue command at 2 s once Redis has connected, so a Redis that stops answering falls back to direct delivery and inline dispatch instead of holding every dispatch and ingress request.- Keep the dashboard chat's scroll-to-bottom button in view while the reader is scrolled up, where it moved with the thread and was off screen.- Land the dashboard chat's scroll-to-bottom button at the bottom when an older page arrives meanwhile, where the animated jump could end far above it.-- Keep the dashboard's reaction popover of an own message inside the thread, where its last emoji was clipped and could not be picked.+- Keep the dashboard's reaction popover inside the thread, where the emoji nearest the edge of a short or own message was clipped and could not be picked.- Refuse to save a local `storage.localPath` the app cannot create or write, where the next start refused to boot and the dashboard that could undo the save was down.- Answer `400` for a send route's or a product send's `chatId`, or a bulk `batchId`, over 255 characters, where PostgreSQL answered `500` once the value passed its index entry limit.- Answer `400` for a `chatId` over 255 characters in the request body of a chat action, as the send routes do, instead of handing it to the engine.diff --git a/dashboard/src/components/chats/ChatThread.test.ts b/dashboard/src/components/chats/ChatThread.test.tsindex d9d2a6089..1c3806080 100644--- a/dashboard/src/components/chats/ChatThread.test.ts+++ b/dashboard/src/components/chats/ChatThread.test.ts@@ -868,7 +868,34 @@ test('the reaction popover of an own message grows from the end of its icon, not/\.chats-page \.message-bubble-wrapper\.outgoing \.reaction-quick-popover \{([^}]*)\}/.exec(css)?.[1] ?? '';assert.match(rule, /inset-inline-end:\s*0;/);assert.match(rule, /left:\s*auto;/);- assert.doesNotMatch(rule, /translateX/);+ // No centring on the icon: whatever shift it carries is the one set when it opens.+ assert.doesNotMatch(rule, /-50%/);+});++// jsdom has no layout, so the rectangles are given: a popover that opens 30 px past the start edge of the+// thread is shifted back by 30 px, one inside it is left alone, and the shift is measured again each time.+test('the reaction popover is shifted back inside the thread when it opens past an edge', () => {+ const { container } = renderThread('operator', [PROMPT, { ...PROMPT, id: 'db-2', waMessageId: 'wamid.2' }]);+ const thread = container.querySelector<HTMLElement>('.room-messages');+ assert.ok(thread);+ const wrapper = bubblesOf(container)[0].querySelector<HTMLElement>('.reaction-trigger-wrapper');+ const popover = wrapper?.querySelector<HTMLElement>('.reaction-quick-popover');+ assert.ok(wrapper && popover);+ const rect = (left: number, right: number) => () =>+ ({ left, right, top: 0, bottom: 0, width: right - left }) as DOMRect;+ thread.getBoundingClientRect = rect(100, 700);++ popover.getBoundingClientRect = rect(70, 278);+ rtl.fireEvent.mouseEnter(wrapper);+ assert.equal(popover.style.getPropertyValue('--popover-shift'), '30px');++ popover.getBoundingClientRect = rect(500, 708);+ rtl.fireEvent.mouseEnter(wrapper);+ assert.equal(popover.style.getPropertyValue('--popover-shift'), '-8px');++ popover.getBoundingClientRect = rect(300, 508);+ rtl.fireEvent.mouseEnter(wrapper);+ assert.equal(popover.style.getPropertyValue('--popover-shift'), '');});test('the scroll-to-bottom button is the last child of the scroller and jumps without animating', async () => {diff --git a/dashboard/src/components/chats/ChatThread.tsx b/dashboard/src/components/chats/ChatThread.tsxindex 4544b828b..f379a1561 100644--- a/dashboard/src/components/chats/ChatThread.tsx+++ b/dashboard/src/components/chats/ChatThread.tsx@@ -6,6 +6,7 @@ import {useState,type FocusEvent,type KeyboardEvent,+ type SyntheticEvent,type RefObject,} from 'react';import { useTranslation } from 'react-i18next';@@ -294,6 +295,23 @@ function ChatThread({return () => el.removeEventListener('scroll', onScroll);});+ // The reaction popover is centred on its icon, and the icon of a short bubble is a few pixels from the pane's+ // edge, so the emoji nearest the edge would be clipped and out of the pointer's reach. When it opens it is+ // measured against the pane and shifted back inside by the amount it runs over (see Chats.css).+ const fitReactionPopover = useCallback(+ (event: SyntheticEvent<HTMLDivElement>) => {+ const popover = event.currentTarget.querySelector<HTMLElement>('.reaction-quick-popover');+ const pane = messagesContainerRef.current;+ if (!popover || !pane) return;+ popover.style.removeProperty('--popover-shift');+ const at = popover.getBoundingClientRect();+ const edge = pane.getBoundingClientRect();+ const shift = at.left < edge.left ? edge.left - at.left : at.right > edge.right ? edge.right - at.right : 0;+ if (shift !== 0) popover.style.setProperty('--popover-shift', `${Math.round(shift)}px`);+ },+ [messagesContainerRef],+ );+const handleJumpToBottom = useCallback(() => {const el = messagesContainerRef.current;if (!el) return;@@ -698,7 +716,11 @@ function ChatThread({<CornerUpLeft size={14} /></button>- <div className="reaction-trigger-wrapper">+ <div+ className="reaction-trigger-wrapper"+ onMouseEnter={fitReactionPopover}+ onFocus={fitReactionPopover}+ ><button type="button" className="action-btn reaction-btn" title={t('chats.actions.react')}><Smile size={14} /></button>diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.cssindex 9985c37e9..1748b1f3c 100644--- a/dashboard/src/pages/Chats.css+++ b/dashboard/src/pages/Chats.css@@ -1165,7 +1165,8 @@position: absolute;bottom: 100%;left: 50%;- transform: translateX(-50%) translateY(-6px);+ /* --popover-shift is set when it opens, by the amount it would run past the pane (ChatThread). */+ transform: translateX(calc(-50% + var(--popover-shift, 0px))) translateY(-6px);background: var(--bg-white);border: 1px solid var(--border);box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);@@ -1182,7 +1183,7 @@.chats-page .message-bubble-wrapper.outgoing .reaction-quick-popover {left: auto;inset-inline-end: 0;- transform: translateY(-6px);+ transform: translateX(var(--popover-shift, 0px)) translateY(-6px);}.chats-page .reaction-quick-popover::after {