Skip to content

Commit 7d91c39

Browse files
committed
fix: revert overview section changes
1 parent b1ece2c commit 7d91c39

5 files changed

Lines changed: 11 additions & 332 deletions

File tree

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import type { EntryProps } from 'contentful-management';
1515
import { SummaryModal } from '../modals/SummaryModal';
1616
import { isPreviewPayload } from '../../../../utils/utils';
1717

18-
type OverviewSectionProps = {
18+
interface OverviewSectionProps {
1919
sdk: PageAppSDK;
2020
payload: PreviewPayload | MappingReviewSuspendPayload;
2121
oauthToken: string;
2222
onReturnToMainPage: () => void;
2323
onCreateSelected?: () => Promise<void>;
24-
};
24+
}
2525

2626
const OverviewSection = ({
2727
sdk,
@@ -168,16 +168,14 @@ const OverviewSection = ({
168168
)}
169169
</Flex>
170170

171-
{sdk ? (
172-
<SummaryModal
173-
isOpen={summaryEntries !== null}
174-
sdk={sdk}
175-
entries={summaryEntries ?? []}
176-
contentTypeDisplayInfoMap={contentTypeDisplayInfoMap}
177-
defaultLocale={sdk.locales.default}
178-
onDone={handleSummaryDone}
179-
/>
180-
) : null}
171+
<SummaryModal
172+
isOpen={summaryEntries !== null}
173+
sdk={sdk}
174+
entries={summaryEntries ?? []}
175+
contentTypeDisplayInfoMap={contentTypeDisplayInfoMap}
176+
defaultLocale={sdk.locales.default}
177+
onDone={handleSummaryDone}
178+
/>
181179
</Box>
182180
);
183181
};

apps/google-docs/src/utils/checkboxEntryList.ts

Lines changed: 1 addition & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { EntryToCreate, MappingReviewSuspendPayload, PreviewPayload } from '@types';
1+
import type { EntryToCreate, PreviewPayload } from '@types';
22
import { collectReferencedTempIdsFromEntry } from '../services/referenceResolution';
33
import { type ContentTypeDisplayInfo } from '../services/contentTypeService';
44
import { orderEntriesByCreationOrder } from './previewPayload';
55
import { getEntryDisplayTitle } from './getEntryDisplayTitle';
6-
import { isPreviewPayload } from './utils';
76

87
export interface CheckboxEntryListRow {
98
id: string;
@@ -15,12 +14,6 @@ export interface CheckboxEntryListRow {
1514

1615
export type ContentTypeDisplayInfoMap = ReadonlyMap<string, ContentTypeDisplayInfo>;
1716

18-
interface OverviewSourceEntry {
19-
tempId: string;
20-
contentTypeName: string;
21-
entryTitle?: string;
22-
}
23-
2417
interface OrderedEntriesContext {
2518
entries: EntryToCreate[];
2619
entriesByTempId: Map<string, EntryToCreate>;
@@ -34,17 +27,6 @@ interface TreeBuildContext {
3427
defaultLocale?: string;
3528
}
3629

37-
interface OverviewSourceTreeBuildContext {
38-
orderedEntriesContext: OrderedOverviewSourceEntriesContext;
39-
childTempIdsByParentTempId: Map<string, string[]>;
40-
}
41-
42-
interface OrderedOverviewSourceEntriesContext {
43-
entries: OverviewSourceEntry[];
44-
entriesByTempId: Map<string, OverviewSourceEntry>;
45-
orderedIndexByTempId: Map<string, number>;
46-
}
47-
4830
function resolveContentTypeLabel(
4931
contentTypeId: string,
5032
contentTypeDisplayInfoMap?: ContentTypeDisplayInfoMap
@@ -119,24 +101,6 @@ function buildOrderedEntriesContext(orderedEntries: EntryToCreate[]): OrderedEnt
119101
};
120102
}
121103

122-
function buildOrderedOverviewSourceEntriesContext(
123-
orderedEntries: OverviewSourceEntry[]
124-
): OrderedOverviewSourceEntriesContext {
125-
const entriesByTempId = new Map<string, OverviewSourceEntry>();
126-
const orderedIndexByTempId = new Map<string, number>();
127-
128-
orderedEntries.forEach((entry, index) => {
129-
entriesByTempId.set(entry.tempId, entry);
130-
orderedIndexByTempId.set(entry.tempId, index);
131-
});
132-
133-
return {
134-
entries: orderedEntries,
135-
entriesByTempId,
136-
orderedIndexByTempId,
137-
};
138-
}
139-
140104
function collectChildTempIds(childTempIdsByParentTempId: Map<string, string[]>): Set<string> {
141105
return new Set([...childTempIdsByParentTempId.values()].flat());
142106
}
@@ -163,35 +127,6 @@ function buildRowTreeForTempId(
163127
);
164128
}
165129

166-
function buildOverviewRow(
167-
entry: OverviewSourceEntry,
168-
entryIndex: number,
169-
children: CheckboxEntryListRow[]
170-
) {
171-
return {
172-
id: entry.tempId,
173-
entryIndex,
174-
contentTypeName: entry.contentTypeName,
175-
entryTitle: entry.entryTitle,
176-
children,
177-
};
178-
}
179-
180-
function buildOverviewRowTreeForTempId(
181-
tempId: string,
182-
context: OverviewSourceTreeBuildContext
183-
): CheckboxEntryListRow | undefined {
184-
const entry = context.orderedEntriesContext.entriesByTempId.get(tempId);
185-
if (!entry) return undefined;
186-
187-
const entryIndex = context.orderedEntriesContext.orderedIndexByTempId.get(tempId) ?? -1;
188-
const childRows = (context.childTempIdsByParentTempId.get(tempId) ?? [])
189-
.map((childTempId) => buildOverviewRowTreeForTempId(childTempId, context))
190-
.filter((row): row is CheckboxEntryListRow => row !== undefined);
191-
192-
return buildOverviewRow(entry, entryIndex, childRows);
193-
}
194-
195130
function buildTreeRootRows(
196131
context: TreeBuildContext,
197132
childTempIds: Set<string>
@@ -209,22 +144,6 @@ function buildTreeRootRows(
209144
return roots;
210145
}
211146

212-
function buildOverviewTreeRootRows(
213-
context: OverviewSourceTreeBuildContext,
214-
childTempIds: Set<string>
215-
): CheckboxEntryListRow[] {
216-
const roots: CheckboxEntryListRow[] = [];
217-
218-
for (const entry of context.orderedEntriesContext.entries) {
219-
if (childTempIds.has(entry.tempId)) continue;
220-
221-
const row = buildOverviewRowTreeForTempId(entry.tempId, context);
222-
if (row) roots.push(row);
223-
}
224-
225-
return roots;
226-
}
227-
228147
function buildFlatRows(
229148
orderedEntries: EntryToCreate[],
230149
contentTypeDisplayInfoMap?: ContentTypeDisplayInfoMap,
@@ -238,95 +157,12 @@ function buildFlatRows(
238157
return rows;
239158
}
240159

241-
function buildFlatOverviewRows(orderedEntries: OverviewSourceEntry[]): CheckboxEntryListRow[] {
242-
return orderedEntries.map((entry, index) => buildOverviewRow(entry, index, []));
243-
}
244-
245-
function orderMappingReviewEntriesByCreationOrder(
246-
entries: MappingReviewSuspendPayload['entryBlockGraph']['entries'],
247-
creationOrder: string[] | undefined
248-
): MappingReviewSuspendPayload['entryBlockGraph']['entries'] {
249-
if (!creationOrder || creationOrder.length === 0) {
250-
return entries;
251-
}
252-
253-
const byTempId = new Map<
254-
string,
255-
MappingReviewSuspendPayload['entryBlockGraph']['entries'][number]
256-
>();
257-
for (const entry of entries) {
258-
if (entry.tempId) {
259-
byTempId.set(entry.tempId, entry);
260-
}
261-
}
262-
263-
const ordered: MappingReviewSuspendPayload['entryBlockGraph']['entries'] = [];
264-
const placed = new Set<string>();
265-
266-
for (const tempId of creationOrder) {
267-
if (placed.has(tempId)) continue;
268-
const entry = byTempId.get(tempId);
269-
if (entry) {
270-
ordered.push(entry);
271-
placed.add(tempId);
272-
}
273-
}
274-
275-
for (const entry of entries) {
276-
if (!entry.tempId || !placed.has(entry.tempId)) {
277-
ordered.push(entry);
278-
if (entry.tempId) {
279-
placed.add(entry.tempId);
280-
}
281-
}
282-
}
283-
284-
return ordered;
285-
}
286-
287-
function buildChildTempIdsByParentTempIdFromReferenceGraph(
288-
orderedEntriesContext: OrderedOverviewSourceEntriesContext,
289-
referenceGraph: MappingReviewSuspendPayload['referenceGraph']
290-
): Map<string, string[]> {
291-
const childTempIdsByParentTempId = new Map<string, string[]>();
292-
const assignedChildIds = new Set<string>();
293-
const childTempIdsByParent = new Map<string, string[]>();
294-
295-
for (const edge of referenceGraph.edges ?? []) {
296-
if (typeof edge.from !== 'string' || typeof edge.to !== 'string') {
297-
continue;
298-
}
299-
300-
const existing = childTempIdsByParent.get(edge.from) ?? [];
301-
existing.push(edge.to);
302-
childTempIdsByParent.set(edge.from, existing);
303-
}
304-
305-
for (const entry of orderedEntriesContext.entries) {
306-
const referencedTempIds = childTempIdsByParent.get(entry.tempId) ?? [];
307-
308-
for (const referencedTempId of referencedTempIds) {
309-
if (referencedTempId === entry.tempId) continue;
310-
if (!orderedEntriesContext.entriesByTempId.has(referencedTempId)) continue;
311-
if (assignedChildIds.has(referencedTempId)) continue;
312-
313-
assignedChildIds.add(referencedTempId);
314-
const childTempIds = childTempIdsByParentTempId.get(entry.tempId) ?? [];
315-
childTempIds.push(referencedTempId);
316-
childTempIdsByParentTempId.set(entry.tempId, childTempIds);
317-
}
318-
}
319-
320-
return childTempIdsByParentTempId;
321-
}
322-
323160
export function buildCheckboxEntryList(
324161
payload: PreviewPayload,
325162
contentTypeDisplayInfoMap?: ContentTypeDisplayInfoMap,
326163
defaultLocale?: string
327164
): CheckboxEntryListRow[] {
328165
const { entries, referenceGraph } = payload;
329-
330166
if (entries.length === 0) {
331167
return [];
332168
}
@@ -352,57 +188,6 @@ export function buildCheckboxEntryList(
352188
return roots;
353189
}
354190

355-
export function buildCheckboxEntryListFromMappingReviewPayload(
356-
payload: MappingReviewSuspendPayload
357-
): CheckboxEntryListRow[] {
358-
const orderedGraphEntries = orderMappingReviewEntriesByCreationOrder(
359-
payload.entryBlockGraph.entries,
360-
payload.referenceGraph.creationOrder
361-
);
362-
363-
const orderedOverviewEntries: OverviewSourceEntry[] = orderedGraphEntries
364-
.map((entry) => {
365-
const tempId = entry.tempId?.trim();
366-
if (!tempId) {
367-
return null;
368-
}
369-
370-
const matchingContentType = payload.contentTypes.find(
371-
(contentType) => contentType.sys.id === entry.contentTypeId
372-
);
373-
374-
return {
375-
tempId,
376-
contentTypeName: matchingContentType?.name?.trim() || entry.contentTypeId,
377-
entryTitle: tempId,
378-
} satisfies OverviewSourceEntry;
379-
})
380-
.filter((entry): entry is OverviewSourceEntry => entry !== null);
381-
382-
if (orderedOverviewEntries.length === 0) {
383-
return [];
384-
}
385-
386-
const orderedEntriesContext = buildOrderedOverviewSourceEntriesContext(orderedOverviewEntries);
387-
const childTempIdsByParentTempId = buildChildTempIdsByParentTempIdFromReferenceGraph(
388-
orderedEntriesContext,
389-
payload.referenceGraph
390-
);
391-
const roots = buildOverviewTreeRootRows(
392-
{
393-
orderedEntriesContext,
394-
childTempIdsByParentTempId,
395-
},
396-
collectChildTempIds(childTempIdsByParentTempId)
397-
);
398-
399-
if (roots.length === 0) {
400-
return buildFlatOverviewRows(orderedOverviewEntries);
401-
}
402-
403-
return roots;
404-
}
405-
406191
export function collectCheckboxEntryListRowIds(rows: CheckboxEntryListRow[]): string[] {
407192
return rows.flatMap((row) => [row.id, ...collectCheckboxEntryListRowIds(row.children)]);
408193
}

apps/google-docs/src/utils/previewPayload.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type {
22
AssetToCreate,
3-
EntryBlockGraph,
43
EntryToCreate,
54
NormalizedDocument,
65
PreviewPayload,
@@ -65,23 +64,6 @@ function parseReferenceGraph(raw: unknown): ReviewedReferenceGraph | undefined {
6564
};
6665
}
6766

68-
function parseEntryBlockGraph(raw: unknown): EntryBlockGraph | undefined {
69-
if (raw === undefined) {
70-
return undefined;
71-
}
72-
73-
if (!isRecord(raw)) {
74-
throw new Error('entryBlockGraph must be an object when present.');
75-
}
76-
77-
return {
78-
entries: Array.isArray(raw.entries) ? (raw.entries as EntryBlockGraph['entries']) : [],
79-
excludedSourceRefs: Array.isArray(raw.excludedSourceRefs)
80-
? (raw.excludedSourceRefs as EntryBlockGraph['excludedSourceRefs'])
81-
: [],
82-
};
83-
}
84-
8567
/** Order entries by `referenceGraph.creationOrder`, then append any missing entries (original order). */
8668
export function orderEntriesByCreationOrder(
8769
entries: EntryToCreate[],
@@ -184,13 +166,11 @@ export function validatePayloadShape(payload: unknown): PreviewPayload {
184166
const referenceGraph = parseReferenceGraph(payload.referenceGraph);
185167

186168
const normalizedDocument = parseNormalizedDocument(payload.normalizedDocument);
187-
const entryBlockGraph = parseEntryBlockGraph(payload.entryBlockGraph);
188169

189170
return {
190171
entries: payload.entries as EntryToCreate[],
191172
assets,
192173
referenceGraph: referenceGraph ?? {},
193174
normalizedDocument,
194-
entryBlockGraph,
195175
};
196176
}

0 commit comments

Comments
 (0)