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

Expandable flyout width #170078

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

PhilippeOberti
Copy link
Contributor

@PhilippeOberti PhilippeOberti commented Oct 27, 2023

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 a large 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:

  • the right section's width will grow from a minimum of 380px to a maximum of 750px (unless the window size is smaller than 380px, in which case the flyout takes the size of the browser window)
  • the left section will take the remaining on the window width on resolutions lower than 1600px. For higher resolutions, the left section takes 80% of the window width, with a maximum set at 1500px

The PR also makes a couple of more minor changes:

  • adding responsive={false} in a lot of EuiFlexGroup within the flyout to avoid the UI to change on smaller screen (now that we have a minimum fixed width)
  • added unit tests to test the preview section

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

@PhilippeOberti PhilippeOberti added release_note:enhancement Team:Threat Hunting Security Solution Threat Hunting Team Team:Threat Hunting:Investigations Security Solution Investigations Team ci:cloud-deploy Create or update a Cloud deployment v8.12.0 labels Oct 30, 2023
@PhilippeOberti
Copy link
Contributor Author

@elasticmachine merge upstream

@PhilippeOberti PhilippeOberti force-pushed the expandable-flyout-width branch 4 times, most recently from 1274b74 to edf7920 Compare November 8, 2023 17:43
@PhilippeOberti PhilippeOberti removed the ci:cloud-deploy Create or update a Cloud deployment label Nov 8, 2023
@PhilippeOberti PhilippeOberti marked this pull request as ready for review November 8, 2023 22:14
@PhilippeOberti PhilippeOberti requested a review from a team as a code owner November 8, 2023 22:14
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@PhilippeOberti PhilippeOberti force-pushed the expandable-flyout-width branch 3 times, most recently from f8f999b to e64a8d1 Compare November 14, 2023 22:31
Copy link
Contributor

@christineweng christineweng left a 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(
Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

the preview is now slightly smaller than the right panel, you can see the edges of right panel - is this an intended design choice?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this change on purpose, to get closer to the mocks
Screenshot 2023-11-15 at 4 17 14 PM

: 0;

// handle tiny screens by not going smaller than the window width
if (rightSectionWidth > windowWidth) rightSectionWidth = windowWidth;
Copy link
Contributor

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)

Copy link
Contributor Author

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) *
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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 :)

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know small screen is not the main focus here, flagging it as observation: according to this line, if the windowWith is smaller than 380px, the right panel should take up the entire screen, during testing, I'm seeing a gap on the left which appears to be a SecurityPageWrapper

image

Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor Author

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 =
Copy link
Contributor

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?

Copy link
Contributor Author

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


// 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;
Copy link
Contributor Author

@PhilippeOberti PhilippeOberti Nov 15, 2023

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...

Copy link
Contributor

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?

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 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.

Copy link
Contributor

@christineweng christineweng left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making the changes!

Small ui nit: the right section of the header in insights are missing responsive={false}
here and here
image

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 4694 4696 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 12.8MB 12.8MB +3.3KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@PhilippeOberti PhilippeOberti merged commit c3ac89c into elastic:main Nov 16, 2023
26 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Nov 16, 2023
@PhilippeOberti PhilippeOberti deleted the expandable-flyout-width branch November 16, 2023 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:enhancement Team:Threat Hunting:Investigations Security Solution Investigations Team Team:Threat Hunting Security Solution Threat Hunting Team v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants