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(Canvas): Replace autofit by keeping zoom level and ensuring selected item is visible #1469

Merged
merged 5 commits into from
Sep 26, 2024

Conversation

lordrip
Copy link
Member

@lordrip lordrip commented Sep 23, 2024

Context

Currently, when selecting a node in the canvas, there is an existing functionality to center the view.
This helps to keep the flow visible at all times, especially in cases when the side panel might overlap the flow.

With complex flows, this behavior turns out to be problematic, as the user might be zooming over a section of the flow, and then selecting a node, effectively moving the viewport somewhere else.

In addition to that, when using chromium-based browsers, navigating from a page to the Design page, makes the nodes render distorted.

There are a few elements contributing to this behavior, first of all, the visible-flow provider was initialized to {}, causing the Canvas component to be rendered twice, and after that, it seems like the useEffect callback that called controller.fromModal was batched after the VisualizationSurface was initialized, missing the update.

Changes

The fix for the former is to remove the auto-center functionality so the zoom is kept between node editing, and for the latter, the fix is to replace the useEffect callback with useLayoutEffect to ensure the nodes and edges are available before the VisualizationSurface component.

Notes

Both fixes are complementary to each other, so they need to be merged together.

fix: #1352
fix: https://issues.redhat.com/browse/KTO-461

@lordrip lordrip force-pushed the fix/remove-autozoom branch from 26f3f20 to 4ab3e40 Compare September 23, 2024 11:29
Comment on lines 192 to 204
useEffect(() => {
const timeoutId = setTimeout(
action(() => {
controller.getGraph().fit(80);
}),
500,
);

return () => {
clearTimeout(timeoutId);
};
}, [controller, selectedIds]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the zoom-out functionality to fit the entire flow.

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 54.66667% with 34 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@19d3095). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../ui/src/components/Visualization/Canvas/Canvas.tsx 35.55% 29 Missing ⚠️
.../ui/src/components/Visualization/Visualization.tsx 0.00% 3 Missing ⚠️
...ents/Visualization/EmptyState/FlowType/NewFlow.tsx 0.00% 1 Missing ⚠️
...ckages/ui/src/providers/visible-flows.provider.tsx 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1469   +/-   ##
=======================================
  Coverage        ?   68.98%           
  Complexity      ?       26           
=======================================
  Files           ?      272           
  Lines           ?     7752           
  Branches        ?     1496           
=======================================
  Hits            ?     5348           
  Misses          ?     2401           
  Partials        ?        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@dlabaj dlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment on the issue you were seeing. Just something I noticed with a quick look.

Copy link
Member

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • several tests are failing
  • in VS Code, the properties panel is not opening anymore

EDIT: infact, the properties panel is not opening either with standalone mode

@apupier
Copy link
Member

apupier commented Sep 24, 2024

note: for a more positive vision (and I think more accurate), I would replace
fix(Canvas): Remove Autozoom functionality by something like: feat(Canvas): Replace autofit by keeping zoom level and ensuring selected item is visible

@lordrip lordrip changed the title fix(Canvas): Remove Autozoom functionality feat(Canvas): Replace autofit by keeping zoom level and ensuring selected item is visible Sep 24, 2024
const lastUpdate = useMemo(() => Date.now(), [props.entities]);

return (
<div className={`canvas-surface ${props.className ?? ''}`}>
<ErrorBoundary key={lastUpdate} fallback={props.fallback ?? <CanvasFallback />}>
<VisualizationProvider controller={controller}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the VisualizationProvider here, to avoid recreating it whenever the entities array change.

cc @jeff-phillips-18

Comment on lines 90 to 92
requestAnimationFrame(() => {
controller.fromModel(model, true);
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the requestAnimationFrame
cc @jeff-phillips-18

@lhein lhein requested a review from apupier September 25, 2024 10:53
Copy link
Member

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the route list toolbar style is no more aligned:
image
image

Currently, when selecting a node in the canvas, there is an existing fuctionality to center the view.
This helps to keep the flow visible at all times, especially in cases when the side panel might overlap the flow.

With complex flows, this behavior turns to be problematic, as the user
might be zooming over a section of the flow, then selecting a node,
effectively moving the viewport somewhere else.

The fix is to remove the auto-center functionality so the zoom is ketp
between node editing.

fix: https://issues.redhat.com/browse/KTO-461
Currently, the visible-flow provider is initialized to an empty object `{}` and then updated through an `useEffect()`, causing that for the first render, it gets rendered twice.

The fix is to use the `initializer` paramter from the `useReducer` hook.
Currently, when using chromium-based browsers, navigating to from a page
to the Design page, makes the nodes render distorted.

There are a few elements contributing to this behavior, first of all,
the `visible-flow` provider was initialized to `{}`, causing to the `Canvas`
component to be rendered twice, and after that, it seems like the
`useEffect` callback that called `controller.fromModal` was batched
after the `VisualizationSurface` was initialized, missing the update.

The fix is to replace the `useEffect` callback with `useLayoutEffect` to
ensure the nodes and edges are available before the `VisualizationSurface`
component.

fix: KaotoIO#1352
In order to preserve the nodes visible when opening the configuration
panel, this commit schedules a `panIntoView` command to the selected
node, preserving the zoom level while aiming for the less movement
possible to make the node visible.

relates: https://issues.redhat.com/browse/KTO-461
@lordrip lordrip force-pushed the fix/remove-autozoom branch 2 times, most recently from a17e379 to 7a6d574 Compare September 26, 2024 07:42
When rendering the graph, we can see some flickering in a few
situations:

1. The app is loaded for the first time or refreshed
2. Switching between no routes in the canvas and a adding a route
3. Navigating to a pages and go backto the design page
4. Disabling and enabling steps in the canvas
5. Switching the layout between horizontal and vertical

The fix for those situations is:
1. Adding an `initialized` state to
@lordrip lordrip force-pushed the fix/remove-autozoom branch from 7a6d574 to ed422f6 Compare September 26, 2024 07:43
Copy link

sonarcloud bot commented Sep 26, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
6.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@lordrip lordrip requested a review from apupier September 26, 2024 09:23
Copy link
Member

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On functional side, I tested in VS Code and I have not found any problems.

Note that I do not understand the code changes and how it impacts the behavior change.

@lordrip lordrip merged commit b0291b5 into KaotoIO:main Sep 26, 2024
10 of 12 checks passed
@lordrip
Copy link
Member Author

lordrip commented Sep 26, 2024

Thanks @apupier for the reviews 👍

@lordrip lordrip deleted the fix/remove-autozoom branch September 26, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Distorted UI on the design Page if navigated back from a different page
3 participants