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

ui: Update ResizablePanelGroup internals #1355

Merged
merged 72 commits into from
Jun 21, 2024
Merged

Conversation

backspace
Copy link
Contributor

@backspace backspace commented Jun 14, 2024

This refactors ResizablePanelGroup and its Panel and Handle children. I originally planned to fix a bug where the panels don’t resize when one has been hidden but the fix needs more attention, so I’ll make a followup PR when it’s ready.

Bookkeeping via parallel PanelContext arrays is gone:

  • the group now has arrays of Panel and Handle
    • elements are stored on the components, there’s no longer indirection via specially-constructed ids (${ResizeHandleElIdPrefix}-${this.args.orientation}-${id})
    • the id seen there is instead derived from the component’s position in the array
  • ratio, length, and other properties are stored directly on Panel
  • this led to the removal of ember-ref-bucket

ResizeHandler is now Handle internally, ResizeHandle when exported.

@isHidden for a panel is now documented in Freestyle.

Tests now exercise horizontal orientation too. I thought of combining the horizontal and vertical tests as they’re identical other than using the appropriate dimensions but that seemed harder to understand. That means any new tests for the component would need to be added to two files, so if people think combining them is a good idea, I’m open to that.

@backspace backspace added the bug Something isn't working label Jun 14, 2024
@backspace backspace self-assigned this Jun 14, 2024
Copy link

github-actions bot commented Jun 14, 2024

Host Test Results

    1 files  ±0      1 suites  ±0   13m 37s ⏱️ -6s
630 tests ±0  628 ✔️ ±0  2 💤 ±0  0 ±0 
635 runs  ±0  633 ✔️ ±0  2 💤 ±0  0 ±0 

Results for commit 6dc6c9f. ± Comparison against base commit 0f4bd3c.

♻️ This comment has been updated with latest results.

test<MyTestContext>('it adjusts to its container growing (default)', async function (assert) {
this.renderController.containerStyle =
'max-width: 100%; height: 200px; width: 218px;';
await renderHorizontalResizablePanelGroup(this.renderController);
Copy link
Contributor

@tintinthong tintinthong Jun 20, 2024

Choose a reason for hiding this comment

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

assertion after this to show status quo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you expand on this? I wouldn’t normally repeat assertions when I consider a case covered.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait. Pff I thought the modifier changed the width of panel-0-content or something. My bad.

Yea doesn't seem to be a need to "repeat" this assertion. My point was if the width change from 200 to 240. Id want 200 to be asserted. Then 240 to be asserted.

this.renderController.panels[1].lengthPx = 200;
this.renderController.panels[0].innerContainerStyle =
'height: 180px; background: blue';
await renderHorizontalResizablePanelGroup(this.renderController);
Copy link
Contributor

Choose a reason for hiding this comment

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

assert for status quo

Copy link
Contributor

Choose a reason for hiding this comment

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

I think perhaps, this one makes sense to assert

Copy link
Contributor

@tintinthong tintinthong left a comment

Choose a reason for hiding this comment

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

I am a big fan of this PR -- just the renaming makes much of a diff. It reduces a lot of overhead when looking at the resizable panel code.

assert.hasNumericStyle('.panel-1-content', 'width', 67, 1);
});

test<MyTestContext>('it adjusts to its container shrinking and growing', async function (assert) {
Copy link
Contributor

@tintinthong tintinthong Jun 20, 2024

Choose a reason for hiding this comment

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

Actually, this test seems to want to test growing followed by shrinking.

I think its too generic and can be broken up.

  • I dont think we need a test to display shrinking followed by growing (wdyt)
  • double clicks should be separate test
  • isnt the growing and shrinking handled in test before? so, maybe some portions of this test is slightly redundant

@tintinthong tintinthong requested a review from a team June 20, 2024 03:43
});
}
}
calculateLengthsOfPanelsWithoutMinLength();
Copy link
Contributor

@tintinthong tintinthong Jun 20, 2024

Choose a reason for hiding this comment

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

I recall this is the main calculation code that consolidates length and ratio and the panels. Its relatively complicated. And I know thereis some issues with this code bcos ratios are normalised as in between of adding and removing new panels. This will essentially, lead to ratios being morphed. For example, when going from 3 panels to 2 panels by removing panels and adding

It goes like (only considering ratios)

  • 3 panels 0.2,0.4,0.4
  • 2 panels 0.33, 0..66 (unregistered a panel)
  • 1 panel 1 (unregistered a panel)
  • 2 panel 0.769, 0.23 (registered a panel)

You can see that the ratios morphed maybe not for the better

In the spirit to be aware of this, can we separate this into a block of code where ratio calculation exist. Then we can maybe add test there in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I see what you’re saying. I’ll include something like this in the followup that addresses the ratios. Does this mean that maybe the old ratios before hiding should be tracked and restored when unhidden? Seems like an explosion of complexity is possible 😳

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like an explosion of complexity if its all inside the component. Tho, im also skeptical that you can prevent the ratios from being morphed if you commit to the principle of recalculate them every time you register or unregister a new panel.

we probably have to decide on a heuristic for this to be stable. But, I think its just hard to think about at its current state. For hiding and persistence, I didn't think you need to change the ratios. I thought you'd just store some new state in the local storage?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code should belong together in some sort of abstraction. wdyt

  • calculateLengthsOfPanelsWithMinLength , calculateLengthsOfPanelsWithoutMinLength uses the intermediate ratios from registering to update the lengths onContainerResize
  • calculateRatios updates the intermediate ratios upon register, unregistering, moving the handles

tho im ok also not including these changes in this PR

@tintinthong tintinthong requested a review from a team June 20, 2024 13:40
@tintinthong
Copy link
Contributor

I recall messing about freestyle usage stuff and the the resizable panel doesn't work exactly as expected. Do u experience this?

@backspace
Copy link
Contributor Author

I recall messing about freestyle usage stuff and the the resizable panel doesn't work exactly as expected. Do u experience this?

Which part? The isHidden definitely doesn’t, that’s what I’ll address in the followup.

Thanks for the earlier feedback, I’ll address it today 😀

@backspace backspace merged commit 8baf10d into main Jun 21, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants