Skip to content

Commit 806b561

Browse files
committed
refactor: remove fixture-loader and related types, integrate DocumentOutline for mapping review
1 parent 64e1da0 commit 806b561

18 files changed

Lines changed: 158 additions & 383 deletions

File tree

apps/google-docs/src/fixtures/googleDocsReview/fixture-loader.ts

Lines changed: 0 additions & 158 deletions
This file was deleted.

apps/google-docs/src/fixtures/googleDocsReview/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/google-docs/src/locations/Page/Page.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MainPageView } from './components/mainpage/MainPageView';
1010
import { PreviewPageView } from './components/mainpage/PreviewPageView';
1111
import { MappingReviewSuspendPayload, PreviewPayload } from '@types';
1212
import { isMappingReviewSuspendPayload } from '../../utils/utils';
13+
import fixtureReviewPayload from '../../fixtures/googleDocsReview/fixture.json';
1314

1415
const Page = () => {
1516
const sdk = useSDK<PageAppSDK>();
@@ -38,8 +39,6 @@ const Page = () => {
3839
};
3940

4041
const handlePreviewReady = (payload: PreviewPayload) => {
41-
setIsMappingPrototypeVisible(false);
42-
setMappingReviewPayload(null);
4342
setPreviewPayload(payload);
4443
};
4544

@@ -48,8 +47,6 @@ const Page = () => {
4847
};
4948

5049
const handleReturnToMainPage = () => {
51-
setIsMappingPrototypeVisible(false);
52-
setMappingReviewPayload(null);
5350
setPreviewPayload(null);
5451
};
5552

@@ -66,8 +63,6 @@ const Page = () => {
6663
}
6764
};
6865

69-
console.log('previewPayload', previewPayload);
70-
7166
return (
7267
<>
7368
<Layout withBoxShadow={true} offsetTop={10}>
@@ -87,7 +82,9 @@ const Page = () => {
8782
onOauthTokenChange={handleOauthTokenChange}
8883
onLoadingStateChange={handleOAuthLoadingStateChange}
8984
onSelectFile={handleSelectFile}
90-
onUseFixturePreview={() => setIsMappingPrototypeVisible(true)}
85+
onUseFixturePreview={() =>
86+
setPreviewPayload(fixtureReviewPayload as MappingReviewSuspendPayload)
87+
}
9188
sdk={sdk}
9289
/>
9390
)}

apps/google-docs/src/locations/Page/components/mainpage/PreviewPageView.tsx

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
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';
44
import Splitter from './Splitter';
5-
import { MappingReviewSuspendPayload, PreviewPayload } from '@types';
65
import { 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';
127
import { isMappingReviewSuspendPayload } from '../../../../utils/utils';
138

149
interface PreviewPageViewProps {
@@ -18,18 +13,19 @@ 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 = `Create from document "${payload.normalizedDocument.title ?? 'Selected document'}"`;
3329

3430
return (
3531
<>
@@ -47,24 +43,19 @@ export const PreviewPageView = ({
4743
</Layout.Header>
4844
<Splitter marginTop="spacingS" />
4945
<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>
46+
{/* TODO: Restore OverviewSection once it is compatible with EntryBlockGraph-based preview payloads. */}
47+
{hasEntryBlockGraph(payload) ? (
48+
<DocumentOutline payload={payload} showChrome={false} />
49+
) : (
50+
<Paragraph marginBottom="none">
51+
Preview overview is temporarily unavailable until the preview payload is compatible with
52+
EntryBlockGraph.
53+
</Paragraph>
54+
)}
6455
</Layout.Body>
6556
<ConfirmCancelModal
6657
isOpen={isConfirmCancelModalOpen}
67-
onConfirm={props.onCancel}
58+
onConfirm={onLeavePreview}
6859
onCancel={() => setIsConfirmCancelModalOpen(false)}
6960
/>
7061
</>

apps/google-docs/src/locations/Page/components/overview/OverviewSection.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Box, Button, Flex, Heading, Note, Paragraph } from '@contentful/f36-com
44
import type { MappingReviewSuspendPayload, PreviewPayload } from '@types';
55
import {
66
buildCheckboxEntryList,
7-
buildCheckboxEntryListFromMappingReviewPayload,
87
collectCheckboxEntryListRowIds,
98
type ContentTypeDisplayInfoMap,
109
} from '../../../../utils/checkboxEntryList';
@@ -16,13 +15,13 @@ import type { EntryProps } from 'contentful-management';
1615
import { SummaryModal } from '../modals/SummaryModal';
1716
import { isPreviewPayload } from '../../../../utils/utils';
1817

19-
type CreateOverviewSectionProps = {
18+
type OverviewSectionProps = {
2019
sdk: PageAppSDK;
2120
payload: PreviewPayload | MappingReviewSuspendPayload;
2221
oauthToken: string;
2322
onReturnToMainPage: () => void;
2423
onCreateSelected?: () => Promise<void>;
25-
}
24+
};
2625

2726
const OverviewSection = ({
2827
sdk,
@@ -66,11 +65,6 @@ const OverviewSection = ({
6665
}, [payload]);
6766

6867
useEffect(() => {
69-
if (isMappingReviewMode || !sdk) {
70-
setContentTypeDisplayInfoMap(undefined);
71-
return;
72-
}
73-
7468
const fetchContentTypesInfo = async () => {
7569
const contentTypeIds = [
7670
...new Set(overviewPayload.entries.map((entry) => entry.contentTypeId)),
@@ -130,9 +124,7 @@ const OverviewSection = ({
130124

131125
const handleSummaryDone = () => {
132126
setSummaryEntries(null);
133-
if ('onReturnToMainPage' in props) {
134-
props.onReturnToMainPage();
135-
}
127+
onReturnToMainPage();
136128
};
137129

138130
return (
@@ -149,9 +141,8 @@ const OverviewSection = ({
149141
Overview
150142
</Heading>
151143
<Paragraph marginBottom="none">
152-
{isMappingReviewMode
153-
? 'Review the entry structure produced for the mapping step. Entry creation continues after mapping review is complete.'
154-
: 'Review your content and associated entries below. Select which entries you&apos;d like to create.'}
144+
Review your content and associated entries below. Select which entries you&apos;d like
145+
to create.
155146
</Paragraph>
156147
</Flex>
157148
<Button
@@ -165,9 +156,8 @@ const OverviewSection = ({
165156

166157
{checkboxEntryRows.length === 0 ? (
167158
<Note variant="neutral">
168-
{isMappingReviewMode
169-
? 'No entry mappings are available yet. Once the mapping review payload is generated, the planned entries will appear here.'
170-
: 'No entries were found in this preview. When the document is parsed successfully, entries to create will appear here.'}
159+
No entries were found in this preview. When the document is parsed successfully, entries
160+
to create will appear here.
171161
</Note>
172162
) : (
173163
<CheckboxEntryList
@@ -178,7 +168,7 @@ const OverviewSection = ({
178168
)}
179169
</Flex>
180170

181-
{!isMappingReviewMode && sdk ? (
171+
{sdk ? (
182172
<SummaryModal
183173
isOpen={summaryEntries !== null}
184174
sdk={sdk}

0 commit comments

Comments
 (0)