folder in summary
This commit is contained in:
@@ -34,6 +34,7 @@ interface DocumentLike {
|
||||
title?: string;
|
||||
content_type?: string | null;
|
||||
issued_at?: string | null;
|
||||
folder_id?: string | null;
|
||||
correspondents?: Array<{ id?: string | number; name?: string }>;
|
||||
current_version?: {
|
||||
version_number?: number;
|
||||
@@ -56,11 +57,6 @@ interface AssetLike {
|
||||
|
||||
interface DocumentViewerPanelProps extends DocumentSummarySectionProps {
|
||||
document: DocumentLike | null;
|
||||
documentLink?: {
|
||||
url?: string;
|
||||
contentType?: string | null;
|
||||
filename?: string | null;
|
||||
} | null;
|
||||
ensureAssetUrl?: (docId: string | number, asset: AssetLike, options?: { force?: boolean }) => Promise<unknown>;
|
||||
getDocumentAsset?: (doc: DocumentLike | null, type: string) => AssetLike | null;
|
||||
ensurePreviewData?: (docId: string | number, options?: { signal?: AbortSignal }) => Promise<DocumentLike | null>;
|
||||
@@ -78,7 +74,6 @@ interface DocumentViewerPanelProps extends DocumentSummarySectionProps {
|
||||
export const createDocumentViewerHeaderActions = ({
|
||||
document,
|
||||
actionState,
|
||||
documentLink,
|
||||
onZoom,
|
||||
canZoom = false,
|
||||
}) => {
|
||||
@@ -86,7 +81,7 @@ export const createDocumentViewerHeaderActions = ({
|
||||
return null;
|
||||
}
|
||||
|
||||
const downloadHref = actionState?.downloadHref || documentLink?.url;
|
||||
const downloadHref = actionState?.downloadHref;
|
||||
if (!downloadHref && !(canZoom && onZoom)) {
|
||||
return null;
|
||||
}
|
||||
@@ -122,7 +117,6 @@ export const createDocumentViewerHeaderActions = ({
|
||||
|
||||
const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
document,
|
||||
documentLink,
|
||||
tagLookupById,
|
||||
tagOptions,
|
||||
onTagAdd,
|
||||
@@ -168,6 +162,16 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
return Boolean(getDocumentAsset(document, 'ocr-text'));
|
||||
}, [document, getDocumentAsset]);
|
||||
|
||||
const navigateToFolder = useCallback(
|
||||
(folderId) => {
|
||||
const target = folderId == null
|
||||
? '/documents'
|
||||
: `/documents/folder/${folderId}`;
|
||||
navigate(target);
|
||||
},
|
||||
[navigate],
|
||||
);
|
||||
|
||||
const summaryProps = useMemo(
|
||||
() => ({
|
||||
tagLookupById,
|
||||
@@ -180,6 +184,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
onCorrespondentRemove,
|
||||
onUpdateTitle,
|
||||
onUpdateIssued,
|
||||
onFolderNavigate: navigateToFolder,
|
||||
}),
|
||||
[
|
||||
tagLookupById,
|
||||
@@ -192,6 +197,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
onCorrespondentRemove,
|
||||
onUpdateTitle,
|
||||
onUpdateIssued,
|
||||
navigateToFolder,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -251,7 +257,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
|
||||
const [zoomOverlayOpen, setZoomOverlayOpen] = useState(false);
|
||||
|
||||
const fallbackDocumentLink = useMemo(() => {
|
||||
const resolvedDocumentLink = useMemo(() => {
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
@@ -272,14 +278,12 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
};
|
||||
}, [document, resolveApiPath]);
|
||||
|
||||
const effectiveDocumentLink = documentLink?.url ? documentLink : fallbackDocumentLink;
|
||||
|
||||
const handleZoomOpen = useCallback(() => {
|
||||
if (!effectiveDocumentLink?.url) {
|
||||
if (!resolvedDocumentLink?.url) {
|
||||
return;
|
||||
}
|
||||
setZoomOverlayOpen(true);
|
||||
}, [effectiveDocumentLink?.url]);
|
||||
}, [resolvedDocumentLink?.url]);
|
||||
|
||||
const handleZoomClose = useCallback(() => {
|
||||
setZoomOverlayOpen(false);
|
||||
@@ -287,7 +291,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
setZoomOverlayOpen(false);
|
||||
}, [effectiveDocumentLink?.url, document?.id]);
|
||||
}, [resolvedDocumentLink?.url, document?.id]);
|
||||
|
||||
const panelRef = useRef<HTMLDivElement | HTMLFormElement | HTMLElement | null>(null);
|
||||
const isStackedLayout = useViewerLayoutMode(panelRef, document?.id);
|
||||
@@ -344,19 +348,6 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
];
|
||||
}, [document, resolveFolderPath]);
|
||||
|
||||
const handleBreadcrumbNavigate = useCallback(
|
||||
(crumb) => {
|
||||
if (!crumb?.id) {
|
||||
return;
|
||||
}
|
||||
const target = crumb.id === 'root'
|
||||
? '/documents'
|
||||
: `/documents/folder/${crumb.id}`;
|
||||
navigate(target);
|
||||
},
|
||||
[navigate],
|
||||
);
|
||||
|
||||
const breadcrumbTrailEntries = useMemo(() => {
|
||||
if (!breadcrumbs.length) {
|
||||
return [];
|
||||
@@ -365,28 +356,27 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
return breadcrumbs.map((crumb, index) => ({
|
||||
id: crumb.id,
|
||||
label: crumb.name,
|
||||
onClick: index < lastIndex ? () => handleBreadcrumbNavigate(crumb) : null,
|
||||
onClick: index < lastIndex ? () => navigateToFolder(crumb.id) : null,
|
||||
}));
|
||||
}, [breadcrumbs, handleBreadcrumbNavigate]);
|
||||
}, [breadcrumbs, navigateToFolder]);
|
||||
|
||||
const zoomDisplay = useMemo(() => {
|
||||
if (!effectiveDocumentLink?.url || !document) {
|
||||
if (!resolvedDocumentLink?.url || !document) {
|
||||
return null;
|
||||
}
|
||||
const docContentType = document.content_type;
|
||||
const versionContentType = document.current_version?.version?.content_type;
|
||||
const normalizedContentType = effectiveDocumentLink.contentType || docContentType || versionContentType || null;
|
||||
const normalizedContentType = resolvedDocumentLink.contentType || docContentType || versionContentType || null;
|
||||
return {
|
||||
url: effectiveDocumentLink.url,
|
||||
url: resolvedDocumentLink.url,
|
||||
alt: document.title,
|
||||
contentType: normalizedContentType || undefined,
|
||||
};
|
||||
}, [effectiveDocumentLink?.url, effectiveDocumentLink?.contentType, document]);
|
||||
}, [resolvedDocumentLink?.url, resolvedDocumentLink?.contentType, document]);
|
||||
|
||||
const headerActions = createDocumentViewerHeaderActions({
|
||||
document,
|
||||
actionState,
|
||||
documentLink: effectiveDocumentLink,
|
||||
onZoom: zoomDisplay ? handleZoomOpen : null,
|
||||
canZoom: Boolean(zoomDisplay),
|
||||
});
|
||||
@@ -486,7 +476,7 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
|
||||
<section className={viewerClassName}>
|
||||
<DocumentViewerLayout
|
||||
document={document}
|
||||
documentLink={effectiveDocumentLink}
|
||||
documentLink={resolvedDocumentLink}
|
||||
summaryProps={summaryProps}
|
||||
metadataPayload={metadataPayload}
|
||||
contentTabConfig={contentTabConfig}
|
||||
|
||||
Reference in New Issue
Block a user