Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(import): allow continuing the import after an error #6614

Merged
merged 9 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions editor/src/components/editor/action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import { assertNever } from '../../core/shared/utils'
import type {
ImportOperation,
ImportOperationAction,
ImportStatus,
} from '../../core/shared/import/import-operation-types'
import type { ProjectRequirements } from '../../core/shared/import/project-health-check/utopia-requirements-types'
export { isLoggedIn, loggedInUser, notLoggedIn } from '../../common/user'
Expand Down Expand Up @@ -1008,6 +1009,11 @@ export interface UpdateImportOperations {
type: ImportOperationAction
}

export interface UpdateImportStatus {
action: 'UPDATE_IMPORT_STATUS'
importStatus: ImportStatus
}

export interface UpdateProjectRequirements {
action: 'UPDATE_PROJECT_REQUIREMENTS'
requirements: Partial<ProjectRequirements>
Expand Down Expand Up @@ -1376,6 +1382,7 @@ export type EditorAction =
| SetImageDragSessionState
| UpdateGithubOperations
| UpdateImportOperations
| UpdateImportStatus
| UpdateProjectRequirements
| SetImportWizardOpen
| UpdateBranchContents
Expand Down
9 changes: 9 additions & 0 deletions editor/src/components/editor/actions/action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ import type {
SetImportWizardOpen,
UpdateImportOperations,
UpdateProjectRequirements,
UpdateImportStatus,
} from '../action-types'
import type { InsertionSubjectWrapper, Mode } from '../editor-modes'
import { EditorModes, insertionSubject } from '../editor-modes'
Expand Down Expand Up @@ -274,6 +275,7 @@ import type { ElementPathTrees } from '../../../core/shared/element-path-tree'
import type {
ImportOperation,
ImportOperationAction,
ImportStatus,
} from '../../../core/shared/import/import-operation-types'
import type { ProjectRequirements } from '../../../core/shared/import/project-health-check/utopia-requirements-types'

Expand Down Expand Up @@ -1610,6 +1612,13 @@ export function updateImportOperations(
}
}

export function updateImportStatus(importStatus: ImportStatus): UpdateImportStatus {
return {
action: 'UPDATE_IMPORT_STATUS',
importStatus: importStatus,
}
}

export function updateProjectRequirements(
requirements: Partial<ProjectRequirements>,
): UpdateProjectRequirements {
Expand Down
1 change: 1 addition & 0 deletions editor/src/components/editor/actions/action-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export function isTransientAction(action: EditorAction): boolean {
case 'SET_ERROR_BOUNDARY_HANDLING':
case 'SET_IMPORT_WIZARD_OPEN':
case 'UPDATE_IMPORT_OPERATIONS':
case 'UPDATE_IMPORT_STATUS':
case 'UPDATE_PROJECT_REQUIREMENTS':
return true

Expand Down
16 changes: 13 additions & 3 deletions editor/src/components/editor/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ import type {
SetImportWizardOpen,
UpdateImportOperations,
UpdateProjectRequirements,
UpdateImportStatus,
} from '../action-types'
import { isAlignment, isLoggedIn } from '../action-types'
import type { Mode } from '../editor-modes'
Expand Down Expand Up @@ -1034,7 +1035,7 @@ export function restoreEditorState(
githubSettings: currentEditor.githubSettings,
imageDragSessionState: currentEditor.imageDragSessionState,
githubOperations: currentEditor.githubOperations,
importOperations: currentEditor.importOperations,
importState: currentEditor.importState,
projectRequirements: currentEditor.projectRequirements,
importWizardOpen: currentEditor.importWizardOpen,
branchOriginContents: currentEditor.branchOriginContents,
Expand Down Expand Up @@ -2178,13 +2179,22 @@ export const UPDATE_FNS = {
},
UPDATE_IMPORT_OPERATIONS: (action: UpdateImportOperations, editor: EditorModel): EditorModel => {
const resultImportOperations = getUpdateOperationResult(
editor.importOperations,
editor.importState.importOperations,
action.operations,
action.type,
)
return {
...editor,
importOperations: resultImportOperations,
importState: { ...editor.importState, importOperations: resultImportOperations },
}
},
UPDATE_IMPORT_STATUS: (action: UpdateImportStatus, editor: EditorModel): EditorModel => {
return {
...editor,
importState: {
...editor.importState,
importStatus: action.importStatus,
},
}
},
UPDATE_PROJECT_REQUIREMENTS: (
Expand Down
39 changes: 25 additions & 14 deletions editor/src/components/editor/import-wizard/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import { RequirementResolutionResult } from '../../../core/shared/import/project

export function OperationLine({ operation }: { operation: ImportOperation }) {
const operationRunningStatus = React.useMemo(() => {
return operation.timeStarted == null
? 'waiting'
: operation.timeDone == null
? 'running'
: 'done'
if (operation.timeDone != null) {
return 'done'
}
return operation.timeStarted == null ? 'waiting' : 'running'
}, [operation.timeStarted, operation.timeDone])
const colorTheme = useColorTheme()
const textColor = operationRunningStatus === 'waiting' ? 'gray' : colorTheme.fg0.value
Expand All @@ -29,7 +28,7 @@ export function OperationLine({ operation }: { operation: ImportOperation }) {
() =>
childrenShown ||
operation.timeDone == null ||
operation.result == ImportOperationResult.Error,
operation.result != ImportOperationResult.Success,
[childrenShown, operation.timeDone, operation.result],
)
const hasChildren = React.useMemo(
Expand Down Expand Up @@ -253,14 +252,26 @@ function getImportOperationText(operation: ImportOperation): React.ReactNode {
}
switch (operation.type) {
case 'loadBranch':
return (
<span>
Loading branch{' '}
<strong>
{operation.githubRepo?.owner}/{operation.githubRepo?.repository}@{operation.branchName}
</strong>
</span>
)
if (operation.branchName != null) {
return (
<span>
Loading branch{' '}
<strong>
{operation.githubRepo?.owner}/{operation.githubRepo?.repository}@
{operation.branchName}
</strong>
</span>
)
} else {
return (
<span>
Loading repository{' '}
<strong>
{operation.githubRepo?.owner}/{operation.githubRepo?.repository}
</strong>
</span>
)
}
case 'fetchDependency':
return `Fetching ${operation.dependencyName}@${operation.dependencyVersion}`
case 'parseFiles':
Expand Down
Loading
Loading