Skip to content

Commit aa5294a

Browse files
committed
✨(frontend) fix attachment download filename
use the document title instead of the uuid when downloading attachments Signed-off-by: Cyril <c.gromoff@gmail.com>
1 parent 18f4ab8 commit aa5294a

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ and this project adheres to
2525
- ♿ remove redundant aria-label on hidden icons and update tests #1432
2626
- ♿ improve semantic structure and aria roles of leftpanel #1431
2727
- ♿ add default background to left panel for better accessibility #1423
28-
- ♿ restyle checked checkboxes: removing strikethrough #1439
28+
- ♿ restyle checked checkboxes: removing strikethrough #1439
2929
- ♿ add h1 for SR on 40X pages and remove alt texts #1438
3030
- ♿ update labels and shared document icon accessibility #1442
3131

32-
3332
### Fixed
3433

3534
- 🐛(backend) duplicate sub docs as root for reader users
3635
- ⚗️(service-worker) remove index from cache first strategy #1395
3736
- 🐛(frontend) fix 404 page when reload 403 page #1402
3837
- 🐛(frontend) fix legacy role computation #1376
3938
- 🐛(frontend) scroll back to top when navigate to a document #1406
39+
- 🐛(frontend) fix attachment download filename #1447
4040

4141
### Changed
4242

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,4 +874,38 @@ test.describe('Doc Editor', () => {
874874
await expect(pdfEmbed).toHaveAttribute('type', 'application/pdf');
875875
await expect(pdfEmbed).toHaveAttribute('role', 'presentation');
876876
});
877+
878+
test('it downloads PDF with original filename', async ({
879+
page,
880+
browserName,
881+
}) => {
882+
const [randomDoc] = await createDoc(page, 'doc-editor', browserName, 1);
883+
884+
const fileChooserPromise = page.waitForEvent('filechooser');
885+
const downloadPromise = page.waitForEvent('download');
886+
const responseCheckPromise = page.waitForResponse(
887+
(response) =>
888+
response.url().includes('media-check') && response.status() === 200,
889+
);
890+
891+
await verifyDocName(page, randomDoc);
892+
893+
await openSuggestionMenu({ page });
894+
await page.getByText('Embed a PDF file').click();
895+
896+
await page.getByText('Add PDF').click();
897+
await page.getByText('Upload file').click();
898+
899+
const fileChooser = await fileChooserPromise;
900+
await fileChooser.setFiles(path.join(__dirname, 'assets/test-pdf.pdf'));
901+
902+
await responseCheckPromise;
903+
904+
await page.locator('.bn-block-content[data-content-type="pdf"]').click();
905+
906+
await page.locator('[data-test="downloadfile"]').click();
907+
908+
const download = await downloadPromise;
909+
expect(download.suggestedFilename()).toBe('test-pdf.pdf');
910+
});
877911
});

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/FileDownloadButton.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,19 @@ export const FileDownloadButton = ({
7676

7777
if (!url.includes('-unsafe')) {
7878
const blob = (await exportResolveFileUrl(url)) as Blob;
79-
downloadFile(blob, url.split('/').pop() || 'file');
79+
downloadFile(
80+
blob,
81+
(fileBlock.props.name as string) || url.split('/').pop() || 'file',
82+
);
8083
} else {
8184
const onConfirm = async () => {
8285
const blob = (await exportResolveFileUrl(url)) as Blob;
83-
downloadFile(blob, url.split('/').pop() || 'file (unsafe)');
86+
downloadFile(
87+
blob,
88+
(fileBlock.props.name as string) ||
89+
url.split('/').pop() ||
90+
'file (unsafe)',
91+
);
8492
};
8593

8694
open(onConfirm);
@@ -100,6 +108,7 @@ export const FileDownloadButton = ({
100108
<>
101109
<Components.FormattingToolbar.Button
102110
className="bn-button --docs--editor-file-download-button"
111+
data-test="downloadfile"
103112
label={
104113
dict.formatting_toolbar.file_download.tooltip[fileBlock.type] ||
105114
dict.formatting_toolbar.file_download.tooltip['file']

0 commit comments

Comments
 (0)