-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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][Data Quality Dashboard]: migrate styled-component… #205559
[Security Solution][Data Quality Dashboard]: migrate styled-component… #205559
Conversation
c5df37c
to
b91c385
Compare
Pinging @elastic/security-threat-hunting-explore (Team:Threat Hunting:Explore) |
33c4085
to
4d0d6da
Compare
linkText: css({ | ||
display: 'flex', | ||
gap: euiTheme.size.xs, | ||
}), |
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.
using object notation is recommended for 2 reasons:
- emotion docs advise to use it for typescript https://emotion.sh/docs/typescript#emotionreact
- Free Autocomplete of keys and values.
export const linkTextCss = ({ euiTheme }: UseEuiTheme): CSSObject => ({ | ||
display: 'flex', | ||
gap: euiTheme.size.s, | ||
}); |
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.
Instead of defining shared useStyles
hooks unnecessarily, I decided to export small nuggets of shared css snippets like this. When passed directly into css={}
prop as a function emotion passes in the theme for free so no need for import, also no need to wrap the properties in css()
call.
@@ -113,7 +113,7 @@ describe('LegacyHistoricalCheckFields', () => { | |||
<TestExternalProviders> | |||
<EuiMarkdownFormat>{tablesMarkdown}</EuiMarkdownFormat> | |||
</TestExternalProviders> | |||
).container.innerHTML | |||
).container.children[0].innerHTML |
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.
for some reason the this container started producing an additional <span>
I didn't spend time debugging why but I checked that it works as expected visually
|
||
export interface Props { | ||
docsCount: number; | ||
ilmPhase?: string; | ||
sizeInBytes?: number; | ||
sameFamilyFieldsCount?: 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.
cleaning up leftovers from before
className="eui-yScroll" | ||
$width={LEGEND_WIDTH} | ||
> | ||
<div css={styles.legendContainer} data-test-subj="legend" className="eui-scrollBar"> |
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.
this className
change is intentional and is needed because eui-yScroll
is added on <style>
level and previously <LegendContainer>
styled-components styles were also added on style level and took precedence.
But now after replacing with emotion, emotion styles are now coming from compiled css bundle and are being overshadowed by eui-yScroll
class's block-size
property which completely breaks the height restriction of the container and renders the list unrestricted, so scroll is removed.
I found the eui-scrollBar
which is less opinionated and doesn't enforce block-size
but applies same basic styling for scrolling https://eui.elastic.co/#/utilities/scroll%23scroll-bar-style I just needed to add overflowY: auto
explicitly in this case to achieve parity with eui-yScroll
behavior.
@@ -25,7 +25,6 @@ module.exports = { | |||
/x-pack[\/\\]solutions[\/\\]observability[\/\\]plugins[\/\\]synthetics[\/\\]/, | |||
/x-pack[\/\\]solutions[\/\\]observability[\/\\]plugins[\/\\]uptime[\/\\]/, | |||
/x-pack[\/\\]solutions[\/\\]observability[\/\\]plugins[\/\\]ux[\/\\]/, | |||
/x-pack[\/\\]solutions[\/\\]security[\/\\]packages[\/\\]ecs_data_quality_dashboard[\/\\]/, |
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.
this line was the puzzle piece that helped me debug what happened before with my faulty setup last time I tried to convert to emotion and failed. Turns out we have to uncomment this line to allow proper emotion compilation on webpack side. Now everything works as expected.
80a70e3
to
b7d2a9d
Compare
</MockKibanaContextProvider> | ||
</I18nProvider> | ||
<MockKibanaContextProvider startServices={startServices}> | ||
<KibanaRenderContextProvider {...coreMock.createStart()}> |
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.
this turned out to cause issues with existing tests, so I moved this to data_quality.test only for now with latest commit
c4ebd35
to
90240b3
Compare
…s to Emotion Addresses elastic#205449 - Replaced styled-components with Emotion for styling components - Updated all styled-components imports to Emotion - Refactored styles using Emotion's `css` and `useEuiTheme` hooks - Ensured all components are using Emotion's `css` prop for styling - Updated tsconfig to include Emotion types and configuration - Removed ecs_data_quality_dashboard package from packages/kbn-babel-preset/styled_components_files.js so that emotion is properly compiled
The whole point of this change is to make babel-jest transform options shared and reusable by other packages' jest.config transforms that need to add their own custom stuff. For example here ecs_data_quality_dashboard makes use of that to add @emotion/babel-preset-css-prop that is needed to properly compile emotion css prop in jest tests.
- Add a new babel transformer for jest in the security solution plugin to enable overview/data_quality.test.tsx to pass without compilation warnings - Integrate `@emotion/babel-preset-css-prop` with custom label format - Update `test_providers.tsx` to include `KibanaRenderContextProvider` and `coreMock` - Modify jest configuration in `overview` to use the new babel transformer - Ensure compatibility with existing jest preset and module name mapping
- Removed KibanaRenderContextProvider from TestProvidersComponent due to issues in current overview tests - Updated test setup in data_quality.test.tsx to include KibanaRenderContextProvider instead
90240b3
to
5ab5bfe
Compare
/ci |
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]
History
cc @kapral18 |
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.
kbn-test
changes LGTM
<MockKibanaContextProvider startServices={startServices}> | ||
<I18nProvider> |
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.
How come these needed to be swapped?
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 question. Initially I checked the root of security_solution app and it was wrapped in KibanaContextProvider without anything above it. But now after double checking I see that I18nProvider is not even present anywhere, only in tests. But we can clean it up later wdyt?
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.
Sure, can be cleaned up later. You already have 2 approvals here :)
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.
✅ for security_solution
files!
Starting backport for target branches: 8.x |
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
…s to Emotion
Addresses #205449
This PR migrates
ecs_data_quality_dashboard
package fromstyled-components
toemotion
. In the process we also convert thekbn/ui-theme
json tokens toeuiTheme
counterparts.Additionally we decorate root
babel-jest
transform locally insecurity_solution/public/overview
andecs_data_quality_dashboard
package folder to include@emotion/babel-preset-css-prop
.The reason for local
babel-jest
transforms is that rootbabel-jest
transform doesn't include@emotion/babel-preset-css-prop
which is necessary for proper compilation of emotion css prop in tests. Without it there is a warningappearing in every test that tests a component that uses css prop with theme function passed into it. Other use cases seem to be compiling fine without this babel preset. But theme callback is a valid way of using emotion so we shouldn't avoid using it just because it's not added properly to the test compilation step. Hence I am adding it locally to
ecs_data_quality_dashboard
package andsecurity_solution/public/overview
.