Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): open the reaction popover below its icon at the top edge

Yudhi Armyndharisd573a164d95d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index defba11d3..caa95bc3c 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 inside the thread, where the emoji nearest the edge of a short or own message was clipped and could not be picked.
+- Keep the dashboard's reaction popover inside the thread, where the emoji nearest one of its edges 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.ts
index 1c3806080..8f84d2491 100644
--- a/dashboard/src/components/chats/ChatThread.test.ts
+++ b/dashboard/src/components/chats/ChatThread.test.ts
@@ -896,6 +896,31 @@ test('the reaction popover is shifted back inside the thread when it opens past
popover.getBoundingClientRect = rect(300, 508);
rtl.fireEvent.mouseEnter(wrapper);
assert.equal(popover.style.getPropertyValue('--popover-shift'), '');
+ assert.equal(popover.hasAttribute('data-below'), false);
+});
+
+// A message at the top of the pane has no room above its icon: the popover opens below it, and is measured
+// again each time, so scrolling the message down puts it back above.
+test('the reaction popover opens below its icon when it would lie above the thread', () => {
+ 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 = (top: number) => () => ({ left: 300, right: 508, top, bottom: top + 44, width: 208 }) as DOMRect;
+ thread.getBoundingClientRect = () => ({ left: 100, right: 700, top: 200, bottom: 600, width: 600 }) as DOMRect;
+
+ popover.getBoundingClientRect = rect(170);
+ rtl.fireEvent.mouseEnter(wrapper);
+ assert.equal(popover.hasAttribute('data-below'), true);
+
+ popover.getBoundingClientRect = rect(260);
+ rtl.fireEvent.mouseEnter(wrapper);
+ assert.equal(popover.hasAttribute('data-below'), false);
+
+ const css = readFileSync(new URL('../../pages/Chats.css', import.meta.url), 'utf8');
+ assert.match(css, /\.reaction-quick-popover\[data-below\] \{[^}]*top:\s*100%;/);
});
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.tsx
index f379a1561..9c0c6a55f 100644
--- a/dashboard/src/components/chats/ChatThread.tsx
+++ b/dashboard/src/components/chats/ChatThread.tsx
@@ -295,19 +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).
+ // The reaction popover is centred on its icon and opens above it. The icon of a short bubble is a few pixels
+ // from the pane's side edge, and a message at the top of the pane has no room above it, so the emoji
+ // nearest an edge would be clipped and out of the pointer's reach. When it opens it is measured against
+ // the pane: shifted back inside by the amount it runs over sideways, and opened below the icon when it
+ // would lie above the pane (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');
+ popover.removeAttribute('data-below');
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`);
+ if (at.top < edge.top) popover.setAttribute('data-below', '');
},
[messagesContainerRef],
);
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index 1748b1f3c..f49776417 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -1186,6 +1186,22 @@
transform: translateX(var(--popover-shift, 0px)) translateY(-6px);
}
+/* Opened below the icon when there is no room above it in the pane (ChatThread sets data-below). */
+.chats-page .reaction-quick-popover[data-below] {
+ bottom: auto;
+ top: 100%;
+ transform: translateX(calc(-50% + var(--popover-shift, 0px))) translateY(6px);
+}
+
+.chats-page .message-bubble-wrapper.outgoing .reaction-quick-popover[data-below] {
+ transform: translateX(var(--popover-shift, 0px)) translateY(6px);
+}
+
+.chats-page .reaction-quick-popover[data-below]::after {
+ top: auto;
+ bottom: 100%;
+}
+
.chats-page .reaction-quick-popover::after {
content: '';
position: absolute;