Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor(wizard): split frontend into functional modules (#126498)

Fernando Gomesbbc92be3b13d
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e32736d9573d..1e3f5c29f309 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -17123,7 +17123,7 @@ snapshots:
scenes-other-welcome-dialog--no-inviter--light:
hash: v1.k794b7964.f766cbd27b7bc11b50ce42602ca2fcab11fa005e795aad0d66e6f67e627570d2.M3CFGWAqq3ebMX5h9Rlb9cCCOBUfhrdc86fQexL6-MA
scenes-other-welcome-dialog--provisioned--dark:
- hash: v1.k794b7964.4624c39797f30be4664c956382e53f065207d2a5c3c10dc923ef5d670a6c4cbd.wgrcJwwsFI0sB4jHPZb_jmpnhkoLO3TFXN5zkw3tPHo
+ hash: v1.k794b7964.7856b20e7f506517d1a2ab2ff089e93ae582d4d8556a99583463a2975e1e08f3.8x8nZe2vn54GB5JrYIRUel_SGBAtA11qvzkXnL0TUaw
scenes-other-welcome-dialog--provisioned--light:
hash: v1.k794b7964.fa2f4c4df2000b0aac6b2d030e35e09b87ccff491a31f6526b0510c497694c57.0RINcqkztk_dHUnIPDZmxsYcQaJuuv3XJPCtwFi8Yq8
scenes-other-welcome-flagshipproductscard--default--dark:
diff --git a/frontend/src/productScenes.tsx b/frontend/src/productScenes.tsx
index c49e2d9fe218..8d6a874666fd 100644
--- a/frontend/src/productScenes.tsx
+++ b/frontend/src/productScenes.tsx
@@ -214,7 +214,7 @@ export const productScenes: Record<string, () => Promise<any>> = {
HeatmapNew: () => import('../../products/web_analytics/frontend/heatmaps/scenes/heatmap/HeatmapNewScene'),
HeatmapRecording: () =>
import('../../products/web_analytics/frontend/heatmaps/scenes/heatmap/HeatmapRecordingScene'),
- WizardRuns: () => import('../../products/wizard/frontend/WizardRunsScene'),
+ WizardRuns: () => import('../../products/wizard/frontend/scenes/WizardRunsScene'),
Workflows: () => import('../../products/workflows/frontend/WorkflowsScene'),
Workflow: () => import('../../products/workflows/frontend/Workflows/WorkflowScene'),
WorkflowsLibraryTemplate: () => import('../../products/workflows/frontend/TemplateLibrary/MessageTemplate'),
diff --git a/products/wizard/frontend/runs/WizardRunDetailsArtifacts.tsx b/products/wizard/frontend/components/run-details/WizardRunDetailsArtifacts.tsx
similarity index 96%
rename from products/wizard/frontend/runs/WizardRunDetailsArtifacts.tsx
rename to products/wizard/frontend/components/run-details/WizardRunDetailsArtifacts.tsx
index ea8d3df62f67..dc9c2e479015 100644
--- a/products/wizard/frontend/runs/WizardRunDetailsArtifacts.tsx
+++ b/products/wizard/frontend/components/run-details/WizardRunDetailsArtifacts.tsx
@@ -13,9 +13,9 @@ import {
import { LinkPrimitive } from 'lib/lemon-ui/Link'
-import type { WizardRunApi, WizardRunArtifactApi, WizardRunGitDiffArtifactApi } from '../generated/api.schemas'
-import { formatArtifactSize } from '../wizardRunDisplay'
-import { WizardRunDiffStats } from './WizardRunDiffStats'
+import type { WizardRunApi, WizardRunArtifactApi, WizardRunGitDiffArtifactApi } from '../../generated/api.schemas'
+import { formatArtifactSize } from '../../lib/wizardRunDisplay'
+import { WizardRunDiffStats } from '../run-diff/WizardRunDiffStats'
export function WizardRunDetailsArtifacts({
run,
diff --git a/products/wizard/frontend/runs/WizardRunDiffStats.tsx b/products/wizard/frontend/components/run-diff/WizardRunDiffStats.tsx
similarity index 100%
rename from products/wizard/frontend/runs/WizardRunDiffStats.tsx
rename to products/wizard/frontend/components/run-diff/WizardRunDiffStats.tsx
diff --git a/products/wizard/frontend/runs/WizardRunDiffViewer.stories.tsx b/products/wizard/frontend/components/run-diff/WizardRunDiffViewer.stories.tsx
similarity index 100%
rename from products/wizard/frontend/runs/WizardRunDiffViewer.stories.tsx
rename to products/wizard/frontend/components/run-diff/WizardRunDiffViewer.stories.tsx
diff --git a/products/wizard/frontend/runs/WizardRunDiffViewer.test.tsx b/products/wizard/frontend/components/run-diff/WizardRunDiffViewer.test.tsx
similarity index 100%
rename from products/wizard/frontend/runs/WizardRunDiffViewer.test.tsx
rename to products/wizard/frontend/components/run-diff/WizardRunDiffViewer.test.tsx
diff --git a/products/wizard/frontend/runs/WizardRunDiffViewer.tsx b/products/wizard/frontend/components/run-diff/WizardRunDiffViewer.tsx
similarity index 99%
rename from products/wizard/frontend/runs/WizardRunDiffViewer.tsx
rename to products/wizard/frontend/components/run-diff/WizardRunDiffViewer.tsx
index 2f78e58577ea..a3a1073259b5 100644
--- a/products/wizard/frontend/runs/WizardRunDiffViewer.tsx
+++ b/products/wizard/frontend/components/run-diff/WizardRunDiffViewer.tsx
@@ -10,7 +10,7 @@ import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
-import { MAX_RENDERED_WIZARD_DIFF_LINES, wizardRunDiffCanRender } from '../wizardRunDisplay'
+import { MAX_RENDERED_WIZARD_DIFF_LINES, wizardRunDiffCanRender } from '../../lib/wizardRunDisplay'
const DIFF_THEME = { light: 'github-light', dark: 'github-dark' } as const
function DiffNotice({
diff --git a/products/wizard/frontend/runs/WizardRunEnvironmentTag.tsx b/products/wizard/frontend/components/run-tags/WizardRunEnvironmentTag.tsx
similarity index 86%
rename from products/wizard/frontend/runs/WizardRunEnvironmentTag.tsx
rename to products/wizard/frontend/components/run-tags/WizardRunEnvironmentTag.tsx
index cafb6fdc6d2c..29fa677c7bd1 100644
--- a/products/wizard/frontend/runs/WizardRunEnvironmentTag.tsx
+++ b/products/wizard/frontend/components/run-tags/WizardRunEnvironmentTag.tsx
@@ -1,7 +1,7 @@
import { IconCloud, IconLaptop } from '@posthog/icons'
import { Badge } from '@posthog/quill-primitives'
-import type { RunEnvironmentEnumApi } from '../generated/api.schemas'
+import type { RunEnvironmentEnumApi } from '../../generated/api.schemas'
export function WizardRunEnvironmentTag({ environment }: { environment: RunEnvironmentEnumApi }): JSX.Element {
return (
diff --git a/products/wizard/frontend/runs/WizardRunStatusTag.tsx b/products/wizard/frontend/components/run-tags/WizardRunStatusTag.tsx
similarity index 94%
rename from products/wizard/frontend/runs/WizardRunStatusTag.tsx
rename to products/wizard/frontend/components/run-tags/WizardRunStatusTag.tsx
index bdc2cff9cb52..f27bc9b6def1 100644
--- a/products/wizard/frontend/runs/WizardRunStatusTag.tsx
+++ b/products/wizard/frontend/components/run-tags/WizardRunStatusTag.tsx
@@ -1,7 +1,7 @@
import { IconCheckCircle, IconClock, IconX, IconXCircle } from '@posthog/icons'
import { Badge, Spinner } from '@posthog/quill-primitives'
-import type { WizardRunApi } from '../generated/api.schemas'
+import type { WizardRunApi } from '../../generated/api.schemas'
export function WizardRunStatusTag({ status }: { status: WizardRunApi['status'] }): JSX.Element {
if (status === 'completed') {
diff --git a/products/wizard/frontend/runs/WizardRunActionsMenu.tsx b/products/wizard/frontend/components/run/WizardRunActionsMenu.tsx
similarity index 94%
rename from products/wizard/frontend/runs/WizardRunActionsMenu.tsx
rename to products/wizard/frontend/components/run/WizardRunActionsMenu.tsx
index e03557ac0d17..eb21f7708ad2 100644
--- a/products/wizard/frontend/runs/WizardRunActionsMenu.tsx
+++ b/products/wizard/frontend/components/run/WizardRunActionsMenu.tsx
@@ -8,8 +8,8 @@ import {
DropdownMenuTrigger,
} from '@posthog/quill-primitives'
-import type { WizardRunApi } from '../generated/api.schemas'
-import { wizardRunCanCancel } from '../wizardRunDisplay'
+import type { WizardRunApi } from '../../generated/api.schemas'
+import { wizardRunCanCancel } from '../../lib/wizardRunDisplay'
export function WizardRunActionsMenu({
run,
diff --git a/products/wizard/frontend/runs/WizardRunProgress.tsx b/products/wizard/frontend/components/run/WizardRunProgress.tsx
similarity index 66%
rename from products/wizard/frontend/runs/WizardRunProgress.tsx
rename to products/wizard/frontend/components/run/WizardRunProgress.tsx
index 8b717678ef65..9f09b9f3d05a 100644
--- a/products/wizard/frontend/runs/WizardRunProgress.tsx
+++ b/products/wizard/frontend/components/run/WizardRunProgress.tsx
@@ -3,15 +3,16 @@ import { Spinner } from '@posthog/quill-primitives'
import { TZLabel } from 'lib/components/TZLabel'
-import type { WizardRunApi, WizardRunTaskApi } from '../generated/api.schemas'
-import type { WizardRunProgressState } from '../wizardRunDisplay'
+import type { WizardRunApi, WizardRunTaskApi } from '../../generated/api.schemas'
import {
+ WizardRunProgressStep,
wizardRunFailureStage,
- wizardRunProgressState,
- wizardRunStagePosition,
+ wizardRunProgressStates,
+ wizardRunProgressStep,
wizardWorkspaceLabel,
-} from '../wizardRunDisplay'
-import { wizardRunErrorDetails } from './wizardRunErrorCatalog'
+} from '../../lib/wizardRunDisplay'
+import type { WizardRunProgressState } from '../../lib/wizardRunDisplay'
+import { wizardRunErrorDetails } from '../../lib/wizardRunErrorCatalog'
function ProgressIcon({ state }: { state: WizardRunProgressState }): JSX.Element {
if (state === 'complete') {
@@ -72,12 +73,15 @@ export function WizardRunProgress({
}): JSX.Element {
const runError = wizardRunErrorDetails(run.error_code, run.error_message)
const failedAtStep = run.status === 'failed' && wizardRunFailureStage(run)
+ const stepStates = wizardRunProgressStates(run)
const steps = [
{
+ step: WizardRunProgressStep.Starting,
title: 'Starting run',
detail: run.created_at ? <TZLabel time={run.created_at} /> : 'Waiting to start',
},
{
+ step: WizardRunProgressStep.PreparingWorkspace,
title: 'Preparing workspace',
detail:
run.workspace.type === 'git_repository'
@@ -85,15 +89,17 @@ export function WizardRunProgress({
: `Folder: ${wizardWorkspaceLabel(run)}`,
},
{
+ step: WizardRunProgressStep.ExecutingWizard,
title: 'Running Wizard',
detail: `Program: ${run.program.name}`,
},
{
+ step: WizardRunProgressStep.CreatingArtifacts,
title: 'Finishing up',
detail:
run.status === 'completed'
? 'Changes and artifacts are ready'
- : wizardRunStagePosition(run) === 3
+ : wizardRunProgressStep(run) === WizardRunProgressStep.CreatingArtifacts
? 'Saving changes and artifacts'
: 'Starts after the program finishes',
},
@@ -102,9 +108,9 @@ export function WizardRunProgress({
return (
<div className="space-y-0">
{steps.map((step, index) => {
- const state = wizardRunProgressState(run, index)
+ const state = stepStates[step.step]
return (
- <div key={step.title} className="relative flex gap-3 pb-5 last:pb-0">
+ <div key={step.step} className="relative flex gap-3 pb-5 last:pb-0">
{index < steps.length - 1 && (
<div className="absolute left-[7px] top-5 h-[calc(100%-12px)] border-l border-primary" />
)}
@@ -114,27 +120,29 @@ export function WizardRunProgress({
<div className="min-w-0">
<div className="font-semibold">{step.title}</div>
<div className="text-xs text-muted">{step.detail}</div>
- {index === 2 && run.status === 'running' && tasks.length > 0 && (
- <ul className="mt-2 space-y-1 text-xs">
- {tasks.map((task) => (
- <li key={task.name} className="flex items-center gap-2">
- <ProgressIcon
- state={
- task.status === 'completed'
- ? 'complete'
- : task.status === 'running'
- ? 'active'
- : task.status === 'failed'
- ? 'failed'
- : 'pending'
- }
- />
- <span className="break-words">{task.name}</span>
- <span className="sr-only">({task.status})</span>
- </li>
- ))}
- </ul>
- )}
+ {step.step === WizardRunProgressStep.ExecutingWizard &&
+ run.status === 'running' &&
+ tasks.length > 0 && (
+ <ul className="mt-2 space-y-1 text-xs">
+ {tasks.map((task) => (
+ <li key={task.name} className="flex items-center gap-2">
+ <ProgressIcon
+ state={
+ task.status === 'completed'
+ ? 'complete'
+ : task.status === 'running'
+ ? 'active'
+ : task.status === 'failed'
+ ? 'failed'
+ : 'pending'
+ }
+ />
+ <span className="break-words">{task.name}</span>
+ <span className="sr-only">({task.status})</span>
+ </li>
+ ))}
+ </ul>
+ )}
{state === 'failed' && (
<div className="mt-1 space-y-1 text-xs">
<div className="flex items-center gap-1 text-danger">
diff --git a/products/wizard/frontend/runs/WizardRunTable.tsx b/products/wizard/frontend/components/run/WizardRunTable.tsx
similarity index 97%
rename from products/wizard/frontend/runs/WizardRunTable.tsx
rename to products/wizard/frontend/components/run/WizardRunTable.tsx
index 031962007ba1..158dcff0bba8 100644
--- a/products/wizard/frontend/runs/WizardRunTable.tsx
+++ b/products/wizard/frontend/components/run/WizardRunTable.tsx
@@ -22,12 +22,12 @@ import {
import { TZLabel } from 'lib/components/TZLabel'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
-import type { WizardRunApi } from '../generated/api.schemas'
-import { wizardGithubRepositoryUrl, wizardWorkspaceLabel } from '../wizardRunDisplay'
+import type { WizardRunApi } from '../../generated/api.schemas'
+import { wizardGithubRepositoryUrl, wizardWorkspaceLabel } from '../../lib/wizardRunDisplay'
+import { WizardRunEnvironmentTag } from '../run-tags/WizardRunEnvironmentTag'
+import { WizardRunStatusTag } from '../run-tags/WizardRunStatusTag'
import { WizardRunActionsMenu } from './WizardRunActionsMenu'
-import { WizardRunEnvironmentTag } from './WizardRunEnvironmentTag'
import { WizardRunsEmptyState } from './WizardRunsEmptyState'
-import { WizardRunStatusTag } from './WizardRunStatusTag'
export function WizardRunTable({
runs,
diff --git a/products/wizard/frontend/runs/WizardRunsEmptyState.tsx b/products/wizard/frontend/components/run/WizardRunsEmptyState.tsx
similarity index 100%
rename from products/wizard/frontend/runs/WizardRunsEmptyState.tsx
rename to products/wizard/frontend/components/run/WizardRunsEmptyState.tsx
diff --git a/products/wizard/frontend/wizardAnalytics.ts b/products/wizard/frontend/lib/wizardAnalytics.ts
similarity index 91%
rename from products/wizard/frontend/wizardAnalytics.ts
rename to products/wizard/frontend/lib/wizardAnalytics.ts
index d7c83a92ed18..53e56d389e4e 100644
--- a/products/wizard/frontend/wizardAnalytics.ts
+++ b/products/wizard/frontend/lib/wizardAnalytics.ts
@@ -1,4 +1,4 @@
-import type { RunEnvironmentEnumApi, WizardRunApi } from './generated/api.schemas'
+import type { RunEnvironmentEnumApi, WizardRunApi } from '../generated/api.schemas'
export function wizardEventProperties(
projectId: number | string | null,
diff --git a/products/wizard/frontend/wizardApi.ts b/products/wizard/frontend/lib/wizardApi.ts
similarity index 87%
rename from products/wizard/frontend/wizardApi.ts
rename to products/wizard/frontend/lib/wizardApi.ts
index 0012358d793d..4aa7092b44a0 100644
--- a/products/wizard/frontend/wizardApi.ts
+++ b/products/wizard/frontend/lib/wizardApi.ts
@@ -1,7 +1,7 @@
import api from 'lib/api'
-import { getWizardRunsArtifactsContentRetrieveUrl, wizardRunsArtifactsList } from './generated/api'
-import type { WizardRunArtifactApi } from './generated/api.schemas'
+import { getWizardRunsArtifactsContentRetrieveUrl, wizardRunsArtifactsList } from '../generated/api'
+import type { WizardRunArtifactApi } from '../generated/api.schemas'
export async function loadWizardRunArtifacts(projectId: string, runId: string): Promise<WizardRunArtifactApi[]> {
return (await wizardRunsArtifactsList(projectId, runId)).results
diff --git a/products/wizard/frontend/wizardRunDisplay.test.ts b/products/wizard/frontend/lib/wizardRunDisplay.test.ts
similarity index 60%
rename from products/wizard/frontend/wizardRunDisplay.test.ts
rename to products/wizard/frontend/lib/wizardRunDisplay.test.ts
index ad09f84b61e8..2b6603976017 100644
--- a/products/wizard/frontend/wizardRunDisplay.test.ts
+++ b/products/wizard/frontend/lib/wizardRunDisplay.test.ts
@@ -1,5 +1,12 @@
-import type { WizardRunApi } from './generated/api.schemas'
-import { wizardGithubRepositoryUrl, wizardRunCanCancel, wizardRunFailureStage } from './wizardRunDisplay'
+import type { WizardRunApi } from '../generated/api.schemas'
+import {
+ WizardRunProgressStep,
+ wizardGithubRepositoryUrl,
+ wizardRunCanCancel,
+ wizardRunFailureStage,
+ wizardRunProgressStates,
+ wizardRunProgressStep,
+} from './wizardRunDisplay'
function makeRun(overrides: Partial<WizardRunApi>): WizardRunApi {
return {
@@ -59,6 +66,49 @@ describe('wizardRunFailureStage', () => {
})
})
+describe('wizardRunProgressStep', () => {
+ test.each([
+ ['created', null, null, WizardRunProgressStep.Starting],
+ ['running', null, 'preparing_workspace', WizardRunProgressStep.PreparingWorkspace],
+ ['running', null, 'executing_wizard', WizardRunProgressStep.ExecutingWizard],
+ ['failed', 'artifact_creation_failed', null, WizardRunProgressStep.CreatingArtifacts],
+ ['completed', null, null, null],
+ ['cancelled', null, null, null],
+ ])('maps %s with stage %s/%s to %s', (status, errorCode, stage, expected) => {
+ const run = makeRun({
+ status: status as WizardRunApi['status'],
+ error_code: errorCode,
+ stage: stage as WizardRunApi['stage'],
+ })
+
+ expect(wizardRunProgressStep(run)).toBe(expected)
+ })
+})
+
+describe('wizardRunProgressStates', () => {
+ test('marks completed steps, the current step, and pending steps', () => {
+ const run = makeRun({ status: 'running', stage: 'executing_wizard' })
+
+ expect(wizardRunProgressStates(run)).toEqual({
+ [WizardRunProgressStep.Starting]: 'complete',
+ [WizardRunProgressStep.PreparingWorkspace]: 'complete',
+ [WizardRunProgressStep.ExecutingWizard]: 'active',
+ [WizardRunProgressStep.CreatingArtifacts]: 'pending',
+ })
+ })
+
+ test('marks the failure step and leaves later steps pending', () => {
+ const run = makeRun({ status: 'failed', error_code: 'artifact_creation_failed' })
+
+ expect(wizardRunProgressStates(run)).toEqual({
+ [WizardRunProgressStep.Starting]: 'complete',
+ [WizardRunProgressStep.PreparingWorkspace]: 'complete',
+ [WizardRunProgressStep.ExecutingWizard]: 'complete',
+ [WizardRunProgressStep.CreatingArtifacts]: 'failed',
+ })
+ })
+})
+
describe('wizardGithubRepositoryUrl', () => {
test('builds the GitHub URL for a repository', () => {
expect(wizardGithubRepositoryUrl('posthog/posthog')).toBe('https://github.com/posthog/posthog')
diff --git a/products/wizard/frontend/lib/wizardRunDisplay.ts b/products/wizard/frontend/lib/wizardRunDisplay.ts
new file mode 100644
index 000000000000..2a521895a6ec
--- /dev/null
+++ b/products/wizard/frontend/lib/wizardRunDisplay.ts
@@ -0,0 +1,179 @@
+import { WizardRunApi, WizardRunStageEnumApi } from '../generated/api.schemas'
+import { wizardRunErrorDetails } from './wizardRunErrorCatalog'
+
+export const MAX_RENDERED_WIZARD_DIFF_BYTES = 2 * 1024 * 1024
+// Byte size does not bound DOM nodes: many short lines can pass the byte cap and still stall the page.
+export const MAX_RENDERED_WIZARD_DIFF_LINES = 20_000
+export const WIZARD_LOCAL_RUNS_VISIBLE = false
+
+export function wizardRunDiffCanRender(sizeBytes: number): boolean {
+ return sizeBytes <= MAX_RENDERED_WIZARD_DIFF_BYTES
+}
+
+export function wizardWorkspaceLabel(run: WizardRunApi): string {
+ return run.workspace.type === 'git_repository' ? run.workspace.repository : run.workspace.project_name
+}
+
+export function wizardCommand(packageVersion: string, command: readonly string[]): string {
+ return ['npx', `@posthog/wizard@${packageVersion}`, ...command].join(' ')
+}
+
+export function wizardRunIsActive(run: WizardRunApi): boolean {
+ return run.status === 'created' || run.status === 'running'
+}
+
+export function wizardRunTerminalLabel(status: WizardRunApi['status']): string {
+ switch (status) {
+ case 'completed':
+ return 'Completed'
+ case 'failed':
+ return 'Failed'
+ case 'cancelled':
+ return 'Canceled'
+ default:
+ return 'Finished'
+ }
+}
+
+export function wizardRunCanCancel(run: WizardRunApi, currentUserId: number | null): boolean {
+ // The server cannot stop a local process, even when it marks that run canceled.
+ return (
+ run.environment === 'cloud' &&
+ wizardRunIsActive(run) &&
+ run.created_by_id !== null &&
+ run.created_by_id === currentUserId
+ )
+}
+
+const FAILURE_STAGE_BY_ERROR_CODE: Record<string, WizardRunStageEnumApi> = {
+ dispatch_failed: WizardRunStageEnumApi.Dispatching,
+ provisioning_failed: WizardRunStageEnumApi.Provisioning,
+ repository_access_failed: WizardRunStageEnumApi.PreparingWorkspace,
+ workspace_preparation_failed: WizardRunStageEnumApi.PreparingWorkspace,
+ timeout: WizardRunStageEnumApi.ExecutingWizard,
+ artifact_creation_failed: WizardRunStageEnumApi.CreatingArtifacts,
+}
+
+export function wizardRunFailureStage(run: WizardRunApi): WizardRunStageEnumApi | null {
+ if (run.stage) {
+ return run.stage
+ }
+
+ // Timeouts are recorded with a generic code regardless of which step ran out of time,
+ // so the failed stage is unknowable and the failure can only be shown at run level.
+ if (run.error_code === 'timeout') {
+ return null
+ }
+
+ return FAILURE_STAGE_BY_ERROR_CODE[run.error_code ?? ''] ?? WizardRunStageEnumApi.ExecutingWizard
+}
+
+export enum WizardRunProgressStep {
+ Starting = 'starting',
+ PreparingWorkspace = 'preparing_workspace',
+ ExecutingWizard = 'executing_wizard',
+ CreatingArtifacts = 'creating_artifacts',
+}
+
+export const WIZARD_RUN_PROGRESS_STEPS = [
+ WizardRunProgressStep.Starting,
+ WizardRunProgressStep.PreparingWorkspace,
+ WizardRunProgressStep.ExecutingWizard,
+ WizardRunProgressStep.CreatingArtifacts,
+] as const
+
+export type WizardRunProgressState = 'complete' | 'active' | 'pending' | 'failed'
+
+function progressStepForStage(stage: WizardRunStageEnumApi | null): WizardRunProgressStep | null {
+ switch (stage) {
+ case WizardRunStageEnumApi.Dispatching:
+ case WizardRunStageEnumApi.Provisioning:
+ return WizardRunProgressStep.Starting
+ case WizardRunStageEnumApi.PreparingWorkspace:
+ return WizardRunProgressStep.PreparingWorkspace
+ case WizardRunStageEnumApi.ExecutingWizard:
+ return WizardRunProgressStep.ExecutingWizard
+ case WizardRunStageEnumApi.CreatingArtifacts:
+ return WizardRunProgressStep.CreatingArtifacts
+ default:
+ return null
+ }
+}
+
+export function wizardRunProgressStep(run: WizardRunApi): WizardRunProgressStep | null {
+ if (run.status === 'completed' || run.status === 'cancelled') {
+ return null
+ }
+ if (run.status === 'created') {
+ return WizardRunProgressStep.Starting
+ }
+
+ const stage = run.status === 'failed' ? wizardRunFailureStage(run) : run.stage
+ return progressStepForStage(stage) ?? (run.status === 'running' ? WizardRunProgressStep.ExecutingWizard : null)
+}
+
+export function wizardRunProgressStates(run: WizardRunApi): Record<WizardRunProgressStep, WizardRunProgressState> {
+ const currentStep = wizardRunProgressStep(run)
+ const currentIndex = currentStep ? WIZARD_RUN_PROGRESS_STEPS.indexOf(currentStep) : -1
+
+ return Object.fromEntries(
+ WIZARD_RUN_PROGRESS_STEPS.map((step, index) => {
+ if (run.status === 'completed') {
+ return [step, 'complete']
+ }
+ if (run.status === 'cancelled' || currentStep === null) {
+ return [step, index === 0 ? 'complete' : 'pending']
+ }
+ if (run.status === 'failed' && index === currentIndex) {
+ return [step, 'failed']
+ }
+ if (index < currentIndex) {
+ return [step, 'complete']
+ }
+ return [step, index === currentIndex ? 'active' : 'pending']
+ })
+ ) as Record<WizardRunProgressStep, WizardRunProgressState>
+}
+
+export function wizardGithubRepositoryUrl(repository: string): string {
+ return `https://github.com/${repository}`
+}
+
+export function formatArtifactSize(sizeBytes: number): string {
+ if (sizeBytes < 1024) {
+ return `${sizeBytes} B`
+ }
+ if (sizeBytes < 1024 * 1024) {
+ return `${(sizeBytes / 1024).toFixed(1)} KB`
+ }
+ return `${(sizeBytes / (1024 * 1024)).toFixed(1)} MB`
+}
+
+export function wizardRunCurrentState(run: WizardRunApi): string {
+ if (run.status === 'completed') {
+ return 'Completed successfully'
+ }
+ if (run.status === 'failed') {
+ return wizardRunErrorDetails(run.error_code, run.error_message).title
+ }
+ if (run.status === 'cancelled') {
+ return 'Run canceled'
+ }
+
+ switch (run.stage) {
+ case WizardRunStageEnumApi.Dispatching:
+ return 'Starting the Wizard Worker'
+ case WizardRunStageEnumApi.Provisioning:
+ return 'Provisioning the Wizard Worker'
+ case WizardRunStageEnumApi.PreparingWorkspace:
+ return 'Preparing the repository'
+ case WizardRunStageEnumApi.ExecutingWizard:
+ return run.program.name.endsWith('audit')
+ ? `Running the ${run.program.name}`
+ : `Running ${run.program.name}`
+ case WizardRunStageEnumApi.CreatingArtifacts:
+ return 'Creating run artifacts'
+ default:
+ return run.status === 'running' ? 'Running the Wizard' : 'Starting the Wizard run'
+ }
+}
diff --git a/products/wizard/frontend/runs/wizardRunErrorCatalog.test.ts b/products/wizard/frontend/lib/wizardRunErrorCatalog.test.ts
similarity index 100%
rename from products/wizard/frontend/runs/wizardRunErrorCatalog.test.ts
rename to products/wizard/frontend/lib/wizardRunErrorCatalog.test.ts
diff --git a/products/wizard/frontend/runs/wizardRunErrorCatalog.ts b/products/wizard/frontend/lib/wizardRunErrorCatalog.ts
similarity index 100%
rename from products/wizard/frontend/runs/wizardRunErrorCatalog.ts
rename to products/wizard/frontend/lib/wizardRunErrorCatalog.ts
diff --git a/products/wizard/frontend/wizardLibraryLogic.test.tsx b/products/wizard/frontend/logics/wizardLibraryLogic.test.tsx
similarity index 97%
rename from products/wizard/frontend/wizardLibraryLogic.test.tsx
rename to products/wizard/frontend/logics/wizardLibraryLogic.test.tsx
index 891ef4102434..32621110a965 100644
--- a/products/wizard/frontend/wizardLibraryLogic.test.tsx
+++ b/products/wizard/frontend/logics/wizardLibraryLogic.test.tsx
@@ -11,9 +11,9 @@ import { projectLogic } from 'scenes/projectLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { wizardRegistryList, wizardRunsCreate } from './generated/api'
-import type { WizardProgramApi, WizardRunApi } from './generated/api.schemas'
-import { WizardRunsEmptyState } from './runs/WizardRunsEmptyState'
+import { WizardRunsEmptyState } from '../components/run/WizardRunsEmptyState'
+import { wizardRegistryList, wizardRunsCreate } from '../generated/api'
+import type { WizardProgramApi, WizardRunApi } from '../generated/api.schemas'
import { wizardLibraryLogic } from './wizardLibraryLogic'
import { wizardRunDetailsLogic } from './wizardRunDetailsLogic'
@@ -21,7 +21,7 @@ jest.mock('lib/utils/copyToClipboard', () => ({
copyToClipboard: jest.fn(),
}))
-jest.mock('./generated/api', () => ({
+jest.mock('../generated/api', () => ({
wizardRegistryList: jest.fn(),
wizardRunsCreate: jest.fn(),
wizardRunsList: jest.fn().mockResolvedValue({ count: 0, next: null, previous: null, results: [] }),
diff --git a/products/wizard/frontend/wizardLibraryLogic.ts b/products/wizard/frontend/logics/wizardLibraryLogic.ts
similarity index 98%
rename from products/wizard/frontend/wizardLibraryLogic.ts
rename to products/wizard/frontend/logics/wizardLibraryLogic.ts
index 837ab554dea9..067bb8bd5644 100644
--- a/products/wizard/frontend/wizardLibraryLogic.ts
+++ b/products/wizard/frontend/logics/wizardLibraryLogic.ts
@@ -12,17 +12,17 @@ import { uuid } from 'lib/utils/dom'
import { projectLogic } from 'scenes/projectLogic'
import { urls } from 'scenes/urls'
-import type { IntegrationType, PreflightStatus } from '../../../frontend/src/types'
-import { wizardRegistryList, wizardRunsCreate } from './generated/api'
+import type { IntegrationType, PreflightStatus } from '../../../../frontend/src/types'
+import { wizardRegistryList, wizardRunsCreate } from '../generated/api'
import type {
RunEnvironmentEnumApi,
WizardProgramApi,
WizardRunApi,
WizardRunCreateRequestApi,
-} from './generated/api.schemas'
-import { wizardEventProperties, wizardRunEventProperties } from './wizardAnalytics'
+} from '../generated/api.schemas'
+import { wizardEventProperties, wizardRunEventProperties } from '../lib/wizardAnalytics'
+import { WIZARD_LOCAL_RUNS_VISIBLE, wizardCommand } from '../lib/wizardRunDisplay'
import { type WizardRunDetailSource, wizardRunDetailsLogic } from './wizardRunDetailsLogic'
-import { WIZARD_LOCAL_RUNS_VISIBLE, wizardCommand } from './wizardRunDisplay'
import { wizardRunsLogic } from './wizardRunsLogic'
function requestError(error: unknown, fallback: string): string {
diff --git a/products/wizard/frontend/wizardRunDetailsLogic.test.ts b/products/wizard/frontend/logics/wizardRunDetailsLogic.test.ts
similarity index 98%
rename from products/wizard/frontend/wizardRunDetailsLogic.test.ts
rename to products/wizard/frontend/logics/wizardRunDetailsLogic.test.ts
index 21f2a8e94611..d56a00e9d82b 100644
--- a/products/wizard/frontend/wizardRunDetailsLogic.test.ts
+++ b/products/wizard/frontend/logics/wizardRunDetailsLogic.test.ts
@@ -8,18 +8,18 @@ import { projectLogic } from 'scenes/projectLogic'
import { initKeaTests } from '~/test/init'
-import { wizardRunsPartialUpdate, wizardRunsRetrieve } from './generated/api'
-import type { WizardRunApi, WizardRunGitDiffArtifactApi } from './generated/api.schemas'
-import { loadWizardRunArtifactContent, loadWizardRunArtifacts } from './wizardApi'
+import { wizardRunsPartialUpdate, wizardRunsRetrieve } from '../generated/api'
+import type { WizardRunApi, WizardRunGitDiffArtifactApi } from '../generated/api.schemas'
+import { loadWizardRunArtifactContent, loadWizardRunArtifacts } from '../lib/wizardApi'
import { wizardRunDetailsLogic } from './wizardRunDetailsLogic'
-jest.mock('./generated/api', () => ({
+jest.mock('../generated/api', () => ({
wizardRunsList: jest.fn().mockResolvedValue({ count: 0, next: null, previous: null, results: [] }),
wizardRunsPartialUpdate: jest.fn(),
wizardRunsRetrieve: jest.fn(),
}))
-jest.mock('./wizardApi', () => ({
+jest.mock('../lib/wizardApi', () => ({
loadWizardRunArtifactContent: jest.fn(),
loadWizardRunArtifacts: jest.fn(),
}))
diff --git a/products/wizard/frontend/wizardRunDetailsLogic.ts b/products/wizard/frontend/logics/wizardRunDetailsLogic.ts
similarity index 98%
rename from products/wizard/frontend/wizardRunDetailsLogic.ts
rename to products/wizard/frontend/logics/wizardRunDetailsLogic.ts
index 06290e212eca..22ec8e6055c3 100644
--- a/products/wizard/frontend/wizardRunDetailsLogic.ts
+++ b/products/wizard/frontend/logics/wizardRunDetailsLogic.ts
@@ -10,11 +10,11 @@ import { dayjs } from 'lib/dayjs'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { projectLogic } from 'scenes/projectLogic'
-import { wizardRunsPartialUpdate, wizardRunsRetrieve } from './generated/api'
-import type { WizardRunApi, WizardRunArtifactApi, WizardRunGitDiffArtifactApi } from './generated/api.schemas'
-import { wizardRunEventProperties } from './wizardAnalytics'
-import { loadWizardRunArtifactContent, loadWizardRunArtifacts } from './wizardApi'
-import { wizardRunDiffCanRender, wizardRunIsActive } from './wizardRunDisplay'
+import { wizardRunsPartialUpdate, wizardRunsRetrieve } from '../generated/api'
+import type { WizardRunApi, WizardRunArtifactApi, WizardRunGitDiffArtifactApi } from '../generated/api.schemas'
+import { wizardRunEventProperties } from '../lib/wizardAnalytics'
+import { loadWizardRunArtifactContent, loadWizardRunArtifacts } from '../lib/wizardApi'
+import { wizardRunDiffCanRender, wizardRunIsActive } from '../lib/wizardRunDisplay'
import { wizardRunsLogic } from './wizardRunsLogic'
const RUN_DETAIL_POLL_INTERVAL_MS = 10_000
diff --git a/products/wizard/frontend/runs/wizardRunSyncLogic.test.ts b/products/wizard/frontend/logics/wizardRunSyncLogic.test.ts
similarity index 100%
rename from products/wizard/frontend/runs/wizardRunSyncLogic.test.ts
rename to products/wizard/frontend/logics/wizardRunSyncLogic.test.ts
diff --git a/products/wizard/frontend/runs/wizardRunSyncLogic.ts b/products/wizard/frontend/logics/wizardRunSyncLogic.ts
similarity index 98%
rename from products/wizard/frontend/runs/wizardRunSyncLogic.ts
rename to products/wizard/frontend/logics/wizardRunSyncLogic.ts
index ad4651a7c2c2..2a1c05b10f10 100644
--- a/products/wizard/frontend/runs/wizardRunSyncLogic.ts
+++ b/products/wizard/frontend/logics/wizardRunSyncLogic.ts
@@ -2,7 +2,7 @@ import { MakeLogicType, actions, events, kea, key, listeners, path, props, reduc
import { getWizardRunsStreamRetrieveUrl, wizardRunsList } from '../generated/api'
import type { WizardRunApi, WizardRunTaskApi, WizardRunTaskListApi } from '../generated/api.schemas'
-import { wizardRunIsActive } from '../wizardRunDisplay'
+import { wizardRunIsActive } from '../lib/wizardRunDisplay'
const RUN_POLL_MS = 30_000
diff --git a/products/wizard/frontend/wizardRunsLogic.test.ts b/products/wizard/frontend/logics/wizardRunsLogic.test.ts
similarity index 97%
rename from products/wizard/frontend/wizardRunsLogic.test.ts
rename to products/wizard/frontend/logics/wizardRunsLogic.test.ts
index 69c1f9bf7158..82cf5a520e04 100644
--- a/products/wizard/frontend/wizardRunsLogic.test.ts
+++ b/products/wizard/frontend/logics/wizardRunsLogic.test.ts
@@ -5,11 +5,11 @@ import { projectLogic } from 'scenes/projectLogic'
import { initKeaTests } from '~/test/init'
-import { wizardRunsList } from './generated/api'
-import type { WizardRunApi } from './generated/api.schemas'
+import { wizardRunsList } from '../generated/api'
+import type { WizardRunApi } from '../generated/api.schemas'
import { wizardRunsLogic } from './wizardRunsLogic'
-jest.mock('./generated/api', () => ({ wizardRunsList: jest.fn() }))
+jest.mock('../generated/api', () => ({ wizardRunsList: jest.fn() }))
const mockWizardRunsList = wizardRunsList as jest.Mock
diff --git a/products/wizard/frontend/wizardRunsLogic.ts b/products/wizard/frontend/logics/wizardRunsLogic.ts
similarity index 98%
rename from products/wizard/frontend/wizardRunsLogic.ts
rename to products/wizard/frontend/logics/wizardRunsLogic.ts
index f388111b75b7..1559b25bd1e2 100644
--- a/products/wizard/frontend/wizardRunsLogic.ts
+++ b/products/wizard/frontend/logics/wizardRunsLogic.ts
@@ -5,9 +5,9 @@ import posthog from 'posthog-js'
import { dayjs } from 'lib/dayjs'
import { projectLogic } from 'scenes/projectLogic'
-import { wizardRunsList } from './generated/api'
-import type { RunEnvironmentEnumApi, WizardRunApi, WizardRunStatusEnumApi } from './generated/api.schemas'
-import { wizardWorkspaceLabel } from './wizardRunDisplay'
+import { wizardRunsList } from '../generated/api'
+import type { RunEnvironmentEnumApi, WizardRunApi, WizardRunStatusEnumApi } from '../generated/api.schemas'
+import { wizardWorkspaceLabel } from '../lib/wizardRunDisplay'
const RUN_POLL_INTERVAL_MS = 10_000
const RUN_PAGE_SIZE = 100
diff --git a/products/wizard/frontend/runs/WizardRunDetailsDialog.tsx b/products/wizard/frontend/runs/WizardRunDetailsDialog.tsx
deleted file mode 100644
index 22fb2c7964ee..000000000000
--- a/products/wizard/frontend/runs/WizardRunDetailsDialog.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-import { useActions, useValues } from 'kea'
-
-import { userLogic } from 'scenes/userLogic'
-
-import type { WizardRunApi, WizardRunTaskApi } from '../generated/api.schemas'
-import { wizardRunDetailsLogic } from '../wizardRunDetailsLogic'
-import { WizardRunDetailsDrawer } from './WizardRunDetailsDrawer'
-
-export function WizardRunDetailsDialog({
- onRunAgain,
- onClose,
- tasks = [],
-}: {
- onRunAgain?: (run: WizardRunApi) => void
- onClose?: () => void
- tasks?: readonly WizardRunTaskApi[]
-}): JSX.Element {
- const { user } = useValues(userLogic)
- const {
- cancelRunRequestLoading,
- runArtifactsError,
- runDetailsError,
- runDetailsLoading,
- runDiffError,
- runDiffLoading,
- selectedRun,
- selectedRunArtifacts,
- selectedRunArtifactsInitialLoading,
- selectedRunDiffArtifactId,
- selectedRunDiffContent,
- } = useValues(wizardRunDetailsLogic)
- const { artifactClicked, cancelRun, closeRunDiff, copyRunId, openRunDiff, refreshSelectedRun, selectRun } =
- useActions(wizardRunDetailsLogic)
-
- return (
- <WizardRunDetailsDrawer
- run={selectedRun}
- tasks={tasks}
- artifacts={selectedRunArtifacts}
- artifactsError={runArtifactsError}
- artifactsLoading={selectedRunArtifactsInitialLoading}
- currentUserId={user?.id ?? null}
- detailsError={runDetailsError}
- refreshing={runDetailsLoading}
- cancelling={cancelRunRequestLoading}
- diffArtifactId={selectedRunDiffArtifactId}
- diffContent={selectedRunDiffContent}
- diffError={runDiffError}
- diffLoading={runDiffLoading}
- onClose={() => {
- selectRun(null)
- onClose?.()
- }}
- onCloseDiff={closeRunDiff}
- onOpenDiff={openRunDiff}
- onArtifactClick={artifactClicked}
- onRefresh={refreshSelectedRun}
- onCopyRunId={copyRunId}
- onCancel={cancelRun}
- onRunAgain={onRunAgain}
- />
- )
-}
diff --git a/products/wizard/frontend/WizardRunsScene.tsx b/products/wizard/frontend/scenes/WizardRunsScene.tsx
similarity index 94%
rename from products/wizard/frontend/WizardRunsScene.tsx
rename to products/wizard/frontend/scenes/WizardRunsScene.tsx
index 071a552b0bba..58033e07475f 100644
--- a/products/wizard/frontend/WizardRunsScene.tsx
+++ b/products/wizard/frontend/scenes/WizardRunsScene.tsx
@@ -24,13 +24,13 @@ import { userLogic } from 'scenes/userLogic'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
-import { WizardLibraryModal } from './library/WizardLibraryModal'
-import { WizardRunDetailsDialog } from './runs/WizardRunDetailsDialog'
-import { WizardRunSceneSyncDetailsDialog } from './runs/WizardRunSceneSyncDetailsDialog'
-import { WizardRunTable } from './runs/WizardRunTable'
-import { wizardLibraryLogic } from './wizardLibraryLogic'
-import { wizardRunDetailsLogic } from './wizardRunDetailsLogic'
-import { wizardRunsLogic } from './wizardRunsLogic'
+import { WizardRunTable } from '../components/run/WizardRunTable'
+import { wizardLibraryLogic } from '../logics/wizardLibraryLogic'
+import { wizardRunDetailsLogic } from '../logics/wizardRunDetailsLogic'
+import { wizardRunsLogic } from '../logics/wizardRunsLogic'
+import { WizardRunDetailsDialog } from '../views/run-details/WizardRunDetailsDialog'
+import { WizardRunSceneSyncDetailsDialog } from '../views/run-details/WizardRunSceneSyncDetailsDialog'
+import { WizardLibraryModal } from '../views/wizard-library/WizardLibraryModal'
export const scene: SceneExport = {
component: WizardRunsScene,
diff --git a/products/wizard/frontend/runs/WizardRunDetailsDrawer.tsx b/products/wizard/frontend/views/run-details/WizardRunDetailsDialog.tsx
similarity index 87%
rename from products/wizard/frontend/runs/WizardRunDetailsDrawer.tsx
rename to products/wizard/frontend/views/run-details/WizardRunDetailsDialog.tsx
index b6d7c280aa0d..2bce45f56c84 100644
--- a/products/wizard/frontend/runs/WizardRunDetailsDrawer.tsx
+++ b/products/wizard/frontend/views/run-details/WizardRunDetailsDialog.tsx
@@ -1,3 +1,4 @@
+import { useActions, useValues } from 'kea'
import { Suspense } from 'react'
import { IconArrowLeft, IconCopy, IconFolder, IconGithub, IconRefresh, IconStopFilled } from '@posthog/icons'
@@ -18,13 +19,14 @@ import {
import { TZLabel } from 'lib/components/TZLabel'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { lazyWithRetry } from 'lib/utils/retryImport'
+import { userLogic } from 'scenes/userLogic'
-import type {
- WizardRunApi,
- WizardRunArtifactApi,
- WizardRunGitDiffArtifactApi,
- WizardRunTaskApi,
-} from '../generated/api.schemas'
+import { WizardRunDetailsArtifacts } from '../../components/run-details/WizardRunDetailsArtifacts'
+import { WizardRunDiffStats } from '../../components/run-diff/WizardRunDiffStats'
+import { WizardRunEnvironmentTag } from '../../components/run-tags/WizardRunEnvironmentTag'
+import { WizardRunStatusTag } from '../../components/run-tags/WizardRunStatusTag'
+import { WizardRunProgress } from '../../components/run/WizardRunProgress'
+import type { WizardRunApi, WizardRunTaskApi } from '../../generated/api.schemas'
import {
WIZARD_LOCAL_RUNS_VISIBLE,
wizardGithubRepositoryUrl,
@@ -33,15 +35,11 @@ import {
wizardRunIsActive,
wizardRunTerminalLabel,
wizardWorkspaceLabel,
-} from '../wizardRunDisplay'
-import { WizardRunDetailsArtifacts } from './WizardRunDetailsArtifacts'
-import { WizardRunDiffStats } from './WizardRunDiffStats'
-import { WizardRunEnvironmentTag } from './WizardRunEnvironmentTag'
-import { WizardRunProgress } from './WizardRunProgress'
-import { WizardRunStatusTag } from './WizardRunStatusTag'
+} from '../../lib/wizardRunDisplay'
+import { wizardRunDetailsLogic } from '../../logics/wizardRunDetailsLogic'
const WizardRunDiffViewer = lazyWithRetry(() =>
- import('./WizardRunDiffViewer').then((module) => ({ default: module.WizardRunDiffViewer }))
+ import('../../components/run-diff/WizardRunDiffViewer').then((module) => ({ default: module.WizardRunDiffViewer }))
)
function LoadingRows(): JSX.Element {
@@ -75,57 +73,56 @@ function RetryItem({
)
}
-export function WizardRunDetailsDrawer({
- run,
- tasks = [],
- artifacts,
- artifactsError,
- artifactsLoading,
- currentUserId,
- detailsError,
- refreshing,
- cancelling,
- diffArtifactId,
- diffContent,
- diffError,
- diffLoading,
- onClose,
- onCloseDiff,
- onOpenDiff,
- onArtifactClick,
- onRefresh,
- onCopyRunId,
- onCancel,
+export function WizardRunDetailsDialog({
onRunAgain,
+ onClose,
+ tasks = [],
}: {
- run: WizardRunApi | null
- tasks?: readonly WizardRunTaskApi[]
- artifacts: WizardRunArtifactApi[]
- artifactsError: string | null
- artifactsLoading: boolean
- currentUserId: number | null
- detailsError: string | null
- refreshing: boolean
- cancelling: boolean
- diffArtifactId: string | null
- diffContent: string | null
- diffError: string | null
- diffLoading: boolean
- onClose: () => void
- onCloseDiff: () => void
- onOpenDiff: (artifact: WizardRunGitDiffArtifactApi) => void
- onRefresh: () => void
- onArtifactClick: (artifact: WizardRunArtifactApi, source: 'button' | 'artifacts_section') => void
- onCopyRunId: (runId: string, location: 'bottom_button' | 'run_id_label') => void
- onCancel: (run: WizardRunApi) => void
onRunAgain?: (run: WizardRunApi) => void
+ onClose?: () => void
+ tasks?: readonly WizardRunTaskApi[]
}): JSX.Element {
+ const { user } = useValues(userLogic)
+ const {
+ cancelRunRequestLoading,
+ runArtifactsError,
+ runDetailsError,
+ runDetailsLoading,
+ runDiffError,
+ runDiffLoading,
+ selectedRun: run,
+ selectedRunArtifacts: artifacts,
+ selectedRunArtifactsInitialLoading: artifactsLoading,
+ selectedRunDiffArtifactId: diffArtifactId,
+ selectedRunDiffContent: diffContent,
+ } = useValues(wizardRunDetailsLogic)
+ const { artifactClicked, cancelRun, closeRunDiff, copyRunId, openRunDiff, refreshSelectedRun, selectRun } =
+ useActions(wizardRunDetailsLogic)
+
+ const artifactsError = runArtifactsError
+ const currentUserId = user?.id ?? null
+ const detailsError = runDetailsError
+ const refreshing = runDetailsLoading
+ const cancelling = cancelRunRequestLoading
+ const diffError = runDiffError
+ const diffLoading = runDiffLoading
+ const onCloseDiff = closeRunDiff
+ const onOpenDiff = openRunDiff
+ const onArtifactClick = artifactClicked
+ const onRefresh = refreshSelectedRun
+ const onCopyRunId = copyRunId
+ const onCancel = cancelRun
+ const handleClose = (): void => {
+ selectRun(null)
+ onClose?.()
+ }
+
const pullRequest = artifacts.find((artifact) => artifact.artifact_type === 'pull_request')
const gitDiff = artifacts.find((artifact) => artifact.artifact_type === 'git_diff')
const selectedDiff = gitDiff?.id === diffArtifactId ? gitDiff : null
return (
- <Dialog open={!!run} onOpenChange={(open) => !open && onClose()}>
+ <Dialog open={!!run} onOpenChange={(open) => !open && handleClose()}>
<DialogContent size={selectedDiff ? 'wide' : undefined} className={selectedDiff ? 'max-w-6xl' : 'max-w-xl'}>
<DialogHeader className="pr-8">
<DialogTitle className="flex items-center justify-between gap-2">
diff --git a/products/wizard/frontend/runs/WizardRunSceneSyncDetailsDialog.tsx b/products/wizard/frontend/views/run-details/WizardRunSceneSyncDetailsDialog.tsx
similarity index 71%
rename from products/wizard/frontend/runs/WizardRunSceneSyncDetailsDialog.tsx
rename to products/wizard/frontend/views/run-details/WizardRunSceneSyncDetailsDialog.tsx
index ec79c7c5d430..a0d16a75b3d8 100644
--- a/products/wizard/frontend/runs/WizardRunSceneSyncDetailsDialog.tsx
+++ b/products/wizard/frontend/views/run-details/WizardRunSceneSyncDetailsDialog.tsx
@@ -1,9 +1,9 @@
import { useValues } from 'kea'
-import type { WizardRunApi } from '../generated/api.schemas'
-import { wizardRunDetailsLogic } from '../wizardRunDetailsLogic'
+import type { WizardRunApi } from '../../generated/api.schemas'
+import { wizardRunDetailsLogic } from '../../logics/wizardRunDetailsLogic'
+import { wizardRunSyncLogic } from '../../logics/wizardRunSyncLogic'
import { WizardRunDetailsDialog } from './WizardRunDetailsDialog'
-import { wizardRunSyncLogic } from './wizardRunSyncLogic'
export function WizardRunSceneSyncDetailsDialog({
projectId,
diff --git a/products/wizard/frontend/library/WizardLibraryModal.tsx b/products/wizard/frontend/views/wizard-library/WizardLibraryModal.tsx
similarity index 95%
rename from products/wizard/frontend/library/WizardLibraryModal.tsx
rename to products/wizard/frontend/views/wizard-library/WizardLibraryModal.tsx
index 7b627c850de0..0c8c7b31c72a 100644
--- a/products/wizard/frontend/library/WizardLibraryModal.tsx
+++ b/products/wizard/frontend/views/wizard-library/WizardLibraryModal.tsx
@@ -7,9 +7,9 @@ import {
DialogTitle,
} from '@posthog/quill-primitives'
-import type { RunEnvironmentEnumApi, WizardProgramApi } from '../generated/api.schemas'
-import { WizardProgramDetails } from './WizardProgramDetails'
-import { WizardProgramList } from './WizardProgramList'
+import type { RunEnvironmentEnumApi, WizardProgramApi } from '../../generated/api.schemas'
+import { WizardProgramDetails } from './components/WizardProgramDetails'
+import { WizardProgramList } from './components/WizardProgramList'
export function WizardLibraryModal({
isOpen,
diff --git a/products/wizard/frontend/library/WizardCommand.tsx b/products/wizard/frontend/views/wizard-library/components/WizardCommand.tsx
similarity index 100%
rename from products/wizard/frontend/library/WizardCommand.tsx
rename to products/wizard/frontend/views/wizard-library/components/WizardCommand.tsx
diff --git a/products/wizard/frontend/library/WizardProgramDetails.tsx b/products/wizard/frontend/views/wizard-library/components/WizardProgramDetails.tsx
similarity index 98%
rename from products/wizard/frontend/library/WizardProgramDetails.tsx
rename to products/wizard/frontend/views/wizard-library/components/WizardProgramDetails.tsx
index 8f2bd6004920..688776a52760 100644
--- a/products/wizard/frontend/library/WizardProgramDetails.tsx
+++ b/products/wizard/frontend/views/wizard-library/components/WizardProgramDetails.tsx
@@ -19,8 +19,8 @@ import {
import { LinkPrimitive } from 'lib/lemon-ui/Link'
-import type { RunEnvironmentEnumApi, WizardProgramApi } from '../generated/api.schemas'
-import { WIZARD_LOCAL_RUNS_VISIBLE } from '../wizardRunDisplay'
+import type { RunEnvironmentEnumApi, WizardProgramApi } from '../../../generated/api.schemas'
+import { WIZARD_LOCAL_RUNS_VISIBLE } from '../../../lib/wizardRunDisplay'
import { WizardCommand } from './WizardCommand'
import { WizardRepositoryPicker } from './WizardRepositoryPicker'
diff --git a/products/wizard/frontend/library/WizardProgramList.tsx b/products/wizard/frontend/views/wizard-library/components/WizardProgramList.tsx
similarity index 97%
rename from products/wizard/frontend/library/WizardProgramList.tsx
rename to products/wizard/frontend/views/wizard-library/components/WizardProgramList.tsx
index 77d6e40d0e5a..8c7a31e7f2ee 100644
--- a/products/wizard/frontend/library/WizardProgramList.tsx
+++ b/products/wizard/frontend/views/wizard-library/components/WizardProgramList.tsx
@@ -15,8 +15,8 @@ import {
cn,
} from '@posthog/quill-primitives'
-import type { WizardProgramApi } from '../generated/api.schemas'
-import { WIZARD_LOCAL_RUNS_VISIBLE } from '../wizardRunDisplay'
+import type { WizardProgramApi } from '../../../generated/api.schemas'
+import { WIZARD_LOCAL_RUNS_VISIBLE } from '../../../lib/wizardRunDisplay'
export function WizardProgramList({
programs,
diff --git a/products/wizard/frontend/library/WizardRepositoryPicker.test.ts b/products/wizard/frontend/views/wizard-library/components/WizardRepositoryPicker.test.ts
similarity index 100%
rename from products/wizard/frontend/library/WizardRepositoryPicker.test.ts
rename to products/wizard/frontend/views/wizard-library/components/WizardRepositoryPicker.test.ts
diff --git a/products/wizard/frontend/library/WizardRepositoryPicker.tsx b/products/wizard/frontend/views/wizard-library/components/WizardRepositoryPicker.tsx
similarity index 100%
rename from products/wizard/frontend/library/WizardRepositoryPicker.tsx
rename to products/wizard/frontend/views/wizard-library/components/WizardRepositoryPicker.tsx
diff --git a/products/wizard/frontend/wizardRunDisplay.ts b/products/wizard/frontend/wizardRunDisplay.ts
deleted file mode 100644
index 27ff684a83b6..000000000000
--- a/products/wizard/frontend/wizardRunDisplay.ts
+++ /dev/null
@@ -1,133 +0,0 @@
-import { WizardRunApi, WizardRunStageEnumApi } from './generated/api.schemas'
-
-export const MAX_RENDERED_WIZARD_DIFF_BYTES = 2 * 1024 * 1024
-// Byte size does not bound DOM nodes: many short lines can pass the byte cap and still stall the page.
-export const MAX_RENDERED_WIZARD_DIFF_LINES = 20_000
-export const WIZARD_LOCAL_RUNS_VISIBLE = false
-
-export function wizardRunDiffCanRender(sizeBytes: number): boolean {
- return sizeBytes <= MAX_RENDERED_WIZARD_DIFF_BYTES
-}
-
-export function wizardWorkspaceLabel(run: WizardRunApi): string {
- return run.workspace.type === 'git_repository' ? run.workspace.repository : run.workspace.project_name
-}
-
-export function wizardCommand(packageVersion: string, command: readonly string[]): string {
- return ['npx', `@posthog/wizard@${packageVersion}`, ...command].join(' ')
-}
-
-export function wizardRunIsActive(run: WizardRunApi): boolean {
- return run.status === 'created' || run.status === 'running'
-}
-
-export function wizardRunTerminalLabel(status: WizardRunApi['status']): string {
- switch (status) {
- case 'completed':
- return 'Completed'
- case 'failed':
- return 'Failed'
- case 'cancelled':
- return 'Canceled'
- default:
- return 'Finished'
- }
-}
-
-export function wizardRunCanCancel(run: WizardRunApi, currentUserId: number | null): boolean {
- // The server cannot stop a local process, even when it marks that run canceled.
- return (
- run.environment === 'cloud' &&
- wizardRunIsActive(run) &&
- run.created_by_id !== null &&
- run.created_by_id === currentUserId
- )
-}
-
-const FAILURE_STAGE_BY_ERROR_CODE: Record<string, WizardRunStageEnumApi> = {
- dispatch_failed: WizardRunStageEnumApi.Dispatching,
- provisioning_failed: WizardRunStageEnumApi.Provisioning,
- repository_access_failed: WizardRunStageEnumApi.PreparingWorkspace,
- workspace_preparation_failed: WizardRunStageEnumApi.PreparingWorkspace,
- timeout: WizardRunStageEnumApi.ExecutingWizard,
- artifact_creation_failed: WizardRunStageEnumApi.CreatingArtifacts,
-}
-
-export function wizardRunFailureStage(run: WizardRunApi): WizardRunStageEnumApi | null {
- if (run.stage) {
- return run.stage
- }
-
- // Timeouts are recorded with a generic code regardless of which step ran out of time,
- // so the failed stage is unknowable and the failure can only be shown at run level.
- if (run.error_code === 'timeout') {
- return null
- }
-
- return FAILURE_STAGE_BY_ERROR_CODE[run.error_code ?? ''] ?? WizardRunStageEnumApi.ExecutingWizard
-}
-
-export type WizardRunProgressState = 'complete' | 'active' | 'pending' | 'failed'
-
-export function wizardRunStagePosition(run: WizardRunApi): number {
- if (run.status === 'completed') {
- return 4
- }
- if (run.status === 'created') {
- return 0
- }
-
- const stage = run.status === 'failed' ? wizardRunFailureStage(run) : run.stage
-
- switch (stage) {
- case 'dispatching':
- case 'provisioning':
- return 0
- case 'preparing_workspace':
- return 1
- case 'executing_wizard':
- return 2
- case 'creating_artifacts':
- return 3
- default:
- return run.status === 'running' ? 2 : 0
- }
-}
-
-export function wizardRunProgressState(run: WizardRunApi, step: number): WizardRunProgressState {
- if (run.status === 'cancelled') {
- return step === 0 ? 'complete' : 'pending'
- }
-
- const position = wizardRunStagePosition(run)
-
- if (run.status === 'failed') {
- if (wizardRunFailureStage(run) === null) {
- return step === 0 ? 'complete' : 'pending'
- }
- if (position === step) {
- return 'failed'
- }
- }
- if (position > step) {
- return 'complete'
- }
- if (position === step && run.status !== 'completed') {
- return 'active'
- }
- return 'pending'
-}
-
-export function wizardGithubRepositoryUrl(repository: string): string {
- return `https://github.com/${repository}`
-}
-
-export function formatArtifactSize(sizeBytes: number): string {
- if (sizeBytes < 1024) {
- return `${sizeBytes} B`
- }
- if (sizeBytes < 1024 * 1024) {
- return `${(sizeBytes / 1024).toFixed(1)} KB`
- }
- return `${(sizeBytes / (1024 * 1024)).toFixed(1)} MB`
-}
diff --git a/products/wizard/manifest.tsx b/products/wizard/manifest.tsx
index 8b8ecd5dbc7a..06f347c70843 100644
--- a/products/wizard/manifest.tsx
+++ b/products/wizard/manifest.tsx
@@ -4,7 +4,7 @@ export const manifest: ProductManifest = {
name: 'Wizard',
scenes: {
WizardRuns: {
- import: () => import('./frontend/WizardRunsScene'),
+ import: () => import('./frontend/scenes/WizardRunsScene'),
projectBased: true,
name: 'Wizard runs',
description: 'Run the setup agent in the cloud, then review the changes it produces.',