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): early break on error #6604

Merged
merged 1 commit into from
Oct 31, 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: 5 additions & 2 deletions editor/src/components/editor/import-wizard/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export function OperationLine({ operation }: { operation: ImportOperation }) {

const [childrenShown, serChildrenShown] = React.useState(false)
const shouldShowChildren = React.useMemo(
() => childrenShown || operation.timeDone == null,
[childrenShown, operation.timeDone],
() =>
childrenShown ||
operation.timeDone == null ||
operation.result == ImportOperationResult.Error,
[childrenShown, operation.timeDone, operation.result],
)
const hasChildren = React.useMemo(
() => operation.children != null && operation.children.length > 0,
Expand Down
19 changes: 13 additions & 6 deletions editor/src/core/shared/github/operations/load-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import {
notifyOperationStarted,
startImportProcess,
} from '../../import/import-operation-service'
import { resetRequirementsResolutions } from '../../import/proejct-health-check/utopia-requirements-service'
import {
RequirementResolutionResult,
resetRequirementsResolutions,
} from '../../import/proejct-health-check/utopia-requirements-service'
import { checkAndFixUtopiaRequirements } from '../../import/proejct-health-check/check-utopia-requirements'
import { ImportOperationResult } from '../../import/import-operation-types'

Expand Down Expand Up @@ -171,8 +174,12 @@ export const updateProjectWithBranchContent =
notifyOperationFinished(dispatch, { type: 'parseFiles' }, ImportOperationResult.Success)

resetRequirementsResolutions(dispatch)
const { fixedProjectContents, result: requirementResolutionResult } =
checkAndFixUtopiaRequirements(dispatch, parseResults)

const parsedProjectContents = checkAndFixUtopiaRequirements(dispatch, parseResults)
if (requirementResolutionResult === RequirementResolutionResult.Critical) {
return []
}

// Update the editor with everything so that if anything else fails past this point
// there's no loss of data from the user's perspective.
Expand All @@ -185,19 +192,19 @@ export const updateProjectWithBranchContent =
branchName,
true,
),
updateProjectContents(parsedProjectContents),
updateBranchContents(parsedProjectContents),
updateProjectContents(fixedProjectContents),
updateBranchContents(fixedProjectContents),
truncateHistory(),
],
'everyone',
)

const componentDescriptorFiles =
getAllComponentDescriptorFilePaths(parsedProjectContents)
getAllComponentDescriptorFilePaths(fixedProjectContents)

// If there's a package.json file, then attempt to load the dependencies for it.
let dependenciesPromise: Promise<void> = Promise.resolve()
const packageJson = packageJsonFileFromProjectContents(parsedProjectContents)
const packageJson = packageJsonFileFromProjectContents(fixedProjectContents)
if (packageJson != null && isTextFile(packageJson)) {
notifyOperationStarted(dispatch, { type: 'refreshDependencies' })
dependenciesPromise = refreshDependencies(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ import type { EditorDispatch } from '../../../../components/editor/action-types'
import CheckPackageJson from './requirements/requirement-package-json'
import CheckLanguage from './requirements/requirement-language'
import CheckReactVersion from './requirements/requirement-react'
import { RequirementResolutionResult } from './utopia-requirements-types'
import type { ProjectRequirement, RequirementCheck } from './utopia-requirements-types'
import { notifyCheckingRequirement, notifyResolveRequirement } from './utopia-requirements-service'
import CheckStoryboard from './requirements/requirement-storyboard'

export function checkAndFixUtopiaRequirements(
dispatch: EditorDispatch,
parsedProjectContents: ProjectContentTreeRoot,
): ProjectContentTreeRoot {
): { result: RequirementResolutionResult; fixedProjectContents: ProjectContentTreeRoot } {
const checks: Record<ProjectRequirement, RequirementCheck> = {
storyboard: new CheckStoryboard(),
packageJsonEntries: new CheckPackageJson(),
language: new CheckLanguage(),
reactVersion: new CheckReactVersion(),
}
let projectContents = parsedProjectContents
let result: RequirementResolutionResult = RequirementResolutionResult.Found
// iterate over all checks, updating the project contents as we go
for (const [name, check] of Object.entries(checks)) {
const checkName = name as ProjectRequirement
notifyCheckingRequirement(dispatch, checkName, check.getStartText())
const checkResult = check.check(projectContents)
if (checkResult.resolution === RequirementResolutionResult.Critical) {
result = RequirementResolutionResult.Critical
}
notifyResolveRequirement(
dispatch,
checkName,
Expand All @@ -34,7 +39,7 @@ export function checkAndFixUtopiaRequirements(
)
projectContents = checkResult.newProjectContents ?? projectContents
}
return projectContents
return { result: result, fixedProjectContents: projectContents }
}

export function getPackageJson(
Expand Down
Loading