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

[ILM] Remove euiThemeVars and remapping colors for Borealis #204449

Merged
merged 10 commits into from
Jan 8, 2025

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,14 @@
align-items: center;
border-radius: 50%;
background-color: $euiColorLightestShade;

&--disabled {
width: $euiSize;
height: $euiSize;
margin: $euiSizeS;
}

&--delete {
background-color: $euiColorLightShade;
}
&__inner--hot {
fill: $euiColorVis9_behindText;
}
&__inner--warm {
fill: $euiColorVis5_behindText;
}
&__inner--cold {
fill: $euiColorVis1_behindText;
}
&__inner--frozen {
fill: $euiColorVis4_behindText;
}
&__inner--delete {
fill: $euiColorDarkShade;
}

&__inner--disabled {
fill: $euiColorMediumShade;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,38 @@
* 2.0.
*/

import React, { FunctionComponent } from 'react';
import { EuiIcon } from '@elastic/eui';
import { FunctionComponent } from 'react';
import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';
import { EuiIcon, useEuiTheme } from '@elastic/eui';
import { Phases } from '../../../../../../common/types';
import './phase_icon.scss';
interface Props {
enabled: boolean;
phase: string & keyof Phases;
}
export const PhaseIcon: FunctionComponent<Props> = ({ enabled, phase }) => {
const { euiTheme } = useEuiTheme();

const isBorealis = euiTheme.themeName === 'EUI_THEME_BOREALIS';

const phaseIconColors = {
hot: isBorealis ? euiTheme.colors.vis.euiColorVis6 : euiThemeVars.euiColorVis9_behindText,
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ We're introducing the behindText vis colors to the euiTheme (PR). This will land in Kibana with this weeks release.
As we want to remove the JSON token usages from client (react) code, it would be great if you could either update if the release is faster than this PR or do a follow-up to update 🙏

warm: isBorealis ? euiTheme.colors.vis.euiColorVis9 : euiThemeVars.euiColorVis5_behindText,
cold: isBorealis ? euiTheme.colors.vis.euiColorVis2 : euiThemeVars.euiColorVis1_behindText,
frozen: euiTheme.colors.vis.euiColorVis4,
delete: euiTheme.colors.darkShade,
};

return (
<div
className={`ilmPhaseIcon ilmPhaseIcon--${phase} ${enabled ? '' : 'ilmPhaseIcon--disabled'}`}
>
{enabled ? (
<EuiIcon
className={`ilmPhaseIcon__inner--${phase}`}
css={css`
fill: ${phaseIconColors[phase]};
`}
type={phase === 'delete' ? 'trash' : 'checkInCircleFilled'}
size={phase === 'delete' ? 'm' : 'l'}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,17 @@ $ilmTimelineBarHeight: $euiSizeS;

&__hotPhase {
width: var(--ilm-timeline-hot-phase-width);

&__colorBar {
background-color: $euiColorVis9;
}
}

&__warmPhase {
width: var(--ilm-timeline-warm-phase-width);

&__colorBar {
background-color: $euiColorVis5;
}
}

&__coldPhase {
width: var(--ilm-timeline-cold-phase-width);

&__colorBar {
background-color: $euiColorVis1;
}
}

&__frozenPhase {
width: var(--ilm-timeline-frozen-phase-width);

&__colorBar {
background-color: $euiColorVis4;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
* 2.0.
*/

/** @jsx jsx */
// Needed for for testing out the css prop feature. See: https://emotion.sh/docs/css-prop#jsx-pragma
Copy link
Contributor Author

@SoniaSanzV SoniaSanzV Jan 8, 2025

Choose a reason for hiding this comment

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

After adding emotion css, the affected snapshots displayed messages like this one:

<div
    -      class="ilmTimeline__colorBar ilmTimeline__frozenPhase__colorBar"
    +     class="ilmTimeline__colorBar"
    +     css="You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."
                            />

This was only happening in test, not in the final html. Following emotion docs and adding ** @jsx jsx * at the top of the file, fixed it

Copy link
Contributor

Choose a reason for hiding this comment

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

If you have to set the JSX pragma this could indicate that you might be missing a required Emotion babel preset for using the css prop for your plugin? 🤔 (emotion docs)

import { css, jsx } from '@emotion/react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import React, { FunctionComponent, memo } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiText, EuiIconTip } from '@elastic/eui';
import {
EuiFlexGroup,
EuiFlexItem,
EuiTitle,
EuiText,
EuiIconTip,
useEuiTheme,
} from '@elastic/eui';

import { useKibana } from '../../../../../shared_imports';

Expand Down Expand Up @@ -135,6 +145,17 @@ export const Timeline: FunctionComponent<Props> = memo(
: undefined,
};

const { euiTheme } = useEuiTheme();

const isBorealis = euiTheme.themeName === 'EUI_THEME_BOREALIS';

const timelineIconColors = {
hot: isBorealis ? euiTheme.colors.vis.euiColorVis6 : euiTheme.colors.vis.euiColorVis9,
warm: isBorealis ? euiTheme.colors.vis.euiColorVis9 : euiTheme.colors.vis.euiColorVis5,
cold: isBorealis ? euiTheme.colors.vis.euiColorVis2 : euiTheme.colors.vis.euiColorVis1,
frozen: euiTheme.colors.vis.euiColorVis4,
};

const phaseAgeInMilliseconds = calculateRelativeFromAbsoluteMilliseconds(absoluteTimings);

const widths = calculateWidths(phaseAgeInMilliseconds);
Expand Down Expand Up @@ -188,7 +209,12 @@ export const Timeline: FunctionComponent<Props> = memo(
data-test-subj="ilmTimelinePhase-hot"
className="ilmTimeline__phasesContainer__phase ilmTimeline__hotPhase"
>
<div className="ilmTimeline__colorBar ilmTimeline__hotPhase__colorBar" />
<div
className={`ilmTimeline__colorBar `}
css={css`
background-color: ${timelineIconColors.hot};
`}
/>
<TimelinePhaseText
phaseName={i18nTexts.hotPhase}
durationInPhase={getDurationInPhaseContent('hot')}
Expand All @@ -199,7 +225,12 @@ export const Timeline: FunctionComponent<Props> = memo(
data-test-subj="ilmTimelinePhase-warm"
className="ilmTimeline__phasesContainer__phase ilmTimeline__warmPhase"
>
<div className="ilmTimeline__colorBar ilmTimeline__warmPhase__colorBar" />
<div
className={`ilmTimeline__colorBar`}
css={css`
background-color: ${timelineIconColors.warm};
`}
/>
<TimelinePhaseText
phaseName={i18nTexts.warmPhase}
durationInPhase={getDurationInPhaseContent('warm')}
Expand All @@ -211,7 +242,12 @@ export const Timeline: FunctionComponent<Props> = memo(
data-test-subj="ilmTimelinePhase-cold"
className="ilmTimeline__phasesContainer__phase ilmTimeline__coldPhase"
>
<div className="ilmTimeline__colorBar ilmTimeline__coldPhase__colorBar" />
<div
className={`ilmTimeline__colorBar`}
css={css`
background-color: ${timelineIconColors.cold};
`}
/>
<TimelinePhaseText
phaseName={i18nTexts.coldPhase}
durationInPhase={getDurationInPhaseContent('cold')}
Expand All @@ -223,7 +259,12 @@ export const Timeline: FunctionComponent<Props> = memo(
data-test-subj="ilmTimelinePhase-frozen"
className="ilmTimeline__phasesContainer__phase ilmTimeline__frozenPhase"
>
<div className="ilmTimeline__colorBar ilmTimeline__frozenPhase__colorBar" />
<div
className="ilmTimeline__colorBar"
css={css`
background-color: ${timelineIconColors.frozen};
`}
/>
<TimelinePhaseText
phaseName={i18nTexts.frozenPhase}
durationInPhase={getDurationInPhaseContent('frozen')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

import React from 'react';
import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';
import { useEuiTheme } from '@elastic/eui';
import type { Phase } from '../../../../../common/types';

const phaseToIndicatorColors = {
hot: euiThemeVars.euiColorVis9,
warm: euiThemeVars.euiColorVis5,
cold: euiThemeVars.euiColorVis1,
frozen: euiThemeVars.euiColorVis4,
delete: euiThemeVars.euiColorLightShade,
};
export const PhaseIndicator = ({ phase }: { phase: Phase }) => {
const { euiTheme } = useEuiTheme();

const isBorealis = euiTheme.themeName === 'EUI_THEME_BOREALIS';

// Changing the mappings for the phases in Borealis as a mid-term solution. See https://github.com/elastic/kibana/issues/203664#issuecomment-2536593361.
const phaseToIndicatorColors = {
hot: isBorealis ? euiTheme.colors.vis.euiColorVis6 : euiTheme.colors.vis.euiColorVis9,
warm: isBorealis ? euiTheme.colors.vis.euiColorVis9 : euiTheme.colors.vis.euiColorVis5,
cold: isBorealis ? euiTheme.colors.vis.euiColorVis2 : euiTheme.colors.vis.euiColorVis1,
frozen: euiTheme.colors.vis.euiColorVis4,
delete: euiTheme.colors.lightShade,
};

return (
<div
css={css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,14 @@ import {
EuiBadgeProps,
EuiBadge,
EuiCode,
useEuiTheme,
} from '@elastic/eui';
import { euiThemeVars } from '@kbn/ui-theme';

import { ApplicationStart } from '@kbn/core/public';
import { Index, IndexDetailsTab } from '@kbn/index-management-shared-types';
import { IlmExplainLifecycleLifecycleExplainManaged } from '@elastic/elasticsearch/lib/api/types';
import { Phase } from '../../../common/types';
import { getPolicyEditPath } from '../../application/services/navigation';

const phaseToBadgeMapping: Record<Phase, { color: EuiBadgeProps['color']; label: string }> = {
hot: {
color: euiThemeVars.euiColorVis9,
label: 'Hot',
},
warm: {
color: euiThemeVars.euiColorVis5,
label: 'Warm',
},
cold: {
color: euiThemeVars.euiColorVis1,
label: 'Cold',
},
frozen: {
color: euiThemeVars.euiColorVis4,
label: 'Frozen',
},
delete: {
color: 'default',
label: 'Delete',
},
};

interface Props {
index: Index;
getUrlForApp: ApplicationStart['getUrlForApp'];
Expand All @@ -64,6 +40,34 @@ export const IndexLifecycleSummary: FunctionComponent<Props> = ({ index, getUrlF
// only ILM managed indices render the ILM tab
const ilm = ilmData as IlmExplainLifecycleLifecycleExplainManaged;

const { euiTheme } = useEuiTheme();

const isBorealis = euiTheme.themeName === 'EUI_THEME_BOREALIS';

// Changing the mappings for the phases in Borealis as a mid-term solution. See https://github.com/elastic/kibana/issues/203664#issuecomment-2536593361.
const phaseToBadgeMapping: Record<Phase, { color: EuiBadgeProps['color']; label: string }> = {
hot: {
color: isBorealis ? euiTheme.colors.vis.euiColorVis6 : euiTheme.colors.vis.euiColorVis9,
label: 'Hot',
},
warm: {
color: isBorealis ? euiTheme.colors.vis.euiColorVis9 : euiTheme.colors.vis.euiColorVis5,
label: 'Warm',
},
cold: {
color: isBorealis ? euiTheme.colors.vis.euiColorVis2 : euiTheme.colors.vis.euiColorVis1,
label: 'Cold',
},
frozen: {
color: euiTheme.colors.vis.euiColorVis4,
label: 'Frozen',
},
delete: {
color: 'default',
label: 'Delete',
},
};

// if ilm.phase is an unexpected value, then display a default badge
const phaseBadgeConfig = phaseToBadgeMapping[ilm.phase as Phase] ?? {
color: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"@kbn/core-http-browser",
"@kbn/config-schema",
"@kbn/shared-ux-router",
"@kbn/ui-theme",
"@kbn/shared-ux-link-redirect-app",
"@kbn/index-management-shared-types",
"@kbn/react-kibana-context-render",
"@kbn/unsaved-changes-prompt",
"@kbn/shared-ux-table-persist",
"@kbn/index-lifecycle-management-common-shared",
"@kbn/ui-theme",
],
"exclude": [
"target/**/*",
Expand Down