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

[Infra] Migrate infra from styled-components to @emotion #202405

Merged

Conversation

MiriamAparicio
Copy link
Contributor

@MiriamAparicio MiriamAparicio commented Dec 2, 2024

Closes #202255

Summary

While working on the visual refresh for the new EUI theme Borealis we figured that was a good time to do the recommended migration from styled-components to @emotion

What has been done

  • Migrate infra plugin from styled-components to @emotion
  • Eui Visual Refresh for Borealis new theme
  • All usage of color palette tokens and functions now pull from the theme, and correctly update to use new colors when the theme changes from Borealis to Amsterdam and vice versa
  • All references to renamed tokens have been updated to use the new token name
  • Remove usage of deprecated useEuiBackgroundColor
  • All usages of "success" colors have been updated to accentSecondary and textAccentSecondary as needed

How to test

Running Kibana with the Borealis theme

In order to run Kibana with Borealis, you'll need to do the following:

  • Set the following in kibana.dev.yml: uiSettings.experimental.themeSwitcherEnabled: true
  • Run Kibana with the following environment variable set: KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn start
  • This will expose a toggle under Stack Management > Advanced Settings > Theme version, which you can use to toggle between Amsterdam and Borealis.

@MiriamAparicio MiriamAparicio added v9.0.0 Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team EUI Visual Refresh labels Dec 2, 2024
@MiriamAparicio MiriamAparicio marked this pull request as ready for review December 3, 2024 12:24
@MiriamAparicio MiriamAparicio requested review from a team as code owners December 3, 2024 12:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Dec 3, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@@ -56,7 +57,7 @@ export const Threshold = ({
data-test-subj={`threshold-${thresholds.join('-')}-${value}`}
>
<Chart>
<Settings theme={theme} baseTheme={baseTheme} locale={i18n.getLocale()} />
<Settings theme={theme as PartialTheme} baseTheme={baseTheme} locale={i18n.getLocale()} />
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to use as PartialTheme here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The types coming from the emotion Theme and the type requested for Settings theme doesn't match, we need to cast it as PartialTheme to work, I'm open to suggestions on how to fix it in a different way

@@ -64,7 +64,7 @@ describe('Threshold', () => {

expect((Metric as jest.Mock).mock.calls[0][0].data[0][0]).toMatchInlineSnapshot(`
Object {
"color": "#f8e9e9",
"color": "#BD271E",
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this potentially be an issue for flakiness should there be any further changes to the design system or theming?

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 thought so, I will check if we can actually not pass the color for the test, or another option

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

I added some nits but haven't tested it yet ( I will add a separate comment if I find issues while testing but the code looks good 💯 )

Copy link
Contributor

@rmyz rmyz left a comment

Choose a reason for hiding this comment

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

LGTM

flex-direction: row;
`;

LogStatusbar.defaultProps = { alignItems: 'center', gutterSize: 'none', justifyContent: 'flexEnd' };
Copy link
Contributor

@tonyghiani tonyghiani Dec 3, 2024

Choose a reason for hiding this comment

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

nit: this is a deprecated React feature, prefer switching over a function react component if you need default props.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found this as a suggestion to replace the attrs on styled components but you're right it's a bit old, I'll see if I found something else

Copy link
Contributor

Choose a reason for hiding this comment

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

Hope this helps, it should make the trick for this case (coded only, check if everything works fine on Kibana please):

export const LogStatusbar = (props: EuiFlexGroupProps) => {
  const { euiTheme } = useEuiTheme();

  return (
    <EuiFlexGroup
      alignItems="center"
      gutterSize="none"
      justifyContent="flexEnd"
      css={css`
        padding: ${euiTheme.size.s};
        border-top: ${euiTheme.border.thin};
        max-height: 48px;
        min-height: 48px;
        background-color: ${euiTheme.colors.emptyShade};
        flex-direction: row;
      `}
      {...props}
    />
  );
};

Copy link
Contributor

@tonyghiani tonyghiani left a comment

Choose a reason for hiding this comment

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

@MiriamAparicio I left some notes but there are more similar across the PR, the color tokens used as shades (emptyShade, 'darkShade`, etc...) are all deprecated and should change with other colors from the palette, this internal guide might help you picking the right color.

Just seen your comment here, if the EUI team is ok keeping those around, I'm 👌

@MiriamAparicio
Copy link
Contributor Author

@tonyghiani the comment wasn't in slack but in another PR related with the visual refresh, #200814 (comment)

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

I saw some errors while testing (And added some questions about some background colors):

  • Undefined values:

    • [ Dark Mode | Amsterdam ] Host details view -> Logs tab ('euiColorEmptyShade'):
      image
    • [Dark Mode | Borealis] Container -> Metrics ('darkMode')

    image

  • Colors:

    • [Light Mode | Borealis] Host Details -> Processes tab -> Process charts: With the new background the chart lines are barely visible:
    image - Q: Is the background of the charts the correct color 🤔 ?

    image

Not sure if related to the PR (probably not):
image

background: ${(props) => props.theme.eui.euiColorGhost};
width: calc(100% + ${(props) => props.theme.eui.euiSizeL} * 2);
margin-left: -${(props) => props.theme.eui.euiSizeL};
background: ${(props) => props.theme.euiTheme.colors.ghost};
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Is it expected that this container always has a white background, also in dark mode?
If it should update the background based on colorMode (having a dark background in dark mode) then this should rather use backgroundBasePlain.

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, makes sense, it already looks dark in dark mode though
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 will change it as ghost is deprecated already

Copy link
Contributor

@mgadewoll mgadewoll Dec 5, 2024

Choose a reason for hiding this comment

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

it already looks dark in dark mode though

I had a look and it is white on dark mode but it's using an EuiPanel as content which actually updates colors.

If this background color for the sticky container is not needed, we could also remove it.

Screenshot 2024-12-05 at 12 59 29

@MiriamAparicio MiriamAparicio force-pushed the 202255-poc-migration-to-emotion branch from 23e74d1 to 672caf8 Compare December 5, 2024 11:12
Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

Tested again and it looks good now 💯

Copy link
Contributor

@mgadewoll mgadewoll left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! Awesome job migrating off styled components! 🎉
Changes LGTM from EUI side 👍

@MiriamAparicio MiriamAparicio force-pushed the 202255-poc-migration-to-emotion branch from c49a950 to 12d44a4 Compare December 5, 2024 17:03
@patpscal
Copy link

patpscal commented Dec 5, 2024

Hi @miriam

Using https://tkajtoch-pr-202405-202255-poc-migration-to-emotion.kbndev.co/

  • Inventory: Couldn't load any data
  • Infrastructure inventory: Couldn't load any data

But I was able to check

Metrics Explorer & Hosts:

Visualizations background won't work correctly, but I think updating them is not included in this iteration. Is that correct?
image

Hosts:

In the condition builder syntax, when creating an alert, the text (FOR, WHEN) should use textAccentSecondary (teal) instead of success (pure green)
Screenshot 2024-12-05 at 18 55 14

Also, pending confirmation from EUI from misusage on the tour component Context

@MiriamAparicio
Copy link
Contributor Author

@patpscal

Inventory: Couldn't load any data
Infrastructure inventory: Couldn't load any data

Yeah, I thought it will lack some data, there was a deployment made by @kuisathaverat but I think it's not available anymore

Visualizations background won't work correctly, but I think updating them is not included in this iteration. Is that correct?

Correct, that should be fixed by the Charts team

In the condition builder syntax, when creating an alert, the text (FOR, WHEN) should use textAccentSecondary (teal) instead of success (pure green)

I'll take a look

@MiriamAparicio MiriamAparicio requested a review from a team as a code owner December 9, 2024 11:14
@MiriamAparicio
Copy link
Contributor Author

@patpscal
Regarding this:

In the condition builder syntax, when creating an alert, the text (FOR, WHEN) should use textAccentSecondary (teal) instead of success (pure green)

The component from eui EuiExpression doesn't accept the new tokens, the color prop just accepts success or danger

Please @mgadewoll correct me if I'm wrong

@elasticmachine
Copy link
Contributor

⏳ Build in-progress

  • Buildkite Build
  • Commit: 2223eeb
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-202405-2223eeba53bd

History

Copy link
Contributor Author

@MiriamAparicio MiriamAparicio Dec 9, 2024

Choose a reason for hiding this comment

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

No idea why this file ended up in my PR after the merge, can you check if it's ok and approve? @elastic/search-kibana

import type { PartialTheme, Theme } from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import { COMPARATORS } from '@kbn/alerting-comparators';

export interface ChartProps {
theme?: PartialTheme;
theme?: UseEuiTheme<{}>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this work? {} is the default value of the generic parameter

Suggested change
theme?: UseEuiTheme<{}>;
theme?: UseEuiTheme;

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 think so, i'll fix it on the next PR

@MiriamAparicio MiriamAparicio merged commit 6bc8c27 into elastic:main Dec 10, 2024
8 checks passed
@MiriamAparicio MiriamAparicio deleted the 202255-poc-migration-to-emotion branch December 10, 2024 08:00
@patpscal
Copy link

Hi @MiriamAparicio, got it. I just learned the EUI team will review their definition here https://github.com/orgs/elastic/projects/1150/views/12?pane=issue&itemId=90262619
So no changes required on our end for now, thank you!

@gvnmagni
Copy link

Apologies for getting into the conversation late, but I saw that you were describing an issue with a chart color that used to be blue and now with Borealis appears light teal.

How to deal with these cases is explained in this document, within the Datavis section.

To make it simple, the issue is that the order of colors within the datavis palette is now changed and Blue is now in a different place than before. Therefore, you just need to use euiTheme.colors.vis.euiColorVis2 to point to the desired blue

I hope this could help clarifying the issue, please feel free to ping me in case of need!

@MiriamAparicio
Copy link
Contributor Author

Hi @gvnmagni
Thanks for pointing that out, I will have a look at the charts background in a follow-up PR

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 12, 2024
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 202405 locally

@crespocarlos crespocarlos changed the title [POC] Migrate infra from styled-components to @emotion [Infra] Migrate infra from styled-components to @emotion Dec 12, 2024
@MiriamAparicio MiriamAparicio added the backport:skip This commit does not require backporting label Dec 12, 2024
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 12, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
Closes elastic#202255

### Summary
While working on the visual refresh for the new EUI theme Borealis we
figured that was a good time to do the recommended migration from
styled-components to @emotion

### What has been done

- Migrate infra plugin from styled-components to @emotion
- Eui Visual Refresh for Borealis new theme
- All usage of color palette tokens and functions now pull from the
theme, and correctly update to use new colors when the theme changes
from Borealis to Amsterdam and vice versa
- All references to renamed tokens have been updated to use the new
token name
- Remove usage of deprecated `useEuiBackgroundColor`
- All usages of "success" colors have been updated to `accentSecondary`
and `textAccentSecondary` as needed


### How to test

#### Running Kibana with the Borealis theme
In order to run Kibana with Borealis, you'll need to do the following:

- Set the following in kibana.dev.yml:
`uiSettings.experimental.themeSwitcherEnabled: true`
- Run Kibana with the following environment variable set:
`KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn
start`
- This will expose a toggle under Stack Management > Advanced Settings >
Theme version, which you can use to toggle between Amsterdam and
Borealis.
MiriamAparicio added a commit that referenced this pull request Dec 13, 2024
)

## Summary

After migrating infra plugin from `styled-components` to `@emotion` in
this [PR](#202405), this file was
missed to update
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 backport:version Backport to applied version labels ci:project-deploy-observability Create an Observability project EUI Visual Refresh release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Infra] Migrate infra from styled-components to @emotion