feat(drive-integration): async import runs rearchitecture [INTEG-4526]#11092
feat(drive-integration): async import runs rearchitecture [INTEG-4526]#11092david-shibley-contentful wants to merge 6 commits into
Conversation
3ca6d78 to
4bc5d43
Compare
Rearchitects the drive-integration import flow from synchronous (20-min blocking spinner) to fully async. Import wizard fires off the agent run, saves a RunRecord to localStorage, then immediately redirects to a new Runs page. The Runs page polls agentRun status every 10s for in-flight imports and supports multiple concurrent runs. ReviewPage is now reachable directly from the Runs page rather than only from the wizard flow. Key changes: - New RunsPage (home screen) + RunRow components with live status badges - useRunStorage hook (localStorage-backed RunRecord[] with 50-record cap) - useRunsPolling hook (parallel Promise.all, 10s interval while running) - workflowService.ts extracted from useWorkflowAgent (resumeAndPollWorkflow) - Page.tsx rewritten around AppView discriminated union state machine - ModalOrchestrator: fire-and-forget startWorkflow → addRun → onRunStarted - 104 tests passing across all new and modified files Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…table after import Three independent useRunStorage instances (Page, RunsPage, ModalOrchestrator) meant addRun() only updated local React state — RunsPage wouldn't see the new run without a page refresh. Lift the hook to Page as the single owner and pass runs/addRun/ removeRun/storageError down as props. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2734bc2 to
2d23ce1
Compare
…y ESLint Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ixtures from branch Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…E_ENABLE_MOCK_REVIEW_PAYLOAD branch Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| const handleCancelReview = async (runId?: string) => { | ||
| if (runId) { | ||
| try { | ||
| await resumeAndPollWorkflow(sdk, runId, { cancelled: true }); |
There was a problem hiding this comment.
⚔️ This is missing the entryBlockGraph. I think we want it for logging purposes
| onRunStarted={handleRunStarted} | ||
| onResetToMain={() => setAppView({ view: 'runs' })} |
There was a problem hiding this comment.
💭 These props do the same thing, setAppView({ view: 'runs' })
| const handleExitReview = () => { | ||
| modalOrchestratorRef.current?.resetFlow(); | ||
| handleReturnToMainPage(); | ||
| setAppView({ view: 'runs' }); |
There was a problem hiding this comment.
💭 Same logic as handleRunStarted(), would replace with that
| {run.createdEntryIds.map((entryId) => ( | ||
| <TextLink | ||
| key={entryId} | ||
| href={`https://app.contentful.com/spaces/${spaceId}/entries/${entryId}`} |
There was a problem hiding this comment.
❓ Should this use : sdk.hostnames.webapp instead of https://app.contentful.com ?
| default: | ||
| return 'expired'; | ||
| } | ||
| } |
There was a problem hiding this comment.
🤔 This could be a map, instead of s switch. Similar to what we do for FAILURE_REASON_MESSAGES
| const runId = await startWorkflow(contentTypeIds, documentSelection); | ||
|
|
||
| if (storageError) { | ||
| // Storage unavailable — surface error before proceeding | ||
| showWorkflowError( | ||
| new WorkflowRunError( | ||
| 'Unable to track this import: browser storage is unavailable or full.', | ||
| WorkflowFailureReason.GENERIC | ||
| ) | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
❓ Do we want to start the workflow even if we've got no storage? How is the user going to be able to see the run?
| onDismiss: (runId: string) => void; | ||
| } | ||
|
|
||
| function formatDate(iso: string): string { |
There was a problem hiding this comment.
⛏️ This manual format handling could be avoided if use a library like Dayjs
| payload: MappingReviewSuspendPayload; | ||
| runId?: string; | ||
| } | null>(null); | ||
| const [appView, setAppView] = useState<AppView>({ view: 'runs' }); |
There was a problem hiding this comment.
💭 Could we move runId outside AppView type? It makes AppView type a bit inconsistent. This could also make simpler with UseEffect in line 41
| if (appView.view !== 'review') { | ||
| setPendingReviewPayload(null); | ||
| return; |
There was a problem hiding this comment.
| if (appView.view !== 'review') { | |
| setPendingReviewPayload(null); | |
| return; | |
| if (appView.view !== 'review') { | |
| setPendingReviewPayload(null); | |
| setIsLoadingReviewPayload(false); | |
| return; |
| errorMessage?: string; | ||
| } | ||
|
|
||
| export type AppView = { view: 'runs' } | { view: 'import' } | { view: 'review'; runId: string }; |
There was a problem hiding this comment.
💭 runs, import and review could be an enum
There was a problem hiding this comment.
❓ Should we allow the user to a way clear the runs they have on the page? So they can free space on the localstorage as well
There was a problem hiding this comment.
Also if a run stuck in 'running' has no action button. The user can't dismiss it, can't cancel it, can't do anything. It just sits there with a spinner.
There was a problem hiding this comment.
Nice work! They way I review PRs:
⛏️ Nitpicks, non blockers
💭 / 🤔 Highly suggested, but non blockers
❓ Question, may be blocking or not depending on the answer
⚔️ Blockers
After testing it locally: There seems to be a bug with the document title that keep it as Untitled document instead of the actual title. We are also showing the entry id instead of the name in the RunPage

There was a problem hiding this comment.
💭 I think we no longer need the loading step for the ModalOrchestrator
INTEG-4526
Summary
Key files
src/types/runs.ts—RunRecord,DisplayStatus,RunWithStatus,AppViewtypessrc/hooks/useRunStorage.ts— localStorage-backed run history (max 50, scoped by space+env)src/hooks/useRunsPolling.ts— parallelPromise.allpolling, 10s interval while runningsrc/services/workflowService.ts—resumeAndPollWorkflowextracted from the hooksrc/locations/Page/components/runs/—RunsPage+RunRowcomponentssrc/locations/Page/Page.tsx—AppViewdiscriminated union state machine replaces binary togglesrc/locations/Page/components/mainpage/ModalOrchestrator.tsx— fire-and-forget wizard exitTest plan
npm testacross all modified files)tsc --noEmit)npm run build)Generated with Claude Code