From d5bc1bcee0149adf7ddf1fcacfe1f3223e0f6955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20P=C3=B6ttker?= Date: Tue, 26 May 2026 07:01:39 +0200 Subject: [PATCH] fix: handle object-format select_options from Paperless for Freigabe field Paperless may return extra_data.select_options as an array of objects {id, label} instead of plain strings. This caused React error #31 when Ant Design tried to render an object as a child in the Select and Table components. - Backend: coerce option items to {id: string, label: string} regardless of whether Paperless returns strings or objects - Frontend: normalize cf.value to a plain string before rendering or storing in state, guarding against object-typed values Co-Authored-By: Claude Sonnet 4.6 --- .../src/freigabe/freigabe.service.ts | 16 +++++++++++++--- paperless-frontend/src/pages/FreigabePage.tsx | 17 +++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/paperless-backend/src/freigabe/freigabe.service.ts b/paperless-backend/src/freigabe/freigabe.service.ts index 043324b..3f5c2c8 100644 --- a/paperless-backend/src/freigabe/freigabe.service.ts +++ b/paperless-backend/src/freigabe/freigabe.service.ts @@ -98,9 +98,19 @@ export class FreigabeService { const field = (fields as any[]).find((f: any) => f.id === FREIGABE_FIELD_ID); if (!field) return []; - const options: string[] = field.extra_data?.select_options ?? []; - return options + const rawOptions: any[] = field.extra_data?.select_options ?? []; + return rawOptions .filter((o) => o !== null && o !== undefined && o !== '') - .map((o) => ({ id: o, label: o })); + .map((o) => { + if (typeof o === 'object') { + // Paperless kann select_options als Objekte liefern + return { + id: String(o.id ?? o.value ?? o.label ?? ''), + label: String(o.label ?? o.name ?? o.id ?? ''), + }; + } + return { id: String(o), label: String(o) }; + }) + .filter((o) => o.id !== ''); } } diff --git a/paperless-frontend/src/pages/FreigabePage.tsx b/paperless-frontend/src/pages/FreigabePage.tsx index 4502ca3..d6c1b18 100644 --- a/paperless-frontend/src/pages/FreigabePage.tsx +++ b/paperless-frontend/src/pages/FreigabePage.tsx @@ -67,19 +67,24 @@ export default function FreigabePage() { return correspondents.find((c) => c.id === id)?.name ?? String(id); }; + const toCfString = (value: any): string | null => { + if (value === null || value === undefined || value === '') return null; + if (typeof value === 'object') return String(value?.id ?? value?.value ?? value?.label ?? '') || null; + return String(value); + }; + const getFreigabeValue = (doc: FreigabeDocument) => { const cf = doc.custom_fields?.find((f) => f.field === FREIGABE_FIELD_ID); - if (!cf || cf.value === null || cf.value === '' || cf.value === undefined) { - return Nicht gesetzt; - } - const opt = freigabeOptions.find((o) => String(o.id) === String(cf.value)); - return {opt?.label ?? String(cf.value)}; + const cfStr = toCfString(cf?.value); + if (!cfStr) return Nicht gesetzt; + const opt = freigabeOptions.find((o) => o.id === cfStr); + return {opt?.label ?? cfStr}; }; const openModal = (doc: FreigabeDocument) => { const cf = doc.custom_fields?.find((f) => f.field === FREIGABE_FIELD_ID); setSelectedDoc(doc); - setSelectedValue(cf?.value ?? null); + setSelectedValue(toCfString(cf?.value)); setModalOpen(true); };