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

Fix and improve resizing in editor (incl. Add Spacer component) #2818

Merged
merged 47 commits into from
Feb 23, 2024

Conversation

apedroferreira
Copy link
Member

@apedroferreira apedroferreira commented Oct 20, 2023

I've tried to bring back this old PR so we can merge it instead of just closing, it's a bit large though... The Spacer component could be separated.

Improves resizing and allows for more control over spacing in the editor overall:

  • Some improvements to the editor such as getting rid of single columns in a page (pages are already columns), and spreading columns in pages if a column moves to a page after a deleting/moving an element.
  • Component API changes: Instead of a resizableHeightProp, make it possible to set a defaultLayoutHeight and minimumLayoutHeight for each component. This means that all components can be resized using the same system, but for now to avoid bugs I've kept the old resizing behavior: only charts and data grid are resizable, and only from the bottom border. This way no new bugs are introduced until we find solutions for some issues in the UX, but this new system is already there.
  • Adds a new Spacer component that can be used just to create white space. Maybe it could be useful but we can remove it from this PR too.

Spacer component demo:

Screen.Recording.2024-02-23.at.16.48.11.mov

Column spread demo:

Screen.Recording.2024-02-23.at.16.48.55.mov

Improved resizing demo (all components would be resizable + could be resized from top border, but this feature shown here is commented out for now as it still has some poor UX to improve in some scenarios):

Screen.Recording.2024-02-23.at.16.50.40.mov

@apedroferreira apedroferreira self-assigned this Oct 20, 2023
@apedroferreira apedroferreira changed the title Fix and improve resizing in editor (WIP) Fix and improve resizing in editor Nov 1, 2023
@apedroferreira apedroferreira marked this pull request as ready for review November 1, 2023 19:58
@apedroferreira apedroferreira marked this pull request as draft November 1, 2023 19:59
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 2, 2023
handleScreenUpdate();
}, []);

React.useEffect(() => {

This comment was marked as outdated.

@@ -816,6 +817,21 @@ export function moveNode<Parent extends AppDomNode, Child extends AppDomNode>(
return setNodeParent(dom, node, parent.id, parentProp, parentIndex);
}

export function spreadNode<Child extends AppDomNode>(dom: AppDom, node: Child) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If an action in the editor causes a column of elements to be inside the page root, for example, we can spread the contents of the column on the page root directly and get rid of the column element.

element: ElementType,
isPageChild = false,
): ElementType | ElementType[] {
if (isPageChild && element.component === PAGE_COLUMN_COMPONENT_ID) {
Copy link
Member Author

@apedroferreira apedroferreira Nov 2, 2023

Choose a reason for hiding this comment

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

Gets rid of page columns inside the page root too, I saw it in a few apps already and it's unnecessary / shouldn't ever happen.

@@ -205,7 +204,8 @@ export default createBuiltin(Chart, {
loadingProp: 'loading',
loadingPropSource: ['data'],
errorProp: 'error',
resizableHeightProp: 'height',
defaultLayoutHeight: 360,
Copy link
Member Author

Choose a reason for hiding this comment

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

New interface that should be simpler.
Any component is vertically resizable, but we can set a default and minimum height for specific components.

const hintPosition = rect.y > HUD_HEIGHT ? HINT_POSITION_TOP : HINT_POSITION_BOTTOM;
const { nodeId: pageNodeId, viewState } = usePageEditorState();

const { nodes: nodesInfo } = viewState;

This comment was marked as outdated.

@@ -1195,6 +1193,8 @@ function RenderedNodeContent({ node, childNodeGroups, Component }: RenderedNodeC
display: 'flex',
alignItems: boundLayoutProps.verticalAlign,
justifyContent: boundLayoutProps.horizontalAlign,
height: node.layout?.height ?? componentConfig.defaultLayoutHeight,
Copy link
Member Author

@apedroferreira apedroferreira Feb 21, 2024

Choose a reason for hiding this comment

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

Element heights are controlled in the boxes that wrap components instead of the components themselves.

@apedroferreira apedroferreira requested a review from a team February 22, 2024 17:50
@apedroferreira apedroferreira marked this pull request as ready for review February 22, 2024 17:50
@Janpot
Copy link
Member

Janpot commented Feb 23, 2024

@apedroferreira Can you also add a demo video that demonstrates the new features?

@apedroferreira
Copy link
Member Author

@apedroferreira Can you also add a demo video that demonstrates the new features?

I've added 3 demos to the description, hopefully it helps!

@Janpot
Copy link
Member

Janpot commented Feb 23, 2024

Looking good:

  • I see one suspicious regression test: https://app.argos-ci.com/mui/mui-toolpad/builds/2595/78472283. Is this expected?
  • I'm not a huge fan of exposing the Spacer component. Ideally we'd treat it as an internal component that gets created automatically when manipulating the UI. But I guess we can start like this and remove it down the line?
  • Do Spacer components collapse? e.g. if you have "component - spacer - component - spacer - component" and you delete the middle component, do you end up with "component - spacer - spacer - component" or with "component - spacer - component"?

@apedroferreira
Copy link
Member Author

Yeah, it's because the default height of the data grid changed, I probably changed it to be a multiple of the resizing intervals.

  • I'm not a huge fan of exposing the Spacer component. Ideally we'd treat it as an internal component that gets created automatically when manipulating the UI. But I guess we can start like this and remove it down the line?

Yeah I just didn't want to delete it right away from this PR but we had discussed not having it and it just being created automatically... As we're not sure about it I don't mind removing it and seeing what we come up with later if we come back to this, I guess it's better than introducing something we might not plan to keep. I'll remove it from the PR if you don't disagree.

  • Do Spacer components collapse? e.g. if you have "component - spacer - component - spacer - component" and you delete the middle component, do you end up with "component - spacer - spacer - component" or with "component - spacer - component"?

Nope, not in this version of them. Again I guess that I can remove it for now anyway.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 23, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 23, 2024
@Janpot
Copy link
Member

Janpot commented Feb 23, 2024

I'll remove it from the PR if you don't disagree.

I'm fine with keeping it

Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

impressive

@apedroferreira apedroferreira changed the title Fix and improve resizing in editor Fix and improve resizing in editor (incl. Add Spacer component) Feb 23, 2024
@apedroferreira apedroferreira merged commit 4870ed8 into mui:master Feb 23, 2024
12 checks passed
@apedroferreira apedroferreira deleted the resizing-fixes branch February 23, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work feature: App Editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants