feat: Remove documentLink prop and onNavigatorSnapshot logic, and add openDetailPanel and closeDetailPanel to document shell.

This commit is contained in:
2025-12-04 01:32:28 +01:00
parent 8bb9f9950a
commit 3f7c294948
9 changed files with 129 additions and 183 deletions
+16 -25
View File
@@ -6,12 +6,6 @@ import MediaViewer from './MediaViewer';
import type { Document } from '../types/documents';
interface DocumentLink {
url?: string;
mimeType?: string;
filename?: string;
}
interface ContentTabConfig {
id?: string;
label?: string;
@@ -29,7 +23,6 @@ type LayoutMode = 'split' | 'stacked' | (string & {});
interface DocumentViewerLayoutProps {
document?: Document | null;
documentLink?: DocumentLink | null;
summaryProps?: Record<string, unknown>;
metadataPayload?: unknown;
contentTabConfig?: ContentTabConfig | null;
@@ -43,7 +36,6 @@ interface DocumentViewerLayoutProps {
const DocumentViewerLayout = ({
document,
documentLink,
summaryProps = {},
metadataPayload,
contentTabConfig,
@@ -58,28 +50,27 @@ const DocumentViewerLayout = ({
const viewportRef = useRef<HTMLDivElement>(null);
const previewContent = useMemo(() => {
if (!document || !documentLink?.url) {
if (!document) {
return null;
}
const normalizedMimeType = (documentLink.mimeType
|| document.mime_type
|| '')
.toLowerCase();
const normalizedFilename = documentLink.filename
|| document.filename
|| document.original_name
|| '';
const downloadUrl = document.current_version?.download?.url;
if (!downloadUrl) {
return null;
}
const normalizedMimeType = (document.mime_type || '').toLowerCase();
const normalizedFilename = document.filename;
const isPdf = normalizedMimeType === 'application/pdf'
|| normalizedMimeType === 'application/x-pdf';
if (isPdf) {
const documentTitle = document.title
|| document.filename
|| document.original_name;
const documentTitle = document.title;
return (
<PdfViewer
src={documentLink.url}
src={downloadUrl}
title={documentTitle ? `Preview of ${documentTitle}` : undefined}
viewportRef={viewportRef}
/>
@@ -88,23 +79,23 @@ const DocumentViewerLayout = ({
return (
<MediaViewer
src={documentLink.url}
src={downloadUrl}
mimeType={normalizedMimeType}
filename={normalizedFilename}
alt={`Preview of ${document.title}`}
/>
);
}, [document, documentLink, viewportRef]);
}, [document, viewportRef]);
const renderViewportPane = useCallback(() => (
<div className="document-viewer__viewport" ref={viewportRef}>
{!documentLink?.url ? (
{!document?.current_version?.download?.url ? (
<div className="document-viewer__message">{previewLoadingMessage}</div>
) : (
previewContent
)}
</div>
), [previewContent, documentLink?.url, previewLoadingMessage, viewportRef]);
), [previewContent, document?.current_version?.download?.url, previewLoadingMessage, viewportRef]);
const viewportPane = renderViewportPane();
@@ -230,24 +230,6 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
const panelRef = useRef<HTMLDivElement | HTMLFormElement | HTMLElement | null>(null);
const isStackedLayout = useViewerLayoutMode(panelRef, document?.id);
const resolvedDocumentLink = useMemo(() => {
if (!document) {
return null;
}
const downloadUrl = document.current_version?.download?.url;
const href = downloadUrl;
if (!href) {
return null;
}
const mimeType = document.mime_type;
const filename = document.current_version?.filename || document.filename || document.title || null;
return {
url: href,
mimeType,
filename,
};
}, [document]);
const {
panelStyle: managedDetailPanelStyle,
handleProps: managedResizeHandleProps,
@@ -407,7 +389,6 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
<section className={viewerClassName}>
<DocumentViewerLayout
document={document}
documentLink={resolvedDocumentLink}
summaryProps={summaryProps}
metadataPayload={metadataPayload}
contentTabConfig={contentTabConfig}