Skip to content

Commit

Permalink
cleanup some progress states in ChangeDetectionState
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed May 9, 2022
1 parent 4e2b090 commit 423b7bf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 34 deletions.
10 changes: 5 additions & 5 deletions packages/legend-studio/src/components/editor/ActivityBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export const ActivityBar = observer(() => {
const localChangesDisplayLabel = localChanges > 99 ? '99+' : localChanges;
const localChangesIndicatorStatusIcon =
editorStore.graphManagerState.graph.buildState.hasFailed ||
editorStore.changeDetectionState.forcedStop ? (
editorStore.changeDetectionState.initState.hasFailed ? (
<div />
) : !editorStore.changeDetectionState.isChangeDetectionRunning ||
) : !editorStore.changeDetectionState.initState.hasSucceeded ||
editorStore.changeDetectionState.workspaceLocalLatestRevisionState
.isBuildingEntityHashesIndex ||
editorStore.localChangesState.pushChangesState.isInProgress ? (
Expand Down Expand Up @@ -111,7 +111,7 @@ export const ActivityBar = observer(() => {
const conflictResolutionChangesIndicatorStatusIcon =
!editorStore.isInConflictResolutionMode ? (
<div />
) : !editorStore.changeDetectionState.isChangeDetectionRunning ||
) : !editorStore.changeDetectionState.initState.hasSucceeded ||
editorStore.changeDetectionState.workspaceBaseRevisionState
.isBuildingEntityHashesIndex ? (
<div
Expand All @@ -135,7 +135,7 @@ export const ActivityBar = observer(() => {
editorStore.changeDetectionState.aggregatedWorkspaceChanges.length;
const reviewChangesIndicatorStatusIcon = !reviewChanges ? (
<div />
) : !editorStore.changeDetectionState.isChangeDetectionRunning ||
) : !editorStore.changeDetectionState.initState.hasSucceeded ||
editorStore.changeDetectionState.workspaceBaseRevisionState
.isBuildingEntityHashesIndex ||
editorStore.changeDetectionState.workspaceLocalLatestRevisionState
Expand All @@ -154,7 +154,7 @@ export const ActivityBar = observer(() => {
editorStore.changeDetectionState.potentialWorkspaceUpdateConflicts.length;
const projectLatestChangesIndicatorStatusIcon = !workspaceUpdateChanges ? (
<div />
) : !editorStore.changeDetectionState.isChangeDetectionRunning ||
) : !editorStore.changeDetectionState.initState.hasSucceeded ||
editorStore.changeDetectionState.workspaceBaseRevisionState
.isBuildingEntityHashesIndex ||
editorStore.changeDetectionState.projectLatestRevisionState
Expand Down
28 changes: 14 additions & 14 deletions packages/legend-studio/src/components/editor/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ export const StatusBar = observer((props: { actionsDisabled: boolean }) => {
const pushLocalChanges = applicationStore.guardUnhandledError(() =>
flowResult(editorStore.localChangesState.pushLocalChanges()),
);
// TODO: we probably should refactor this, these messages are not that helpful and
// meant for different purposes
const pushStatusText =
editorStore.graphManagerState.graph.buildState.hasFailed ||
editorStore.changeDetectionState.forcedStop
editorStore.changeDetectionState.initState.hasFailed
? 'change detection halted'
: !editorStore.changeDetectionState.isChangeDetectionRunning
? !editorStore.changeDetectionState.hasChangeDetectionStarted
? 'starting change detection...'
: 'restarting change detection...'
: editorStore.changeDetectionState.workspaceLocalLatestRevisionState
: !editorStore.changeDetectionState.initState.hasSucceeded
? editorStore.changeDetectionState.workspaceLocalLatestRevisionState
.isBuildingEntityHashesIndex
? 'building indexes...'
? 'building indexes...'
: 'starting change detection...'
: editorStore.localChangesState.pushChangesState.isInProgress
? 'pushing local changes...'
: configurationState.isUpdatingConfiguration
Expand All @@ -99,17 +99,17 @@ export const StatusBar = observer((props: { actionsDisabled: boolean }) => {
const acceptConflictResolution = applicationStore.guardUnhandledError(() =>
flowResult(editorStore.conflictResolutionState.acceptConflictResolution()),
);
// TODO: we probably should refactor this, these messages are not that helpful and
// meant for different purposes
const conflictResolutionStatusText =
editorStore.graphManagerState.graph.buildState.hasFailed ||
editorStore.changeDetectionState.forcedStop
editorStore.changeDetectionState.initState.hasFailed
? 'change detection halted'
: !editorStore.changeDetectionState.isChangeDetectionRunning
? !editorStore.changeDetectionState.hasChangeDetectionStarted
? 'starting change detection...'
: 'restarting change detection...'
: editorStore.changeDetectionState.workspaceLocalLatestRevisionState
: !editorStore.changeDetectionState.initState.hasSucceeded
? editorStore.changeDetectionState.workspaceLocalLatestRevisionState
.isBuildingEntityHashesIndex
? 'building indexes...'
? 'building indexes...'
: 'starting change detection...'
: editorStore.conflictResolutionState.isAcceptingConflictResolution
? 'submitting conflict resolution...'
: conflicts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const LocalChanges = observer(() => {
disabled={
isDispatchingAction ||
editorStore.workspaceUpdaterState.isUpdatingWorkspace ||
!editorStore.changeDetectionState.isChangeDetectionRunning ||
!editorStore.changeDetectionState.initState.hasSucceeded ||
!editorStore.isInFormMode
}
tabIndex={-1}
Expand Down
18 changes: 6 additions & 12 deletions packages/legend-studio/src/stores/ChangeDetectionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ export class ChangeDetectionState {
editorStore: EditorStore;
graphState: EditorGraphState;
graphObserveState = ActionState.create();
// TODO: use ActionState for this
isChangeDetectionRunning = false;
hasChangeDetectionStarted = false;
forcedStop = false;
initState = ActionState.create();
/**
* Keep the list of disposers to deactivate `keepAlive` for computed value of element hash code.
* See {@link preComputeGraphElementHashes} for more details
Expand Down Expand Up @@ -279,9 +276,6 @@ export class ChangeDetectionState {

constructor(editorStore: EditorStore, graphState: EditorGraphState) {
makeObservable(this, {
isChangeDetectionRunning: observable,
hasChangeDetectionStarted: observable,
forcedStop: observable,
resolutions: observable,
projectLatestRevisionState: observable.ref,
conflictResolutionBaseRevisionState: observable.ref,
Expand Down Expand Up @@ -365,9 +359,10 @@ export class ChangeDetectionState {
this.graphObserveState.reset();
this.changeDetectionReaction?.();
this.changeDetectionReaction = undefined;
this.isChangeDetectionRunning = false;
if (force) {
this.forcedStop = true;
this.initState.fail();
} else {
this.initState.reset();
}
}

Expand Down Expand Up @@ -431,15 +426,13 @@ export class ChangeDetectionState {
delay: throttleDuration,
},
);
this.isChangeDetectionRunning = true;
this.hasChangeDetectionStarted = true;
this.forcedStop = false;

// dispose and remove the disposers for `keepAlive` computations for elements' hash code
this.graphElementHashCodeKeepAliveComputationDisposers.forEach((disposer) =>
disposer(),
);
this.graphElementHashCodeKeepAliveComputationDisposers = [];
this.initState.pass();
}

snapshotLocalEntityHashesIndex(quiet?: boolean): Map<string, string> {
Expand Down Expand Up @@ -781,6 +774,7 @@ export class ChangeDetectionState {
Date.now() - startTime,
'ms',
);
this.graphObserveState.setMessage(undefined);
this.graphObserveState.pass();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ export enum CONFIGURATION_EDITOR_TAB {
export class ProjectConfigurationEditorState extends EditorState {
sdlcState: EditorSDLCState;
originalProjectConfiguration?: ProjectConfiguration | undefined; // TODO: we might want to remove this when we do change detection for project configuration
isUpdatingConfiguration = false;
projectConfiguration?: ProjectConfiguration | undefined;
selectedTab: CONFIGURATION_EDITOR_TAB;
isReadOnly = false;
projects = new Map<string, ProjectData>();
queryHistory = new Set<string>();
latestProjectStructureVersion: ProjectStructureVersion | undefined;
isUpdatingConfiguration = false;
isQueryingProjects = false;
associatedProjectsAndVersionsFetched = false;
isFetchingAssociatedProjectsAndVersions = false;
latestProjectStructureVersion: ProjectStructureVersion | undefined;

constructor(editorStore: EditorStore, sdlcState: EditorSDLCState) {
super(editorStore);
Expand Down

0 comments on commit 423b7bf

Please sign in to comment.