-
Notifications
You must be signed in to change notification settings - Fork 116
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
Refactor code in EditorStore
to separate out logic for FormMode and TextMode
#1898
Conversation
🦋 Changeset detectedLatest commit: 002fa85 The changes in this PR will be included in the next version bump. This PR includes changesets to release 28 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
EditorStore
to separate out logic for FormMode and TextMode
0d3d6d7
to
d711374
Compare
Codecov Report
@@ Coverage Diff @@
## master #1898 +/- ##
==========================================
- Coverage 40.32% 40.30% -0.02%
==========================================
Files 1444 1447 +3
Lines 65971 66016 +45
Branches 15492 15494 +2
==========================================
+ Hits 26601 26607 +6
- Misses 39268 39308 +40
+ Partials 102 101 -1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface makes sense to me, just left some minor comments on further cleanups we can do.
I haven't reviewed in-depth movement of code logic in EditorGraphState.ts
and GraphEditModeManagerState.ts
- I assume you just moved over code logic, if that's the case, nothing much to check there I think.
My concern is with the switchMode
we do in GraphEditorModeManagerState
, to me that the fact we need a source mode and the target mode seems unnecessary and can be simplified
packages/legend-application-studio/src/components/editor/StatusBar.tsx
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/components/editor/aux-panel/Problems.tsx
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/components/editor/edit-panel/GrammarTextEditor.tsx
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/EmbeddedQueryBuilderState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/sidebar-state/LocalChangesState.ts
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/project-viewer/ProjectViewerStore.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/GraphEditModeManagerState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/GraphEditModeManagerState.ts
Outdated
Show resolved
Hide resolved
I agree having source mode and target mode in switch mode currently doesn't make much sense as we know what to do when we are entering a garph edit mode. But when we have multi file support knowing source mode and target mode is useful as the set of operations we do is different. |
b655d41
to
88d411c
Compare
packages/legend-extension-dsl-diagram/src/stores/studio/DiagramEditorState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/EditorGraphState.ts
Outdated
Show resolved
Hide resolved
bea20e8
to
52c338b
Compare
packages/legend-application-studio/src/stores/EditorTabManagerState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/components/__tests__/LegendStudioExplorerTree.test.tsx
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/components/__tests__/EmbeddedQueryBuilder.test.tsx
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/components/__tests__/ClassQueryBuilder.test.tsx
Outdated
Show resolved
Hide resolved
isGraphBuildFailure: true, | ||
}), | ||
); | ||
if (this.editorStore.isInFormMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention, the biggest thing about this task is that we must remove isInFormMode
and isInTextmode
from EditorStore
, those methods should not be needed, we should add methods to the interface everywhere we see differentiating behavior like this.
packages/legend-application-studio/src/stores/GraphEditModeManagerState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/GraphEditModeManagerState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/GraphEditModeManagerState.ts
Outdated
Show resolved
Hide resolved
packages/legend-application-studio/src/stores/GraphEditModeManagerState.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some minor comments, like last time, the one thing that gates me from fully accepting this change is the complexity in switchMode()
; like any function of this type, if we can break it into consistent, simple interface function call that would be great, from my perspective, changing mode is an operation that is used by higher-level code that has no knowledge of the mode implementation, what we're doing here is practically leaking of mode-specific logic.
Now, the only 3 places we should allow this sort of thing to me are:
- When switching mode since we have to explicitly mention the mode to switch to
- When displaying the mode switcher button (maybe, right now we have binary-state button, but if we have a dropdown or selector, this can even go away)
- When we initialize the mode in
EditorStore
or so, we are biased since we have to pick a default
{editable && editorStore.isInGrammarTextMode && ( | ||
<GrammarTextEditor /> | ||
)} | ||
editorStore.graphEditorMode.mode === |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not so satisfied with this, but we can deal with this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment below for ProjectViewer
@@ -64,7 +58,8 @@ const ProblemItem = observer((props: { problem: Problem }) => { | |||
</div> | |||
{problem.sourceInformation && ( | |||
<div className="auxiliary-panel__problem__source"> | |||
{editorStore.isInGrammarTextMode && | |||
{editorStore.graphEditorMode.mode === |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially if we have a place in rendering code layer to handle differentiating codepath, this is a good candidate to add there, together with all places we have to use editorStore.graphEditorMode.mode
since although we decompose well at the state layer, our rendering is still messy
), | ||
); | ||
} catch { | ||
yield flowResult( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note, here we're making assumption we're already in form mode, what if we're not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function gets called only when we initialize studio. So the mode we are in would be FORM
import { LegendStudioTelemetry } from './LegendStudioTelemetry.js'; | ||
import { GraphEditorMode } from './GraphEditorMode.js'; | ||
|
||
export class GraphEditFormModeState extends GraphEditorMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--> FormGraphEditMode
, also rename the file
import { GraphEditorMode } from './GraphEditorMode.js'; | ||
import { ElementEditorState } from './editor-state/element-editor-state/ElementEditorState.js'; | ||
|
||
export class GraphEditSingleFileGrammarModeState extends GraphEditorMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--> SingleFileGrammarGraphEditMode
(also rename the file)
@@ -1187,11 +894,73 @@ export class EditorStore implements CommandRegistrar { | |||
); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably can move these 2 methods to inside of EditorGraphState
now
@@ -169,8 +134,8 @@ export class EditorStore implements CommandRegistrar { | |||
sdlcState: EditorSDLCState; | |||
graphState: EditorGraphState; | |||
graphManagerState: GraphManagerState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, in terms of organization at EditorStore
level, I think we should move EditorStore.graphEditorMode
to EditorStore.graphState.mode
, I want us to start thinking about how we organize this. Maybe, what we should do is extending GraphManagerState
and have LegendStudioGraphManagerState
or something and put all graph handling logic of EditorGraphState
in there, but colocating GraphEditorMode
with EditorGraphState
is sensible as it is what we had before
const graphEditorMode = new GraphEditSingleFileGrammarModeState(this); | ||
try { | ||
yield flowResult( | ||
graphEditorMode.cleanupBeforeEntering(fallbackOptions), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we still calling different set of methods when switching mode? I felt like we can also following a fix procedure, i.e. simplifying this down to bare-bone mode-independent logic, i.e.
attempt to leave and cleanup current mode
check if we can enter target mode
initialize target mode
switch to new mode
this.localChangesState = new TextLocalChangesState(this, this.sdlcState); | ||
*switchModes( | ||
to: GRAPH_EDITOR_MODE, | ||
fallbackOptions?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can sleep on this for now, worst case, we have different set of methods: handleGraphBuilderFailure()
and handleCompilationFailure()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like said, let's address comments here in a later PR, the organization benefit we got out of this PR is already huge. Thanks @gayathrir11!!
Summary
How did you test this change?