-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Expandable flyout width #170078
Expandable flyout width #170078
Conversation
fc30711
to
2401755
Compare
@elasticmachine merge upstream |
1274b74
to
edf7920
Compare
edf7920
to
307e325
Compare
Pinging @elastic/security-threat-hunting (Team:Threat Hunting) |
f8f999b
to
e64a8d1
Compare
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.
Thank you for making these changes! Overall works great!
Observing a strange behavior with preview when width is between 1600px and 1900px, the calculated preview width is smaller than the right panel
Screen.Recording.2023-11-15.at.3.39.07.PM.mov
expect(getByTestId(`${PREVIEW_SECTION_TEST_ID}BannerPanel`)).toHaveClass( | ||
`euiPanel--${banner.backgroundColor}` | ||
); | ||
// expect(getByTestId(`${PREVIEW_SECTION_TEST_ID}BannerText`)).toHaveProperty( |
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.
is this test duplicate of the next one?
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.
yeah forgot to remove that comment line, good catch thanks!
bottom: 0; | ||
right: 0; | ||
left: ${left}; | ||
top: 4px; |
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.
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.
: 0; | ||
|
||
// handle tiny screens by not going smaller than the window width | ||
if (rightSectionWidth > windowWidth) rightSectionWidth = windowWidth; |
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.
as an alternative of adding an extra if here, you can take the smaller of calculated width and window width on line 69
Math.min(windowWidth, RIGHT_SECTION_MIN_WIDTH)
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.
yup change made!
? windowWidth < MIN_RESOLUTION_BREAKPOINT | ||
? RIGHT_SECTION_MIN_WIDTH | ||
: RIGHT_SECTION_MIN_WIDTH + | ||
(RIGHT_SECTION_MAX_WIDTH - RIGHT_SECTION_MIN_WIDTH) * |
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.
nit: maybe extract this ratio calculation as a variable?
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.
@christineweng to solve this and the Math.min of your previous comment, this is the best I can come up with
let rightSectionWidth: number = 0;
if (showRight) {
if (windowWidth < MIN_RESOLUTION_BREAKPOINT) {
// the right section's width will grow from 380px (at 992px resolution) while handling tiny screens by not going smaller than the window width
rightSectionWidth = Math.min(RIGHT_SECTION_MIN_WIDTH, windowWidth);
} else {
const ratioWidth =
(RIGHT_SECTION_MAX_WIDTH - RIGHT_SECTION_MIN_WIDTH) *
((windowWidth - MIN_RESOLUTION_BREAKPOINT) /
(MAX_RESOLUTION_BREAKPOINT - MIN_RESOLUTION_BREAKPOINT));
// the right section's width will grow to 750px (at 1920px resolution) and will never go bigger than 750px in higher resolutions
rightSectionWidth = Math.max(RIGHT_SECTION_MIN_WIDTH + ratioWidth, RIGHT_SECTION_MAX_WIDTH);
}
}
Do you prefer this over the previous code?
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.
LGTM! good old if else saves the day :)
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.
yeah, I actually pushed a commit changing right, left and preview section variables to be consistent :)
: 0; | ||
|
||
// handle tiny screens by not going smaller than the window width | ||
if (rightSectionWidth > windowWidth) rightSectionWidth = windowWidth; |
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.
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.
good observation and I noticed this as well during testing. The code says it should take the whole width but the UI doesn't reflect that. I hadn't gone as far of trying to understand why, because I considered this a minor annoyance for a width that we don't fully support...
I think it's something we can keep in mind for future work, maybe. The bug existed before this refactor so I'm ok to not worry about this for now, if you are as well or course!
if (rightSectionWidth > windowWidth) rightSectionWidth = windowWidth; | ||
|
||
// never go bigger than 750px | ||
if (rightSectionWidth > RIGHT_SECTION_MAX_WIDTH) rightSectionWidth = RIGHT_SECTION_MAX_WIDTH; |
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.
same as above, this check can be replaced by Math.min(calculated width, RIGHT_SECTION_MAX_WIDTH)
on line 70
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.
yup change made!
showRight && showLeft ? `${rightSectionWidth + leftSectionWidth}px` : `${rightSectionWidth}px`; | ||
|
||
// preview section's width should only be similar to the right section | ||
const previewSectionLeft: number = |
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.
curious why previewSectionLeft
is different from leftSectionWidth
?
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.
good point, they're identical, I've updated the code accordingly
e64a8d1
to
1a54fe4
Compare
|
||
// preview section's width should only be similar to the right section. | ||
// Though because the preview is rendered with an absolute position in the flyout, we calculate its left position instead of the width | ||
let previewSectionLeft: number = 0; |
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.
@christineweng in theory, we could completely remove this variable and only rely on the leftSectionWdith
. We could then also remove the showPreview
prop.
I just feel like having this helps understanding. Are you ok with keeping it this way? To me it makes the code readable...
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.
hmm... we shouldn't be relying on leftSectionWidth
either because it could be zero, right? is it safe to assume if preview is open, then the right section is also open, the offset should be windowWidth - rightSectionWidth
?
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.
Yes I think we can assume that a preview section should always be displayed on top of a right section.
What I have now is
let previewSectionLeft: number = 0;
if (showPreview) {
// the preview section starts where the left section ends
previewSectionLeft = leftSectionWidth;
}
if showPreview
is false then we have 0.
If it's true then we purely rely on the leftSectionWidth
, which will be 0 of leftSection
is false, and a non-0 value if leftSection
is true.
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.
…s width for different screen resolutions
1a54fe4
to
e8572eb
Compare
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
Summary
This PR changes the way the
kbn-expandable-flyout
package handles multiple screen resolutions.Prior implementation was pretty basic and was following EUI's basic flyout sizes, using a small
size
when only the right section was rendered, and alarge
size when both right and left section were rendered (using a 60%-40% for the content).The new implementation is a lot smarter regarding handling screen resolution, while also answering customer's feedback that the right section's width is often too small to be usable.
Here are the biggest changes:
380px
to a maximum of750px
(unless the window size is smaller than380px
, in which case the flyout takes the size of the browser window)1600px
. For higher resolutions, the left section takes 80% of the window width, with a maximum set at1500px
The PR also makes a couple of more minor changes:
responsive={false}
in a lot ofEuiFlexGroup
within the flyout to avoid the UI to change on smaller screen (now that we have a minimum fixed width)Right section only
Screen.Recording.2023-11-08.at.3.46.55.PM.mov
Right and left section
Screen.Recording.2023-11-08.at.3.47.35.PM.mov
https://github.com/elastic/security-team/issues/7896