Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(demo): added deletion/restoration demo routes (#62)

Corentin THOMASSET0f20b9fd1672
diff --git a/apps/papra-client/src/modules/demo/demo-api-mock.ts b/apps/papra-client/src/modules/demo/demo-api-mock.ts
index dc09d811..bfced411 100644
--- a/apps/papra-client/src/modules/demo/demo-api-mock.ts
+++ b/apps/papra-client/src/modules/demo/demo-api-mock.ts
@@ -91,14 +91,16 @@ const inMemoryApiMock: Record<string, { handler: any }> = {
const documents = await Promise.all(keys.map(key => documentStorage.getItem(key)));
+ const filteredDocuments = documents.filter(document => !document?.deletedAt);
+
const {
pageIndex = 0,
pageSize = 10,
} = query ?? {};
return {
- documents: documents.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize),
- documentsCount: documents.length,
+ documents: filteredDocuments.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize),
+ documentsCount: filteredDocuments.length,
};
},
}),
@@ -133,19 +135,6 @@ const inMemoryApiMock: Record<string, { handler: any }> = {
},
}),
- ...defineHandler({
- path: '/api/organizations/:organizationId/documents/:documentId',
- method: 'GET',
- handler: async ({ params: { organizationId, documentId } }) => {
- const key = `${organizationId}:${documentId}`;
- const document = await documentStorage.getItem(key);
-
- assert(document, { status: 404 });
-
- return { document };
- },
- }),
-
...defineHandler({
path: '/api/organizations/:organizationId/documents/search',
method: 'GET',
@@ -164,22 +153,82 @@ const inMemoryApiMock: Record<string, { handler: any }> = {
const documents = await Promise.all(keys.map(key => documentStorage.getItem(key)));
- const filteredDocuments = documents.filter(document => document?.name.includes(searchQuery));
+ const filteredDocuments = documents.filter(document => document?.name.includes(searchQuery) && !document?.deletedAt);
return {
documents: filteredDocuments.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize),
+ documentsCount: filteredDocuments.length,
+ };
+ },
+ }),
+
+ ...defineHandler({
+ path: '/api/organizations/:organizationId/documents/deleted',
+ method: 'GET',
+ handler: async ({ params: { organizationId } }) => {
+ const organization = organizationStorage.getItem(organizationId);
+ assert(organization, { status: 403 });
+
+ const allKeys = await documentStorage.getKeys();
+ const keys = allKeys.filter(key => key.startsWith(organizationId));
+
+ const documents = await Promise.all(keys.map(key => documentStorage.getItem(key)));
+
+ const deletedDocuments = documents.filter(document => document?.deletedAt);
+
+ return {
+ documents: deletedDocuments,
+ documentsCount: deletedDocuments.length,
};
},
}),
+ ...defineHandler({
+ path: '/api/organizations/:organizationId/documents/:documentId',
+ method: 'GET',
+ handler: async ({ params: { organizationId, documentId } }) => {
+ const key = `${organizationId}:${documentId}`;
+ const document = await documentStorage.getItem(key);
+
+ assert(document, { status: 404 });
+
+ return { document };
+ },
+ }),
+
+ ...defineHandler({
+ path: '/api/organizations/:organizationId/documents/:documentId/restore',
+ method: 'POST',
+ handler: async ({ params: { organizationId, documentId } }) => {
+ const key = `${organizationId}:${documentId}`;
+ const document = await documentStorage.getItem(key);
+
+ assert(document, { status: 404 });
+
+ document.deletedAt = undefined;
+ document.deletedBy = undefined;
+ document.updatedAt = new Date();
+
+ await documentStorage.setItem(key, document);
+ },
+ }),
+
...defineHandler({
path: '/api/organizations/:organizationId/documents/:documentId',
method: 'DELETE',
handler: async ({ params: { organizationId, documentId } }) => {
const key = `${organizationId}:${documentId}`;
- await documentStorage.removeItem(key);
- await documentFileStorage.removeItem(key);
+ const document = await documentStorage.getItem(key);
+ assert(document, { status: 404 });
+
+ const now = new Date();
+
+ document.deletedAt = now;
+ document.updatedAt = now;
+ document.deletedBy = 'usr_1';
+
+ await documentStorage.setItem(key, document);
},
}),
diff --git a/apps/papra-client/src/modules/documents/components/documents-list.component.tsx b/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
index c556b1f3..0a8205c8 100644
--- a/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
+++ b/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
@@ -12,6 +12,7 @@ import { A } from '@solidjs/router';
import { createSolidTable, flexRender, getCoreRowModel, getPaginationRowModel } from '@tanstack/solid-table';
import { type Accessor, type Component, For, Match, type Setter, Show, Switch } from 'solid-js';
import { getDocumentIcon } from '../document.models';
+import { DocumentManagementDropdown } from './document-management-dropdown.component';
type Pagination = {
pageIndex: number;
@@ -30,6 +31,16 @@ export const deletedAtColumn: ColumnDef<Document> = {
cell: data => <div class="text-muted-foreground hidden sm:block" title={data.getValue<Date>().toLocaleString()}>{timeAgo({ date: data.getValue<Date>() })}</div>,
};
+export const standardActionsColumn: ColumnDef<Document> = {
+ header: () => (<span class="block text-right">Actions</span>),
+ id: 'actions',
+ cell: data => (
+ <div class="flex items-center justify-end">
+ <DocumentManagementDropdown documentId={data.row.original.id} organizationId={data.row.original.organizationId} />
+ </div>
+ ),
+};
+
export const DocumentsPaginatedList: Component<{
documents: Document[];
documentsCount: number;
diff --git a/apps/papra-client/src/modules/documents/documents.types.ts b/apps/papra-client/src/modules/documents/documents.types.ts
index 03bccc7b..9ff0fa20 100644
--- a/apps/papra-client/src/modules/documents/documents.types.ts
+++ b/apps/papra-client/src/modules/documents/documents.types.ts
@@ -7,4 +7,5 @@ export type Document = {
createdAt: Date;
updatedAt?: Date;
deletedAt?: Date;
+ deletedBy?: string;
};
diff --git a/apps/papra-client/src/modules/documents/pages/documents.page.tsx b/apps/papra-client/src/modules/documents/pages/documents.page.tsx
index ebe33333..46f2d55f 100644
--- a/apps/papra-client/src/modules/documents/pages/documents.page.tsx
+++ b/apps/papra-client/src/modules/documents/pages/documents.page.tsx
@@ -9,7 +9,7 @@ import { createQueries, keepPreviousData } from '@tanstack/solid-query';
import { type Component, createSignal, Suspense } from 'solid-js';
import { DocumentManagementDropdown } from '../components/document-management-dropdown.component';
import { DocumentUploadArea } from '../components/document-upload-area.component';
-import { DocumentsPaginatedList } from '../components/documents-list.component';
+import { createdAtColumn, DocumentsPaginatedList, standardActionsColumn } from '../components/documents-list.component';
import { getDocumentIcon } from '../document.models';
import { fetchOrganizationDocuments } from '../documents.services';
@@ -117,9 +117,12 @@ export const DocumentsPage: Component = () => {
documentsCount={query[0].data?.documentsCount ?? 0}
getPagination={getPagination}
setPagination={setPagination}
+ extraColumns={[
+ createdAtColumn,
+ standardActionsColumn,
+ ]}
/>
</>
-
)}
</Suspense>
</div>