Skip to content

Commit ae1b051

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 431c331 commit ae1b051

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CHANGELOG.md

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

@@ -38,6 +38,7 @@ and this project adheres to
3838
- 🐛(frontend) fix legacy role computation #1376
3939
- 🛂(frontend) block editing title when not allowed #1412
4040
- 🐛(frontend) scroll back to top when navigate to a document #1406
41+
- 🐛(frontend) fix attachment download filename #1447
4142
- 🐛(frontend) exclude h4-h6 headings from table of contents #1441
4243
- 🔒(frontend) prevent readers from changing callout emoji #1449
4344

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ test.describe('Doc Editor', () => {
846846

847847
await page.getByText('Add PDF').click();
848848
const fileChooserPromise = page.waitForEvent('filechooser');
849+
const downloadPromise = page.waitForEvent('download');
849850
await page.getByText('Upload file').click();
850851
const fileChooser = await fileChooserPromise;
851852

@@ -866,5 +867,12 @@ test.describe('Doc Editor', () => {
866867

867868
await expect(pdfEmbed).toHaveAttribute('type', 'application/pdf');
868869
await expect(pdfEmbed).toHaveAttribute('role', 'presentation');
870+
871+
// Check download with original filename
872+
await page.locator('.bn-block-content[data-content-type="pdf"]').click();
873+
await page.locator('[data-test="downloadfile"]').click();
874+
875+
const download = await downloadPromise;
876+
expect(download.suggestedFilename()).toBe('test-pdf.pdf');
869877
});
870878
});

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,23 @@ 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 || 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+
87+
const baseName =
88+
fileBlock.props.name || url.split('/').pop() || 'file';
89+
90+
const regFindLastDot = /(\.[^/.]+)$/;
91+
const unsafeName = baseName.includes('.')
92+
? baseName.replace(regFindLastDot, '-unsafe$1')
93+
: baseName + '-unsafe';
94+
95+
downloadFile(blob, unsafeName);
8496
};
8597

8698
open(onConfirm);
@@ -100,6 +112,7 @@ export const FileDownloadButton = ({
100112
<>
101113
<Components.FormattingToolbar.Button
102114
className="bn-button --docs--editor-file-download-button"
115+
data-test="downloadfile"
103116
label={
104117
dict.formatting_toolbar.file_download.tooltip[fileBlock.type] ||
105118
dict.formatting_toolbar.file_download.tooltip['file']

0 commit comments

Comments
 (0)