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

[Security Solution][Detection Engine] EUI Tech Debt - Removes references to static EuiTheme variables #208820

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

rylnd
Copy link
Contributor

@rylnd rylnd commented Jan 29, 2025

Summary

This PR is a followup to #205990, which removed references to all of the deprecated/renamed EUI vars in preparation for 9.0. Here, we address some of the non-critical tech debt related to the EUI refresh, namely the removal of static EUI tokens from our codebase.

I made every attempt not to change any styles in this PR, except to simplify CSS to produce an equivalent design. A common example of this was removing a static margin or padding declaration referencing euiThemeVars.size*, and swapping it with an equivalent gutterSize prop on the EuiFlexGroup container, or with an align-self or other equivalent flexbox directive.

Screenshots of Areas Affected

The majority of changes here involved the Exception List/Item pages. I've attached screenshots of their current layout for comparison/review:

Rule Exceptions Tab

Before

Rule exceptions tab - before

After

Rule exceptions tab - after

Shared Exception Lists

Shared Exception Lists

Shared Exception List Details

Shared Exception List Details

Threshold Input

Threshold Input

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

rylnd added 21 commits January 23, 2025 16:15
The EUI page header has some parent <p> somewhere, and we were
incorrectly putting <div>s as children. This fixes that, along with a
few necessary style changes (and updated snapshots).
This replaces static references to euiThemeVars to enable this behavior.

I did away with some `margin` usage in favor of `EuiFlexGroup`'s
`gutterSize` prop, as well as removing some manual `display: flex`s in
favor of EuiFlexItem/Group.

This also appears to fix some errors in the snapshot test related to
this component. I'm not sure how those happened, but it appears specific
to that test and not a production behavior.
While removing static references to euiThemeVars, I found that these
manual styles weren't needed:

* `&div:first-child` selector wasn't being applied
* margins can be replaced with a different `gutterSize` prop
* the eui-yScrollWithShadow was adding a shadow to a container that
  wasn't actually scrollable; when the extra margin above was removed,
  this caused the shadow to cover part of the border of the Exception
  item panels
Because we need to _call_ a hook (`useEuiTheme`) in order to apply
styles here, this needs to either be a dedicated React component, or
itself a hook.

Since the consuming code (all the way down to the EUI component) expects
an array of Elements, we can't use a component (since it must return a
single component, even if it's a Fragment). So: the function is now a
hook!

We necessarily now removed the useMemo's wrapping the original function
calls, but that's okay because a) there's nothing expensive happening in
the hook and b) we can always add a `useMemo` to the hook itself, later.
This ports the styles over from static generation with euiThemeVars to
dynamic with useEuiTheme. I also simplified styles in a few ways, here:

1. Remove the JS conditions around applying styles, and porting to
   equivalent CSS
2. Removing unnecessary flex-basis CSS (which didn't work on the div it
   was being applied to)
3. Moving child `color` CSS to the parent, instead.
The previous tests were calling React-generating code outside of react,
and then in the test we were calling `render()` on the results.

We now instead make use of `renderHook`, give a slightly better name to
the test helper that wrapped our now-hook, and update snapshots as well.
We had negative-margin CSS to offset a 24px `gap` on our flex grouping.
By reducing the `gap` to 8px, we no longer need to offset it.
Instead of adding bottom padding to each element in a container (the
header of an individual exception list on its Shared Details page), we
instead make the container a `FlexGroup` and add an analogous
`gutterSize` prop (and `margin-bottom`) to it.
I forgot about the aforementioned weirdness in EUIPageHeader that
necessitates everything being a span.
We were wrapping a `span` in a `div`, and then giving that div:

1. display: inline
2. margin-left: 4px

Because the margin is so insignificant (there is already natural space
after the previous element), I opted to just remove the div and its
styles altogether.
The generated styles are equivalent.
…tCard

This component exists as the inner item on the Shared Exception Lists
page. Styles have been verified as equivalent.
* Defines a FieldSectionGroup component instead of applying the same
  styles to multiple identical EuiFieldGroup components
* Replaces use of margin-top with a more appropriate `align-self`
  declaration
@rylnd rylnd added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:Detection Engine Security Solution Detection Engine Area EUI Visual Refresh labels Jan 29, 2025
@rylnd rylnd self-assigned this Jan 29, 2025
@rylnd
Copy link
Contributor Author

rylnd commented Jan 29, 2025

/ci

@elasticmachine
Copy link
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!

@elasticmachine
Copy link
Contributor

elasticmachine commented Jan 29, 2025

💔 Build Failed

Failed CI Steps

History

cc @rylnd

rylnd added 2 commits January 29, 2025 13:45
These were already fixed on the package version of this component, but
the one that's still in the plugin was not updated, which I noticed
while taking screenshots.
@rylnd
Copy link
Contributor Author

rylnd commented Jan 29, 2025

Note to self: I think that 7b5441e was a mistake. That function should reference components that use the useEuiTheme() hook, as opposed to calling the hook directly.

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 EUI Visual Refresh release_note:skip Skip the PR/issue when compiling release notes Team:Detection Engine Security Solution Detection Engine Area
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants