Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): open a document sent by URL in a new tab
Yudhi Armyndharisd7cb8391ff0e
diff --git a/dashboard/src/components/chats/ChatThread.test.ts b/dashboard/src/components/chats/ChatThread.test.tsindex 0d7b75c65..f224429d9 100644--- a/dashboard/src/components/chats/ChatThread.test.ts+++ b/dashboard/src/components/chats/ChatThread.test.ts@@ -151,3 +151,24 @@ test('an @mention of a participant who posted in the thread shows their first naassert.equal(body?.querySelector('bdi')?.textContent, '@Bob');assert.equal(container.querySelector('.quote-body bdi')?.textContent, '@Bob');});++test('a document sent by URL opens in a new tab instead of navigating the dashboard away', () => {+ // Browsers ignore `download` on a cross-origin link, so a plain click would unload the dashboard.+ const doc = (id: string, data: string): ChatMessageView => ({+ ...PROMPT,+ id,+ waMessageId: `wamid.${id}`,+ body: '',+ type: 'document',+ metadata: { media: { mimetype: 'application/pdf', filename: `${id}.pdf`, data } },+ });+ const { container } = renderThread('operator', [+ doc('remote', 'https://files.example.com/remote.pdf'),+ doc('inline', 'JVBERi0='),+ ]);+ const [remote, inline] = Array.from(container.querySelectorAll<HTMLAnchorElement>('a.chat-document-media'));+ assert.equal(remote.getAttribute('target'), '_blank');+ assert.equal(remote.getAttribute('rel'), 'noopener noreferrer');+ assert.equal(inline.getAttribute('target'), null);+ assert.equal(inline.getAttribute('download'), 'inline.pdf');+});diff --git a/dashboard/src/components/chats/ChatThread.tsx b/dashboard/src/components/chats/ChatThread.tsxindex 73eeb6db7..498309b10 100644--- a/dashboard/src/components/chats/ChatThread.tsx+++ b/dashboard/src/components/chats/ChatThread.tsx@@ -374,7 +374,14 @@ function ChatThread({default:return (<div className="message-media-document">- <a href={mediaSrc} download={mediaInfo.filename || 'document'} className="chat-document-media">+ {/* A document sent by URL links off-site, where browsers ignore `download`, so a plain+ click would navigate the dashboard away; open it in a new tab instead. */}+ <a+ href={mediaSrc}+ download={mediaInfo.filename || 'document'}+ className="chat-document-media"+ {...(/^https?:\/\//i.test(mediaSrc) ? { target: '_blank', rel: 'noopener noreferrer' } : {})}+ >📎 {mediaInfo.filename || t('chats.downloadDocument')}</a></div>