cleanup
This commit is contained in:
@@ -38,12 +38,12 @@ interface DescribeSummaryOptions {
|
||||
export interface DocumentSummaryRow {
|
||||
key: string;
|
||||
label: string;
|
||||
value: string | null | undefined;
|
||||
value: string | null;
|
||||
}
|
||||
|
||||
export interface DocumentSummary {
|
||||
title: string | undefined;
|
||||
originalName: string | null | undefined;
|
||||
originalName: string | null;
|
||||
mimeTypeLabel: string;
|
||||
sizeLabel: string;
|
||||
createdAtLabel: string;
|
||||
@@ -51,7 +51,7 @@ export interface DocumentSummary {
|
||||
updatedAtLabel: string;
|
||||
pageCount: number | null;
|
||||
pageCountLabel: string;
|
||||
folderLabel: string | null | undefined;
|
||||
folderLabel: string | null;
|
||||
tags: TagEntry[];
|
||||
correspondents: CorrespondentEntry[];
|
||||
tagsSummary: string;
|
||||
@@ -59,7 +59,7 @@ export interface DocumentSummary {
|
||||
summaryRows: DocumentSummaryRow[];
|
||||
}
|
||||
|
||||
const coercePageCount = (metadata: DocumentMetadata | null | undefined): number | null => {
|
||||
const coercePageCount = (metadata?: DocumentMetadata | null): number | null => {
|
||||
const raw = metadata?.page_count;
|
||||
if (raw == null || raw === '') {
|
||||
return null;
|
||||
@@ -68,7 +68,7 @@ const coercePageCount = (metadata: DocumentMetadata | null | undefined): number
|
||||
return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
|
||||
};
|
||||
|
||||
const sanitizeArray = <T>(entries: (T | null | undefined)[] | null | undefined): T[] =>
|
||||
const sanitizeArray = <T>(entries?: Array<T | null> | null): T[] =>
|
||||
Array.isArray(entries) ? entries.filter(Boolean) as T[] : [];
|
||||
|
||||
export const describeDocumentSummary = (document?: SummaryDocument | null, options: DescribeSummaryOptions = {}): DocumentSummary => {
|
||||
@@ -79,7 +79,7 @@ export const describeDocumentSummary = (document?: SummaryDocument | null, optio
|
||||
if (!document) {
|
||||
return {
|
||||
title: '',
|
||||
originalName: '',
|
||||
originalName: null,
|
||||
mimeTypeLabel: '—',
|
||||
sizeLabel: '—',
|
||||
createdAtLabel: '—',
|
||||
@@ -110,7 +110,8 @@ export const describeDocumentSummary = (document?: SummaryDocument | null, optio
|
||||
const issuedLabel = formatDateTime(document.issued_at);
|
||||
const updatedAtLabel = formatDateTime(document.updated_at);
|
||||
|
||||
const folderLabel = document.folder_path;
|
||||
const folderLabel = document.folder_path ?? null;
|
||||
const displayFolderLabel = folderLabel ?? 'Documents';
|
||||
|
||||
const tags = sanitizeArray<TagEntry>(document.tags);
|
||||
const correspondents = sanitizeArray<CorrespondentEntry>(document.correspondents);
|
||||
@@ -130,7 +131,7 @@ export const describeDocumentSummary = (document?: SummaryDocument | null, optio
|
||||
{ key: 'issued', label: 'Issued', value: issuedLabel },
|
||||
{ key: 'pages', label: 'Pages', value: pageCountLabel },
|
||||
{ key: 'updated', label: 'Updated', value: updatedAtLabel },
|
||||
{ key: 'folder', label: 'Folder', value: folderLabel },
|
||||
{ key: 'folder', label: 'Folder', value: displayFolderLabel },
|
||||
{ key: 'tags', label: 'Tags', value: tagsSummary },
|
||||
{ key: 'correspondents', label: 'Correspondents', value: correspondentsSummary },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user