Skip to content

Commit

Permalink
move state to editorState
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Oct 10, 2024
1 parent 120a6f2 commit 4e96929
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 68 deletions.
9 changes: 8 additions & 1 deletion editor/src/components/editor/action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import type {
ColorSwatch,
PostActionMenuData,
ErrorBoundaryHandling,
ProjectRequirements,
} from './store/editor-state'
import type { Notice } from '../common/notice'
import type { LoginState } from '../../common/user'
Expand Down Expand Up @@ -1007,6 +1008,11 @@ export interface UpdateImportOperations {
type: ImportOperationAction
}

export interface UpdateProjectRequirements {
action: 'UPDATE_PROJECT_REQUIREMENTS'
requirements: Partial<ProjectRequirements>
}

export interface SetRefreshingDependencies {
action: 'SET_REFRESHING_DEPENDENCIES'
value: boolean
Expand Down Expand Up @@ -1370,6 +1376,8 @@ export type EditorAction =
| SetImageDragSessionState
| UpdateGithubOperations
| UpdateImportOperations
| UpdateProjectRequirements
| SetImportWizardOpen
| UpdateBranchContents
| SetRefreshingDependencies
| ApplyCommandsAction
Expand All @@ -1393,7 +1401,6 @@ export type EditorAction =
| SetCollaborators
| ExtractPropertyControlsFromDescriptorFiles
| SetSharingDialogOpen
| SetImportWizardOpen
| ResetOnlineState
| IncreaseOnlineStateFailureCount
| SetErrorBoundaryHandling
Expand Down
25 changes: 18 additions & 7 deletions editor/src/components/editor/actions/action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ import type {
SetErrorBoundaryHandling,
SetImportWizardOpen,
UpdateImportOperations,
UpdateProjectRequirements,
} from '../action-types'
import type { InsertionSubjectWrapper, Mode } from '../editor-modes'
import { EditorModes, insertionSubject } from '../editor-modes'
Expand All @@ -259,6 +260,7 @@ import type {
ColorSwatch,
PostActionMenuData,
ErrorBoundaryHandling,
ProjectRequirements,
} from '../store/editor-state'
import type { InsertionPath } from '../store/insertion-path'
import type { TextProp } from '../../text-editor/text-editor'
Expand Down Expand Up @@ -1608,6 +1610,22 @@ export function updateImportOperations(
}
}

export function updateProjectRequirements(
requirements: Partial<ProjectRequirements>,
): UpdateProjectRequirements {
return {
action: 'UPDATE_PROJECT_REQUIREMENTS',
requirements: requirements,
}
}

export function setImportWizardOpen(open: boolean): SetImportWizardOpen {
return {
action: 'SET_IMPORT_WIZARD_OPEN',
open: open,
}
}

export function setFilebrowserDropTarget(target: string | null): SetFilebrowserDropTarget {
return {
action: 'SET_FILEBROWSER_DROPTARGET',
Expand Down Expand Up @@ -1893,13 +1911,6 @@ export function setSharingDialogOpen(open: boolean): SetSharingDialogOpen {
}
}

export function setImportWizardOpen(open: boolean): SetImportWizardOpen {
return {
action: 'SET_IMPORT_WIZARD_OPEN',
open: open,
}
}

export function resetOnlineState(): ResetOnlineState {
return {
action: 'RESET_ONLINE_STATE',
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 @@ -139,6 +139,7 @@ export function isTransientAction(action: EditorAction): boolean {
case 'SET_ERROR_BOUNDARY_HANDLING':
case 'SET_IMPORT_WIZARD_OPEN':
case 'UPDATE_IMPORT_OPERATIONS':
case 'UPDATE_PROJECT_REQUIREMENTS':
return true

case 'TRUE_UP_ELEMENTS':
Expand Down
27 changes: 20 additions & 7 deletions editor/src/components/editor/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ import type {
SetErrorBoundaryHandling,
SetImportWizardOpen,
UpdateImportOperations,
UpdateProjectRequirements,
} from '../action-types'
import { isAlignment, isLoggedIn } from '../action-types'
import type { Mode } from '../editor-modes'
Expand Down Expand Up @@ -637,6 +638,7 @@ import {
notifyCheckingRequirement,
notifyResolveRequirement,
RequirementResolutionResult,
updateRequirements,
} from '../../../core/shared/import/utopia-requirements-service'

export const MIN_CODE_PANE_REOPEN_WIDTH = 100
Expand Down Expand Up @@ -1042,6 +1044,8 @@ export function restoreEditorState(
imageDragSessionState: currentEditor.imageDragSessionState,
githubOperations: currentEditor.githubOperations,
importOperations: currentEditor.importOperations,
projectRequirements: currentEditor.projectRequirements,
importWizardOpen: currentEditor.importWizardOpen,
branchOriginContents: currentEditor.branchOriginContents,
githubData: currentEditor.githubData,
refreshingDependencies: currentEditor.refreshingDependencies,
Expand All @@ -1053,7 +1057,6 @@ export function restoreEditorState(
forking: currentEditor.forking,
collaborators: currentEditor.collaborators,
sharingDialogOpen: currentEditor.sharingDialogOpen,
importWizardOpen: currentEditor.importWizardOpen,
editorRemixConfig: currentEditor.editorRemixConfig,
}
}
Expand Down Expand Up @@ -2270,6 +2273,22 @@ export const UPDATE_FNS = {
importOperations: resultImportOperations,
}
},
UPDATE_PROJECT_REQUIREMENTS: (
action: UpdateProjectRequirements,
editor: EditorModel,
): EditorModel => {
const result = updateRequirements(editor.projectRequirements, action.requirements)
return {
...editor,
projectRequirements: result,
}
},
SET_IMPORT_WIZARD_OPEN: (action: SetImportWizardOpen, editor: EditorModel): EditorModel => {
return {
...editor,
importWizardOpen: action.open,
}
},
SET_REFRESHING_DEPENDENCIES: (
action: SetRefreshingDependencies,
editor: EditorModel,
Expand Down Expand Up @@ -6159,12 +6178,6 @@ export const UPDATE_FNS = {
sharingDialogOpen: action.open,
}
},
SET_IMPORT_WIZARD_OPEN: (action: SetImportWizardOpen, editor: EditorModel): EditorModel => {
return {
...editor,
importWizardOpen: action.open,
}
},
SET_ERROR_BOUNDARY_HANDLING: (
action: SetErrorBoundaryHandling,
editor: EditorModel,
Expand Down
70 changes: 70 additions & 0 deletions editor/src/components/editor/store/editor-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ import type { NavigatorRow } from '../../navigator/navigator-row'
import type { FancyError } from '../../../core/shared/code-exec-utils'
import type { GridCellCoordinates } from '../../canvas/canvas-strategies/strategies/grid-cell-bounds'
import type { ImportOperation } from '../../../core/shared/import/import-operation-types'
import type { RequirementResolutionResult } from '../../../core/shared/import/utopia-requirements-service'

const ObjectPathImmutable: any = OPI

Expand Down Expand Up @@ -1163,6 +1164,70 @@ export interface PullRequest {
number: number
}

export interface RequirementResolution {
status: RequirementResolutionStatus
value?: string | null
resolution?: RequirementResolutionResult | null
}

export function requirementResolution(
status: RequirementResolutionStatus,
value?: string | null,
resolution?: RequirementResolutionResult | null,
): RequirementResolution {
return {
status,
value,
resolution,
}
}

export interface ProjectRequirements {
storyboard: RequirementResolution
packageJsonEntries: RequirementResolution
language: RequirementResolution
reactVersion: RequirementResolution
}

export type ProjectRequirement = keyof ProjectRequirements

export function newProjectRequirements(
storyboard: RequirementResolution,
packageJsonEntries: RequirementResolution,
language: RequirementResolution,
reactVersion: RequirementResolution,
): ProjectRequirements {
return {
storyboard,
packageJsonEntries,
language,
reactVersion,
}
}

export enum RequirementResolutionStatus {
NotStarted = 'not-started',
Pending = 'pending',
Done = 'done',
}

export function emptyRequirementResolution(): RequirementResolution {
return {
status: RequirementResolutionStatus.NotStarted,
value: null,
resolution: null,
}
}

export function emptyProjectRequirements(): ProjectRequirements {
return newProjectRequirements(
emptyRequirementResolution(),
emptyRequirementResolution(),
emptyRequirementResolution(),
emptyRequirementResolution(),
)
}

export interface ProjectGithubSettings {
targetRepository: GithubRepo | null
originCommit: string | null
Expand Down Expand Up @@ -1454,6 +1519,7 @@ export interface EditorState {
imageDragSessionState: ImageDragSessionState
githubOperations: Array<GithubOperation>
importOperations: Array<ImportOperation>
projectRequirements: ProjectRequirements
githubData: GithubData
refreshingDependencies: boolean
colorSwatches: Array<ColorSwatch>
Expand Down Expand Up @@ -1551,6 +1617,7 @@ export function editorState(
collaborators: Collaborator[],
sharingDialogOpen: boolean,
importWizardOpen: boolean,
projectRequirements: ProjectRequirements,
remixConfig: EditorRemixConfig,
): EditorState {
return {
Expand Down Expand Up @@ -1636,6 +1703,7 @@ export function editorState(
collaborators: collaborators,
sharingDialogOpen: sharingDialogOpen,
importWizardOpen: importWizardOpen,
projectRequirements: projectRequirements,
editorRemixConfig: remixConfig,
}
}
Expand Down Expand Up @@ -2719,6 +2787,7 @@ export function createEditorState(dispatch: EditorDispatch): EditorState {
collaborators: [],
sharingDialogOpen: false,
importWizardOpen: false,
projectRequirements: emptyProjectRequirements(),
editorRemixConfig: {
errorBoundaryHandling: 'ignore-error-boundaries',
},
Expand Down Expand Up @@ -3088,6 +3157,7 @@ export function editorModelFromPersistentModel(
collaborators: [],
sharingDialogOpen: false,
importWizardOpen: false,
projectRequirements: emptyProjectRequirements(),
editorRemixConfig: {
errorBoundaryHandling: 'ignore-error-boundaries',
},
Expand Down
2 changes: 2 additions & 0 deletions editor/src/components/editor/store/editor-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export function runSimpleLocalEditorAction(
return UPDATE_FNS.UPDATE_IMPORT_OPERATIONS(action, state)
case 'SET_IMPORT_WIZARD_OPEN':
return UPDATE_FNS.SET_IMPORT_WIZARD_OPEN(action, state)
case 'UPDATE_PROJECT_REQUIREMENTS':
return UPDATE_FNS.UPDATE_PROJECT_REQUIREMENTS(action, state)
case 'REMOVE_TOAST':
return UPDATE_FNS.REMOVE_TOAST(action, state)
case 'SET_HIGHLIGHTED_VIEWS':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ import type {
EditorRemixConfig,
ErrorBoundaryHandling,
GridControlData,
ProjectRequirements,
RequirementResolution,
} from './editor-state'
import {
trueUpGroupElementChanged,
Expand All @@ -374,6 +376,8 @@ import {
newGithubData,
renderedAtPropertyPath,
renderedAtChildNode,
requirementResolution,
newProjectRequirements,
} from './editor-state'
import {
editorStateNodeModules,
Expand Down Expand Up @@ -4756,6 +4760,30 @@ export const ProjectGithubSettingsKeepDeepEquality: KeepDeepEqualityCall<Project
projectGithubSettings,
)

export const ProjectRequirementResolutionKeepDeepEquality: KeepDeepEqualityCall<RequirementResolution> =
combine3EqualityCalls(
(resolution) => resolution.status,
createCallWithTripleEquals(),
(resolution) => resolution.value,
createCallWithTripleEquals(),
(resolution) => resolution.resolution,
createCallWithTripleEquals(),
requirementResolution,
)

export const ProjectRequirementsKeepDeepEquality: KeepDeepEqualityCall<ProjectRequirements> =
combine4EqualityCalls(
(requirements) => requirements.storyboard,
ProjectRequirementResolutionKeepDeepEquality,
(requirements) => requirements.packageJsonEntries,
ProjectRequirementResolutionKeepDeepEquality,
(requirements) => requirements.language,
ProjectRequirementResolutionKeepDeepEquality,
(requirements) => requirements.reactVersion,
ProjectRequirementResolutionKeepDeepEquality,
newProjectRequirements,
)

export const GithubFileChangesKeepDeepEquality: KeepDeepEqualityCall<GithubFileChanges> =
combine3EqualityCalls(
(settings) => settings.modified,
Expand Down Expand Up @@ -5379,6 +5407,16 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
newValue.importOperations,
)

const importWizardOpenResults = BooleanKeepDeepEquality(
oldValue.importWizardOpen,
newValue.importWizardOpen,
)

const projectRequirementsResults = ProjectRequirementsKeepDeepEquality(
oldValue.projectRequirements,
newValue.projectRequirements,
)

const branchContentsResults = nullableDeepEquality(ProjectContentTreeRootKeepDeepEquality())(
oldValue.branchOriginContents,
newValue.branchOriginContents,
Expand Down Expand Up @@ -5426,11 +5464,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
newValue.sharingDialogOpen,
)

const importWizardOpenResults = BooleanKeepDeepEquality(
oldValue.importWizardOpen,
newValue.importWizardOpen,
)

const remixConfigResults = RemixConfigKeepDeepEquality(
oldValue.editorRemixConfig,
newValue.editorRemixConfig,
Expand Down Expand Up @@ -5506,6 +5539,8 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
imageDragSessionStateEqual.areEqual &&
githubOperationsResults.areEqual &&
importOperationsResults.areEqual &&
importWizardOpenResults.areEqual &&
projectRequirementsResults.areEqual &&
branchContentsResults.areEqual &&
githubDataResults.areEqual &&
refreshingDependenciesResults.areEqual &&
Expand All @@ -5517,7 +5552,6 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
forkingResults.areEqual &&
collaboratorsResults.areEqual &&
sharingDialogOpenResults.areEqual &&
importWizardOpenResults.areEqual &&
remixConfigResults.areEqual

if (areEqual) {
Expand Down Expand Up @@ -5606,6 +5640,7 @@ export const EditorStateKeepDeepEquality: KeepDeepEqualityCall<EditorState> = (
collaboratorsResults.value,
sharingDialogOpenResults.value,
importWizardOpenResults.value,
projectRequirementsResults.value,
remixConfigResults.value,
)

Expand Down
Loading

0 comments on commit 4e96929

Please sign in to comment.