1- import { useEffect , useMemo , useState } from 'react' ;
2- import { PageAppSDK } from '@contentful/app-sdk ' ;
3- import { Button , Flex , Heading , Layout , Note , Paragraph } from '@contentful/f36-components ' ;
1+ import { useState } from 'react' ;
2+ import { Button , Flex , Heading , Layout , Paragraph } from '@contentful/f36-components ' ;
3+ import type { MappingReviewSuspendPayload , PreviewPayload } from '@types ' ;
44import Splitter from './Splitter' ;
5- import { MappingReviewSuspendPayload , PreviewPayload } from '@types' ;
65import { ConfirmCancelModal } from '../modals/ConfirmCancelModal' ;
7- import { loadGoogleDocsReviewData } from '../../../../fixtures/googleDocsReview' ;
8- import { GoogleDocsMappingReviewScreen } from '../review-prototype/GoogleDocsMappingReviewScreen' ;
9- import OverviewSection from '../overview/OverviewSection' ;
10- import { useSDK } from '@contentful/react-apps-toolkit' ;
11- import { PageAppSDK } from '@contentful/app-sdk' ;
6+ import { DocumentOutline } from '../review/DocumentOutline' ;
127import { isMappingReviewSuspendPayload } from '../../../../utils/utils' ;
138
149interface PreviewPageViewProps {
@@ -18,18 +13,23 @@ interface PreviewPageViewProps {
1813 onResumeMappingReview ?: ( ) => Promise < void > ;
1914}
2015
21- export const PreviewPageView = ( {
22- payload,
23- oauthToken,
24- onLeavePreview,
25- onResumeMappingReview,
26- } : PreviewPageViewProps ) => {
27- const sdk = useSDK < PageAppSDK > ( ) ;
16+ function hasEntryBlockGraph (
17+ payload : PreviewPayload | MappingReviewSuspendPayload
18+ ) : payload is
19+ | MappingReviewSuspendPayload
20+ | ( PreviewPayload & { entryBlockGraph : NonNullable < PreviewPayload [ 'entryBlockGraph' ] > } ) {
21+ return Boolean ( payload . entryBlockGraph ) ;
22+ }
23+
24+ export const PreviewPageView = ( { payload, onLeavePreview } : PreviewPageViewProps ) => {
2825 const [ isConfirmCancelModalOpen , setIsConfirmCancelModalOpen ] = useState ( false ) ;
29- const mappingReviewPayload = isMappingReviewSuspendPayload ( payload ) ? payload : null ;
30- const rawTitle = payload . normalizedDocument ?. title ;
31- const docTitle = typeof rawTitle === 'string' ? rawTitle : undefined ;
32- const title = docTitle && docTitle . trim ( ) . length > 0 ? docTitle : 'Selected document' ;
26+ const isMappingReviewMode = isMappingReviewSuspendPayload ( payload ) ;
27+
28+ const title = isMappingReviewMode
29+ ? `Review document "${
30+ payload . documentTitle ?? payload . normalizedDocument . title ?? payload . documentId
31+ } "`
32+ : `Create from document "${ payload . normalizedDocument . title ?? 'Selected document' } "` ;
3333
3434 return (
3535 < >
@@ -47,24 +47,19 @@ export const PreviewPageView = ({
4747 </ Layout . Header >
4848 < Splitter marginTop = "spacingS" />
4949 < Layout . Body >
50- { fixture ? < GoogleDocsMappingReviewScreen fixture = { fixture } /> : null }
51- < Flex flexDirection = "column" gap = "spacing2Xl" >
52- < OverviewSection
53- sdk = { sdk }
54- payload = { payload || fixture }
55- payload = { payload }
56- oauthToken = { oauthToken }
57- onReturnToMainPage = { onLeavePreview }
58- onCreateSelected = { mappingReviewPayload ? onResumeMappingReview : undefined }
59- />
60- < Heading as = "h2" marginBottom = "none" >
61- Document outline
62- </ Heading >
63- </ Flex >
50+ { /* TODO: Restore OverviewSection once it is compatible with EntryBlockGraph-based preview payloads. */ }
51+ { hasEntryBlockGraph ( payload ) ? (
52+ < DocumentOutline payload = { payload } showChrome = { false } />
53+ ) : (
54+ < Paragraph marginBottom = "none" >
55+ Preview overview is temporarily unavailable until the preview payload is compatible with
56+ EntryBlockGraph.
57+ </ Paragraph >
58+ ) }
6459 </ Layout . Body >
6560 < ConfirmCancelModal
6661 isOpen = { isConfirmCancelModalOpen }
67- onConfirm = { props . onCancel }
62+ onConfirm = { onLeavePreview }
6863 onCancel = { ( ) => setIsConfirmCancelModalOpen ( false ) }
6964 />
7065 </ >
0 commit comments