-
Notifications
You must be signed in to change notification settings - Fork 44
fix(vscode): Adding a step in Kaoto VSCode takes several seconds #1338
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { | |
import { StepsService, VisualizationService } from '@kaoto/services'; | ||
import { useIntegrationJsonStore, useNestedStepsStore, useVisualizationStore } from '@kaoto/store'; | ||
import { IStepProps, IVizStepNode } from '@kaoto/types'; | ||
import { useEffect, useMemo, useRef, useState } from 'react'; | ||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
import ReactFlow, { Background, Viewport } from 'reactflow'; | ||
|
||
const Visualization = () => { | ||
|
@@ -25,8 +25,6 @@ const Visualization = () => { | |
zoom: 1.2, | ||
}; | ||
const [isPanelExpanded, setIsPanelExpanded] = useState(false); | ||
const [, setReactFlowInstance] = useState(null); | ||
const reactFlowWrapper = useRef(null); | ||
const [selectedStep, setSelectedStep] = useState<IStepProps>({ | ||
maxBranches: 0, | ||
minBranches: 0, | ||
|
@@ -40,7 +38,10 @@ const Visualization = () => { | |
const previousLayout = useRef(visualizationStore.layout); | ||
const previousIntegrationJson = useRef(integrationJsonStore.integrationJson); | ||
const visualizationService = new VisualizationService(integrationJsonStore, visualizationStore); | ||
const stepsService = new StepsService(integrationJsonStore, nestedStepsStore, visualizationStore); | ||
const stepsService = useMemo( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 just curious, should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a very interesting question 😃 From my point of view, I don't think that this is the definite way to go but a transition point. At first, the I think that a more appropriate fix would be to have this service as a context, this way we wouldn't need to create the service in different places but just call the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha! makes sense, thanks 👍 |
||
() => new StepsService(integrationJsonStore, nestedStepsStore, visualizationStore), | ||
[integrationJsonStore, nestedStepsStore, visualizationStore], | ||
); | ||
|
||
// initial loading of visualization steps | ||
useEffect(() => { | ||
|
@@ -109,7 +110,7 @@ const Visualization = () => { | |
* @param e | ||
* @param node | ||
*/ | ||
const onNodeClick = (e: any, node: IVizStepNode) => { | ||
const onNodeClick = useCallback((e: any, node: IVizStepNode) => { | ||
// here we check if it's a node or edge | ||
// workaround for https://github.com/wbkd/react-flow/issues/2202 | ||
if (!e.target.classList.contains('stepNode__clickable')) return; | ||
|
@@ -132,11 +133,7 @@ const Visualization = () => { | |
visualizationStore.setSelectedStepUuid(''); | ||
} | ||
} | ||
}; | ||
|
||
const onLoad = (_reactFlowInstance: any) => { | ||
setReactFlowInstance(_reactFlowInstance); | ||
}; | ||
}, [isPanelExpanded, selectedStep.UUID, stepsService, visualizationStore]); | ||
|
||
/** | ||
* Handles Step View configuration changes | ||
|
@@ -152,8 +149,8 @@ const Visualization = () => { | |
<KaotoDrawer | ||
isExpanded={isPanelExpanded} | ||
data-expanded={isPanelExpanded} | ||
isResizable={true} | ||
dataTestId={'kaoto-right-drawer'} | ||
isResizable | ||
dataTestId="kaoto-right-drawer" | ||
panelContent={ | ||
<VisualizationStepViews | ||
step={selectedStep} | ||
|
@@ -162,19 +159,14 @@ const Visualization = () => { | |
saveConfig={saveConfig} | ||
/> | ||
} | ||
position={'right'} | ||
id={'right-resize-panel'} | ||
defaultSize={'500px'} | ||
minSize={'150px'} | ||
position="right" | ||
id="right-resize-panel" | ||
defaultSize="500px" | ||
minSize="150px" | ||
> | ||
<div | ||
className="reactflow-wrapper" | ||
data-testid={'react-flow-wrapper'} | ||
ref={reactFlowWrapper} | ||
style={{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to the corresponding |
||
width: '100vw', | ||
height: 'calc(100vh - 77px )', | ||
}} | ||
data-testid="react-flow-wrapper" | ||
> | ||
<ReactFlow | ||
nodes={visualizationStore.nodes} | ||
|
@@ -186,7 +178,6 @@ const Visualization = () => { | |
onNodeClick={onNodeClick} | ||
onNodesChange={visualizationStore.onNodesChange} | ||
onEdgesChange={visualizationStore.onEdgesChange} | ||
onLoad={onLoad} | ||
snapToGrid={true} | ||
snapGrid={[15, 15]} | ||
deleteKeyCode={null} | ||
|
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.
@kahboom is this needed? I think that it forces a render but I don't know if there another use case for it 🤔
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.
confession time--I have no idea. I think that might have been from an older version of React Flow, but I can't be sure. 😅 We can remove it, just be sure to check rendering still happens as needed with the basic actions (for example replacing from big catalog, deleting steps, editing config, etc.)
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.
Mmm, I think that you're right, I checked here and it seems that it's also deprecated.