The minimalistic document archiving platform.
feat(documents): add download button to document actions in overview page (#1072)
Moriz von Langa71d093f644a3
diff --git a/.changeset/slimy-phones-tan.md b/.changeset/slimy-phones-tan.mdnew file mode 100644index 00000000..a28d13a3--- /dev/null+++ b/.changeset/slimy-phones-tan.md@@ -0,0 +1,5 @@+---+"@papra/app": patch+---++Added a download file option in document list action menudiff --git a/apps/papra-client/src/locales/de.dictionary.ts b/apps/papra-client/src/locales/de.dictionary.tsindex c324cbf4..6c9fc2c7 100644--- a/apps/papra-client/src/locales/de.dictionary.ts+++ b/apps/papra-client/src/locales/de.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Inhalt','documents.tabs.activity': 'Aktivität','documents.deleted.message': 'Dieses Dokument wurde gelöscht und wird in {{ days }} Tagen dauerhaft entfernt.',- 'documents.actions.download': 'Herunterladen',+ 'documents.actions.download.title': 'Herunterladen',+ 'documents.actions.download.error': 'Dokument konnte nicht heruntergeladen werden','documents.actions.open-in-new-tab': 'In neuem Tab öffnen','documents.actions.restore': 'Wiederherstellen','documents.actions.delete': 'Löschen',diff --git a/apps/papra-client/src/locales/el.dictionary.ts b/apps/papra-client/src/locales/el.dictionary.tsindex 9403ad6f..39ff0e93 100644--- a/apps/papra-client/src/locales/el.dictionary.ts+++ b/apps/papra-client/src/locales/el.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Περιεχόμενο','documents.tabs.activity': 'Δραστηριότητα','documents.deleted.message': 'Αυτό το έγγραφο έχει διαγραφεί και θα αφαιρεθεί οριστικά σε {{ days }} ημέρες.',- 'documents.actions.download': 'Λήψη',+ 'documents.actions.download.title': 'Λήψη',+ 'documents.actions.download.error': 'Αποτυχία λήψης εγγράφου','documents.actions.open-in-new-tab': 'Άνοιγμα σε νέα καρτέλα','documents.actions.restore': 'Επαναφορά','documents.actions.delete': 'Διαγραφή',diff --git a/apps/papra-client/src/locales/en.dictionary.ts b/apps/papra-client/src/locales/en.dictionary.tsindex 51ea490a..e0352973 100644--- a/apps/papra-client/src/locales/en.dictionary.ts+++ b/apps/papra-client/src/locales/en.dictionary.ts@@ -335,7 +335,8 @@ export const translations = {'documents.tabs.content': 'Content','documents.tabs.activity': 'Activity','documents.deleted.message': 'This document has been deleted and will be permanently removed in {{ days }} days.',- 'documents.actions.download': 'Download',+ 'documents.actions.download.title': 'Download',+ 'documents.actions.download.error': 'Failed to download document','documents.actions.open-in-new-tab': 'Open in new tab','documents.actions.restore': 'Restore','documents.actions.delete': 'Delete',diff --git a/apps/papra-client/src/locales/es.dictionary.ts b/apps/papra-client/src/locales/es.dictionary.tsindex d839e3ce..7e1ede0e 100644--- a/apps/papra-client/src/locales/es.dictionary.ts+++ b/apps/papra-client/src/locales/es.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Contenido','documents.tabs.activity': 'Actividad','documents.deleted.message': 'Este documento ha sido eliminado y será borrado permanentemente en {{ days }} días.',- 'documents.actions.download': 'Descargar',+ 'documents.actions.download.title': 'Descargar',+ 'documents.actions.download.error': 'No se pudo descargar el documento','documents.actions.open-in-new-tab': 'Abrir en una nueva pestaña','documents.actions.restore': 'Restaurar','documents.actions.delete': 'Eliminar',diff --git a/apps/papra-client/src/locales/fr.dictionary.ts b/apps/papra-client/src/locales/fr.dictionary.tsindex 1581e419..54f1945f 100644--- a/apps/papra-client/src/locales/fr.dictionary.ts+++ b/apps/papra-client/src/locales/fr.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Contenu','documents.tabs.activity': 'Activité','documents.deleted.message': 'Ce document a été supprimé et sera supprimé définitivement dans {{ days }} jours.',- 'documents.actions.download': 'Télécharger',+ 'documents.actions.download.title': 'Télécharger',+ 'documents.actions.download.error': 'Impossible de télécharger le document','documents.actions.open-in-new-tab': 'Ouvrir dans un nouvel onglet','documents.actions.restore': 'Restaurer','documents.actions.delete': 'Supprimer',diff --git a/apps/papra-client/src/locales/it.dictionary.ts b/apps/papra-client/src/locales/it.dictionary.tsindex 4ea1c847..46b6db05 100644--- a/apps/papra-client/src/locales/it.dictionary.ts+++ b/apps/papra-client/src/locales/it.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Contenuto','documents.tabs.activity': 'Attività','documents.deleted.message': 'Questo documento è stato eliminato e sarà rimosso definitivamente tra {{ days }} giorni.',- 'documents.actions.download': 'Scarica',+ 'documents.actions.download.title': 'Scarica',+ 'documents.actions.download.error': 'Impossibile scaricare il documento','documents.actions.open-in-new-tab': 'Apri in una nuova scheda','documents.actions.restore': 'Ripristina','documents.actions.delete': 'Elimina',diff --git a/apps/papra-client/src/locales/nl.dictionary.ts b/apps/papra-client/src/locales/nl.dictionary.tsindex f534b9b0..9787a2a7 100644--- a/apps/papra-client/src/locales/nl.dictionary.ts+++ b/apps/papra-client/src/locales/nl.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Inhoud','documents.tabs.activity': 'Activiteit','documents.deleted.message': 'Dit document is verwijderd en wordt permanent verwijderd over {{ days }} dagen.',- 'documents.actions.download': 'Downloaden',+ 'documents.actions.download.title': 'Downloaden',+ 'documents.actions.download.error': 'Document kon niet worden gedownload','documents.actions.open-in-new-tab': 'Openen in nieuw tabblad','documents.actions.restore': 'Herstellen','documents.actions.delete': 'Verwijderen',diff --git a/apps/papra-client/src/locales/pl.dictionary.ts b/apps/papra-client/src/locales/pl.dictionary.tsindex 9dccb6cb..05b41f05 100644--- a/apps/papra-client/src/locales/pl.dictionary.ts+++ b/apps/papra-client/src/locales/pl.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Treść','documents.tabs.activity': 'Aktywność','documents.deleted.message': 'Ten dokument został usunięty i zostanie trwale usunięty za {{ days }} dni.',- 'documents.actions.download': 'Pobierz',+ 'documents.actions.download.title': 'Pobierz',+ 'documents.actions.download.error': 'Nie udało się pobrać dokumentu','documents.actions.open-in-new-tab': 'Otwórz w nowej karcie','documents.actions.restore': 'Przywróć','documents.actions.delete': 'Usuń',diff --git a/apps/papra-client/src/locales/pt-BR.dictionary.ts b/apps/papra-client/src/locales/pt-BR.dictionary.tsindex 46b3daae..90a7fac3 100644--- a/apps/papra-client/src/locales/pt-BR.dictionary.ts+++ b/apps/papra-client/src/locales/pt-BR.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Conteúdo','documents.tabs.activity': 'Atividades','documents.deleted.message': 'Este documento foi excluído e será deletado permanentemente em {{ days }} dias.',- 'documents.actions.download': 'Baixar',+ 'documents.actions.download.title': 'Baixar',+ 'documents.actions.download.error': 'Falha ao baixar o documento','documents.actions.open-in-new-tab': 'Abrir em nova aba','documents.actions.restore': 'Restaurar','documents.actions.delete': 'Excluir',diff --git a/apps/papra-client/src/locales/pt.dictionary.ts b/apps/papra-client/src/locales/pt.dictionary.tsindex 825c7137..8aabc195 100644--- a/apps/papra-client/src/locales/pt.dictionary.ts+++ b/apps/papra-client/src/locales/pt.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Conteúdo','documents.tabs.activity': 'Atividade','documents.deleted.message': 'Este documento foi eliminado e será permanentemente removido em {{ days }} dias.',- 'documents.actions.download': 'Descarregar',+ 'documents.actions.download.title': 'Descarregar',+ 'documents.actions.download.error': 'Falha ao descarregar o documento','documents.actions.open-in-new-tab': 'Abrir em novo separador','documents.actions.restore': 'Restaurar','documents.actions.delete': 'Eliminar',diff --git a/apps/papra-client/src/locales/ro.dictionary.ts b/apps/papra-client/src/locales/ro.dictionary.tsindex 04894a63..13f8676e 100644--- a/apps/papra-client/src/locales/ro.dictionary.ts+++ b/apps/papra-client/src/locales/ro.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Conținut','documents.tabs.activity': 'Activitate','documents.deleted.message': 'Acest document a fost șters și va fi eliminat definitiv după {{ days }} zile.',- 'documents.actions.download': 'Descarcă',+ 'documents.actions.download.title': 'Descarcă',+ 'documents.actions.download.error': 'Nu s-a putut descărca documentul','documents.actions.open-in-new-tab': 'Deschide în filă nouă','documents.actions.restore': 'Restaurează','documents.actions.delete': 'Șterge',diff --git a/apps/papra-client/src/locales/ru.dictionary.ts b/apps/papra-client/src/locales/ru.dictionary.tsindex 110cb8ba..7aa009bc 100644--- a/apps/papra-client/src/locales/ru.dictionary.ts+++ b/apps/papra-client/src/locales/ru.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Содержимое','documents.tabs.activity': 'Активность','documents.deleted.message': 'Этот документ был удален и будет окончательно удален через {{ days }} {{ count, =1:дней, [2-4]:дня, дней }}.',- 'documents.actions.download': 'Скачать',+ 'documents.actions.download.title': 'Скачать',+ 'documents.actions.download.error': 'Не удалось загрузить документ','documents.actions.open-in-new-tab': 'Открыть в новой вкладке','documents.actions.restore': 'Восстановить','documents.actions.delete': 'Удалить',diff --git a/apps/papra-client/src/locales/sv.dictionary.ts b/apps/papra-client/src/locales/sv.dictionary.tsindex 24357fbf..d798643f 100644--- a/apps/papra-client/src/locales/sv.dictionary.ts+++ b/apps/papra-client/src/locales/sv.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': 'Innehåll','documents.tabs.activity': 'Aktivitet','documents.deleted.message': 'Detta dokument har tagits bort och kommer att tas bort permanent om {{ days }} dagar.',- 'documents.actions.download': 'Ladda ner',+ 'documents.actions.download.title': 'Ladda ner',+ 'documents.actions.download.error': 'Det gick inte att ladda ner dokumentet','documents.actions.open-in-new-tab': 'Öppna i ny tabb','documents.actions.restore': 'Återställ','documents.actions.delete': 'Radera',diff --git a/apps/papra-client/src/locales/zh.dictionary.ts b/apps/papra-client/src/locales/zh.dictionary.tsindex 23bf6767..e8b5edaf 100644--- a/apps/papra-client/src/locales/zh.dictionary.ts+++ b/apps/papra-client/src/locales/zh.dictionary.ts@@ -337,7 +337,8 @@ export const translations: Partial<TranslationsDictionary> = {'documents.tabs.content': '内容','documents.tabs.activity': '活动','documents.deleted.message': '该文档已被删除,将在 {{ days }} 天内被永久移除。',- 'documents.actions.download': '下载',+ 'documents.actions.download.title': '下载',+ 'documents.actions.download.error': '文档下载失败','documents.actions.open-in-new-tab': '在新标签页中打开','documents.actions.restore': '恢复','documents.actions.delete': '删除',diff --git a/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx b/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsxindex a0bbb4ce..3df9ad4a 100644--- a/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx+++ b/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx@@ -7,12 +7,13 @@ import { useI18n } from '@/modules/i18n/i18n.provider';import { Button } from '@/modules/ui/components/button';import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger } from '@/modules/ui/components/dropdown-menu';import { getDocumentOpenWithApps } from '../document.models';-import { useDeleteDocument } from '../documents.composables';+import { useDeleteDocument, useDownloadDocument } from '../documents.composables';import { DocumentOpenWithDropdownItems } from './open-with.component';import { useRenameDocumentDialog } from './rename-document-button.component';export const DocumentManagementDropdown: Component<{ document: Document }> = (props) => {const { deleteDocument } = useDeleteDocument();+ const { downloadDocument } = useDownloadDocument();const { openRenameDialog } = useRenameDocumentDialog();const { t } = useI18n();@@ -56,6 +57,17 @@ export const DocumentManagementDropdown: Component<{ document: Document }> = (pr</DropdownMenuSub></Show>+ <DropdownMenuItem+ class="cursor-pointer"+ onClick={() => downloadDocument({+ documentId: props.document.id,+ organizationId: props.document.organizationId,+ })}+ >+ <div class="i-tabler-download size-4 mr-2" />+ <span>{t('documents.actions.download.title')}</span>+ </DropdownMenuItem>+<DropdownMenuItemclass="cursor-pointer"onClick={() => openRenameDialog({diff --git a/apps/papra-client/src/modules/documents/documents.composables.tsx b/apps/papra-client/src/modules/documents/documents.composables.tsxindex 47cb2e8d..cd956867 100644--- a/apps/papra-client/src/modules/documents/documents.composables.tsx+++ b/apps/papra-client/src/modules/documents/documents.composables.tsx@@ -1,9 +1,11 @@import type { Document } from './documents.types';import { createSignal } from 'solid-js';+import { useI18n } from '@/modules/i18n/i18n.provider';+import { downloadFile } from '@/modules/shared/files/download';import { useConfirmModal } from '../shared/confirm';import { queryClient } from '../shared/query/query-client';import { createToast } from '../ui/components/sonner';-import { deleteDocument, restoreDocument } from './documents.services';+import { deleteDocument, fetchDocument, fetchDocumentFile, restoreDocument } from './documents.services';export function invalidateOrganizationDocumentsQuery({ organizationId }: { organizationId: string }) {return queryClient.invalidateQueries({@@ -22,6 +24,35 @@ function getConfirmMessage(documentName: string) {);}+export function useDownloadDocument() {+ const { t } = useI18n();++ return {+ async downloadDocument({ organizationId, documentId}: { organizationId: string; documentId: string }) {+ try {+ const [document, documentFile] = await Promise.all([+ queryClient.fetchQuery({+ queryKey: ['organizations', organizationId, 'documents', documentId],+ queryFn: () => fetchDocument({ documentId, organizationId }),+ }),+ queryClient.fetchQuery({+ queryKey: ['organizations', organizationId, 'documents', documentId, 'file'],+ queryFn: () => fetchDocumentFile({ documentId, organizationId }),+ }),+ ]);++ const url = URL.createObjectURL(documentFile);++ downloadFile({ url, fileName: document.document.name });++ URL.revokeObjectURL(url);+ } catch {+ createToast({ type: 'error', message: t('documents.actions.download.error') });+ }+ },+ };+}+export function useDeleteDocument() {const { confirm } = useConfirmModal();diff --git a/apps/papra-client/src/modules/documents/pages/document.page.tsx b/apps/papra-client/src/modules/documents/pages/document.page.tsxindex 8b073910..ad0e6ba9 100644--- a/apps/papra-client/src/modules/documents/pages/document.page.tsx+++ b/apps/papra-client/src/modules/documents/pages/document.page.tsx@@ -10,7 +10,6 @@ import { DocumentCustomPropertiesPanel } from '@/modules/custom-properties/compoimport { fetchCustomPropertyDefinitions } from '@/modules/custom-properties/custom-properties.services';import { RelativeTime } from '@/modules/i18n/components/RelativeTime';import { useI18n } from '@/modules/i18n/i18n.provider';-import { downloadFile } from '@/modules/shared/files/download';import { DocumentTagsList } from '@/modules/tags/components/tag-list.component';import { TagLink } from '@/modules/tags/components/tag.component';import { Alert } from '@/modules/ui/components/alert';@@ -24,8 +23,8 @@ import { DocumentPreview } from '../components/document-preview.component';import { DocumentOpenWithDropdownItems } from '../components/open-with.component';import { useRenameDocumentDialog } from '../components/rename-document-button.component';import { getDaysBeforePermanentDeletion, getDocumentActivityIcon, getDocumentOpenWithApps } from '../document.models';-import { useDeleteDocument, useRestoreDocument } from '../documents.composables';-import { fetchDocument, fetchDocumentActivities, fetchDocumentFile } from '../documents.services';+import { useDeleteDocument, useDownloadDocument, useRestoreDocument } from '../documents.composables';+import { fetchDocument, fetchDocumentActivities } from '../documents.services';type KeyValueItem = {label: string | JSX.Element;@@ -127,6 +126,7 @@ export const DocumentPage: Component = () => {const params = useParams();const [searchParams, setSearchParams] = useSearchParams();const { deleteDocument } = useDeleteDocument();+ const { downloadDocument } = useDownloadDocument();const { restore, getIsRestoring } = useRestoreDocument();const navigate = useNavigate();const { config } = useConfig();@@ -151,11 +151,6 @@ export const DocumentPage: Component = () => {queryFn: () => fetchDocument({ documentId: params.documentId, organizationId: params.organizationId }),}));- const documentFileQuery = useQuery(() => ({- queryKey: ['organizations', params.organizationId, 'documents', params.documentId, 'file'],- queryFn: () => fetchDocumentFile({ documentId: params.documentId, organizationId: params.organizationId }),- }));-const customPropertyDefinitionsQuery = useQuery(() => ({queryKey: ['organizations', params.organizationId, 'custom-properties'],queryFn: () => fetchCustomPropertyDefinitions({ organizationId: params.organizationId }),@@ -203,8 +198,6 @@ export const DocumentPage: Component = () => {navigate(`/organizations/${params.organizationId}/documents`);};- const getDataUrl = () => documentFileQuery.data ? URL.createObjectURL(documentFileQuery.data) : undefined;-return (<div class="p-6 flex gap-6 h-full flex-col md:flex-row max-w-7xl mx-auto"><Suspense>@@ -232,12 +225,12 @@ export const DocumentPage: Component = () => {<div class="flex gap-2 mb-2"><Button- onClick={() => downloadFile({ fileName: getDocument().name, url: getDataUrl()! })}+ onClick={() => downloadDocument({ organizationId: getDocument().organizationId, documentId: getDocument().id })}variant="outline"size="sm"><div class="i-tabler-download size-4 mr-2" />- {t('documents.actions.download')}+ {t('documents.actions.download.title')}</Button><DocumentOpenWithDropdown document={getDocument()} organizationId={params.organizationId} />