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: add auto-scroll to canvas elements when selected from panel #3344

Merged
merged 32 commits into from
May 2, 2024

Conversation

b4s36t4
Copy link
Contributor

@b4s36t4 b4s36t4 commented Mar 29, 2024

Closes #3338

Adds auto-scroll to page canvas when element selected from the component panel.

  • I've read and followed the contributing guide on how to create great pull requests.
  • I've updated the relevant documentation for any new or updated feature.
  • I've linked relevant GitHub issue with "Closes #".
  • I've added a visual demonstration in the form of a screenshot or video.
Kapture.2024-03-29.at.00.37.24.mp4

Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

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

It looks great to me, just added some very minor comments!
But it's not scrolling to the elements for me on Google Chrome? Not sure what might be wrong about that or if it's just on my browser...

if (!nodeId) {
return;
}
invariant(appRootRef.current, 'App root not found');
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you can also just check if appRootRef.current is truthy instead of using invariant and just return if not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just copy pasted that line for the one of the command written above, should I remove the invariant?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, not a big deal but I think it makes more sense to just not scroll if this ref isn't there yet.

@b4s36t4
Copy link
Contributor Author

b4s36t4 commented Mar 30, 2024

But it's not scrolling to the elements for me on Google Chrome?

Do you see any error or if possible can you also try on some other browser? I'm using brave which basically chrome and it's working fine for me.

@apedroferreira
Copy link
Member

apedroferreira commented Apr 1, 2024

But it's not scrolling to the elements for me on Google Chrome?

Do you see any error or if possible can you also try on some other browser? I'm using brave which basically chrome and it's working fine for me.

No errors at all, I tried to debug but couldn't find what's wrong so far... doesn't seem to work for me in other browsers either.
I've asked some team members to see if it works for them - if it does we can probably merge this and I can investigate my case later.

@bharatkashyap
Copy link
Member

Doesn't seem to work for me either in Brave:

Screen.Recording.2024-04-03.at.6.31.45.PM.mov

@apedroferreira
Copy link
Member

But it's not scrolling to the elements for me on Google Chrome?

Do you see any error or if possible can you also try on some other browser? I'm using brave which basically chrome and it's working fine for me.

Ah, I just realized that I had the process.env.EXPERIMENTAL_INLINE_CANVAS flag on.
So for that mode we probably just have to target a different ref to be able to scroll,overlayRef.current seems to work!
Other than that the logic should be the same. Sorry for forgetting about that experimental mode!

@@ -152,6 +151,15 @@ export default function AppCanvas({ basename, state: initialState }: AppCanvasPr
return { nodes };
});

setCommandHandler(bridge.canvasCommands, 'scrollComponent', (nodeId) => {
if (!nodeId) {
Copy link
Member

@apedroferreira apedroferreira Apr 3, 2024

Choose a reason for hiding this comment

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

Just another thing I noticed, not very important either: when you call scrollComponent from the RenderOverlay component you already check if selectedNode is defined. So I guess that we don't need to check if nodeId is set here?

@Janpot
Copy link
Member

Janpot commented Apr 4, 2024

Thank you for looking into this feature. Works well (on classic canvas mode). The inline canvas will be the default soon, we should make sure the scroll keeps working under that mode. I've also pushed an integration test for scroll behavior on your PR.

For context: the inline canvas mode removes the iframe from the Toolpad editor in which the Toolpad app runs and runs the Toolpad editor + Toolpad application in the same React tree. The ultimate goal for this is to eventually be able to run Toolpad as a React component inside of Next.js (or any other React runtime). You can try out this mode out by adding a .env file that contains:

EXPERIMENTAL_INLINE_CANVAS=1

Currently the code for this contains some complexity to support both modes but we should be able to simplify as soon as the iframe is discontinued. Apologies for the inconvenience.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 9, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 26, 2024
@b4s36t4
Copy link
Contributor Author

b4s36t4 commented Apr 26, 2024

Hi, guys. Sorry was away for past few days. I'm good with the changes for the new canvas made the changes in both old canvas and new canvas container can you guys take a look.

I'm not sure to remove the code/refactor the changes for the old canvas container, if needed please let me know will do the needful changes

@Janpot @apedroferreira

Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

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

Looks great to me! Thanks for adding a snapshot test too.

@Janpot
Copy link
Member

Janpot commented May 2, 2024

great work, thank you! I've resetted the changes to the test fixture as it seems to be unnecessary

@Janpot Janpot merged commit 8a989bd into mui:master May 2, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Elements in the canvas should scroll into view after selection
4 participants