This commit is contained in:
2025-10-31 00:28:48 +01:00
parent 813ce24aeb
commit 39d1d80383
8 changed files with 103 additions and 118 deletions
+47 -46
View File
@@ -30,12 +30,9 @@ const derivePreviewOrientation = (metadata) => {
const sortCorrespondents = (entries = []) =>
entries
.map((entry) => ({
id: entry.id,
name: entry.name || '',
count: entry.count,
}))
.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
.filter((entry) => entry && entry.name)
.map(({ id, name, count }) => ({ id, name, count }))
.sort((a, b) => a.name.localeCompare(b.name));
const resolveDocumentType = (doc) => {
if (!doc) {
@@ -46,15 +43,8 @@ const resolveDocumentType = (doc) => {
if (!type) {
return null;
}
if (typeof type === 'string') {
const name = type.trim();
if (!name) {
return null;
}
return { id: fallbackId, name };
}
if (typeof type === 'object') {
const name = (type.name || type.label || '').trim();
if (typeof type === 'object' && typeof type.name === 'string') {
const name = type.name.trim();
if (!name) {
return null;
}
@@ -265,7 +255,7 @@ const PreviewStack = ({
>
<img
src={entry.url}
alt={entry.alt || ''}
alt={entry.alt}
className="preview-stack__image"
onClick={(event) => {
event.stopPropagation();
@@ -405,7 +395,7 @@ const DetailPanel = ({
const startTitleEdit = useCallback(() => {
if (!singleDoc) return;
setTitleEditDocId(singleDoc.id);
setTitleDraft(singleDoc.title || singleDoc.original_name || '');
setTitleDraft(singleDoc.title || singleDoc.original_name);
setTitleError(null);
}, [singleDoc]);
@@ -576,14 +566,15 @@ const DetailPanel = ({
const tagMap = new Map();
selectedDocuments.forEach((doc) => {
(doc.tags || []).forEach((tag) => {
const label = (tag?.label || '').trim();
if (!tag?.label) return;
const label = tag.label.trim();
if (!label) return;
if (!tagMap.has(label)) {
const fallback = tagLookupById.get(tag.id) || {};
const fallback = tagLookupById.get(tag.id);
tagMap.set(label, {
id: tag.id,
label,
color: tag.color || fallback.color,
color: tag.color ?? fallback?.color ?? null,
});
}
});
@@ -608,32 +599,42 @@ const DetailPanel = ({
const correspondentOptions = useMemo(() => {
const seen = new Set();
return availableCorrespondents
.map((entry) => (entry?.name || '').trim())
.filter((name) => {
if (!name) return false;
const lower = name.toLowerCase();
if (seen.has(lower)) {
return false;
}
seen.add(lower);
return true;
});
return availableCorrespondents.reduce((options, entry) => {
if (typeof entry?.name !== 'string') {
return options;
}
const name = entry.name.trim();
if (!name) {
return options;
}
const lower = name.toLowerCase();
if (seen.has(lower)) {
return options;
}
seen.add(lower);
options.push(name);
return options;
}, []);
}, [availableCorrespondents]);
const documentTypeOptions = useMemo(() => {
const seen = new Set();
return (documentTypes || [])
.map((entry) => (entry?.name || '').trim())
.filter((name) => {
if (!name) return false;
const lower = name.toLowerCase();
if (seen.has(lower)) {
return false;
}
seen.add(lower);
return true;
});
return (documentTypes || []).reduce((options, entry) => {
if (typeof entry?.name !== 'string') {
return options;
}
const name = entry.name.trim();
if (!name) {
return options;
}
const lower = name.toLowerCase();
if (seen.has(lower)) {
return options;
}
seen.add(lower);
options.push(name);
return options;
}, []);
}, [documentTypes]);
const singleDocumentType = useMemo(() => resolveDocumentType(singleDoc), [singleDoc]);
@@ -751,11 +752,11 @@ const DetailPanel = ({
selectedDocuments.forEach((doc) => {
if (!doc?.id) return;
(doc.correspondents || []).forEach((entry) => {
if (!entry?.id) return;
if (!entry?.id || typeof entry.name !== 'string') return;
if (!map.has(entry.id)) {
map.set(entry.id, {
id: entry.id,
name: entry.name || '',
name: entry.name,
documentIds: new Set(),
});
}
@@ -770,7 +771,7 @@ const DetailPanel = ({
documentIds: [...entry.documentIds],
count: entry.documentIds.size,
}))
.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
.sort((a, b) => a.name.localeCompare(b.name));
}, [selectedDocuments]);
const bulkDocumentTypes = useMemo(() => {
@@ -789,7 +790,7 @@ const DetailPanel = ({
map.get(key).count += 1;
});
return [...map.values()].sort((a, b) => (a.name || '').localeCompare(b.name || ''));
return [...map.values()].sort((a, b) => a.name.localeCompare(b.name));
}, [selectedDocuments]);
const bulkDocumentTypeSummary = useMemo(() => {