Skip to content

Commit 5fba6eb

Browse files
walterraJoseLuisGJ
authored andcommitted
[ML] EUI Visual Refresh (tokens) (elastic#203518)
## Summary Part of elastic#199715 (EUI Visual Refresh). Recommend to review with white-space diff disabled: https://github.com/elastic/kibana/pull/203518/files?w=1 - All references to renamed tokens have been updated to use the new token name. - 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. - Migrated some data visualizer related SCSS to emotion, part of elastic#140695. - It makes use of EUI's own `useEuiTheme()` instead of our own hook variants. So this gets rid of `useCurrentEuiThemeVars()`, `useFieldStatsFlyoutThemeVars()`, `useCurrentEuiTheme()`, `useCurrentThemeVars()`. - Renamed components used to edit Anomaly Detection jobs from `JobDetails`, `Detectors`, `Datafeed` to `EditJobDetailsTab`, `EditDetectorsTab`, `EditDatafeedTab` to make them less ambiguous. - Added unit tests for `ner_output.tsx`. - Adds checks to pick `euiColorVis*` colors suitable for the theme. ---- Some of our code used colors like `euiColorVis5_behindText`. In Borealis `*_behindText` is no longer available since the original colors like `euiColorVis5` have been updated to be suitable to be used behind text. For that reason and for simplicity's sake I removed the border from the custom badges we use to render NER items: NER labels Amsterdam: ![CleanShot 2024-12-18 at 11 37 45@2x](https://github.com/user-attachments/assets/d82bca3a-2ad1-411a-94cd-748de6b4b0e9) NER labels Borealis: ![CleanShot 2024-12-18 at 11 38 45@2x](https://github.com/user-attachments/assets/36987779-fab2-4ad7-8e31-6853d48079a1) ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
1 parent 0a04896 commit 5fba6eb

File tree

126 files changed

+1574
-1222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1574
-1222
lines changed

x-pack/platform/packages/private/ml/aiops_components/src/document_count_chart/document_count_chart.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
getSnappedTimestamps,
2929
getSnappedWindowParameters,
3030
getWindowParametersForTrigger,
31+
useLogRateAnalysisBarColors,
3132
type DocumentCountStatsChangePoint,
3233
type LogRateHistogramItem,
3334
type WindowParameters,
@@ -198,6 +199,7 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
198199
const { data, uiSettings, fieldFormats, charts } = dependencies;
199200

200201
const chartBaseTheme = charts.theme.useChartsBaseTheme();
202+
const barColors = useLogRateAnalysisBarColors();
201203

202204
const xAxisFormatter = fieldFormats.deserialize({ id: 'date' });
203205
const useLegacyTimeAxis = uiSettings.get('visualization:useLegacyTimeAxis', false);
@@ -422,8 +424,10 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
422424
const baselineBadgeMarginLeft =
423425
(mlBrushMarginLeft ?? 0) + (windowParametersAsPixels?.baselineMin ?? 0);
424426

425-
const barColor = barColorOverride ? [barColorOverride] : undefined;
426-
const barHighlightColor = barHighlightColorOverride ? [barHighlightColorOverride] : ['orange'];
427+
const barColor = barColorOverride ? [barColorOverride] : barColors.barColor;
428+
const barHighlightColor = barHighlightColorOverride
429+
? [barHighlightColorOverride]
430+
: [barColors.barHighlightColor];
427431

428432
return (
429433
<>

x-pack/platform/packages/private/ml/data_grid/hooks/use_column_chart.test.tsx

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { render, renderHook } from '@testing-library/react';
1010

1111
import { KBN_FIELD_TYPES } from '@kbn/field-types';
1212

13+
import type { EuiThemeComputed } from '@elastic/eui';
14+
1315
import type {
1416
NumericChartData,
1517
OrdinalChartData,
@@ -23,6 +25,10 @@ import {
2325

2426
import { getFieldType, getLegendText, getXScaleType, useColumnChart } from './use_column_chart';
2527

28+
const euiThemeMock = {
29+
size: { base: '16px' },
30+
} as EuiThemeComputed;
31+
2632
describe('getFieldType()', () => {
2733
it('should return the Kibana field type for a given EUI data grid schema', () => {
2834
expect(getFieldType('text')).toBe('string');
@@ -103,63 +109,81 @@ describe('isUnsupportedChartData()', () => {
103109

104110
describe('getLegendText()', () => {
105111
it('should return the chart legend text for unsupported chart types', () => {
106-
expect(getLegendText(validUnsupportedChartData)).toBe('Chart not supported.');
112+
expect(getLegendText(validUnsupportedChartData, euiThemeMock)).toBe('Chart not supported.');
107113
});
108114
it('should return the chart legend text for empty datasets', () => {
109-
expect(getLegendText(validNumericChartData)).toBe('0 documents contain field.');
115+
expect(getLegendText(validNumericChartData, euiThemeMock)).toBe('0 documents contain field.');
110116
});
111117
it('should return the chart legend text for boolean chart types', () => {
112118
const { getByText } = render(
113119
<>
114-
{getLegendText({
115-
cardinality: 2,
116-
data: [
117-
{ key: 'true', key_as_string: 'true', doc_count: 10 },
118-
{ key: 'false', key_as_string: 'false', doc_count: 20 },
119-
],
120-
id: 'the-id',
121-
type: 'boolean',
122-
})}
120+
{getLegendText(
121+
{
122+
cardinality: 2,
123+
data: [
124+
{ key: 'true', key_as_string: 'true', doc_count: 10 },
125+
{ key: 'false', key_as_string: 'false', doc_count: 20 },
126+
],
127+
id: 'the-id',
128+
type: 'boolean',
129+
},
130+
euiThemeMock
131+
)}
123132
</>
124133
);
125134
expect(getByText('true')).toBeInTheDocument();
126135
expect(getByText('false')).toBeInTheDocument();
127136
});
128137
it('should return the chart legend text for ordinal chart data with less than max categories', () => {
129-
expect(getLegendText({ ...validOrdinalChartData, data: [{ key: 'cat', doc_count: 10 }] })).toBe(
130-
'10 categories'
131-
);
138+
expect(
139+
getLegendText(
140+
{ ...validOrdinalChartData, data: [{ key: 'cat', doc_count: 10 }] },
141+
euiThemeMock
142+
)
143+
).toBe('10 categories');
132144
});
133145
it('should return the chart legend text for ordinal chart data with more than max categories', () => {
134146
expect(
135-
getLegendText({
136-
...validOrdinalChartData,
137-
cardinality: 30,
138-
data: [{ key: 'cat', doc_count: 10 }],
139-
})
147+
getLegendText(
148+
{
149+
...validOrdinalChartData,
150+
cardinality: 30,
151+
data: [{ key: 'cat', doc_count: 10 }],
152+
},
153+
euiThemeMock
154+
)
140155
).toBe('top 20 of 30 categories');
141156
});
142157
it('should return the chart legend text for numeric datasets', () => {
143158
expect(
144-
getLegendText({
145-
...validNumericChartData,
146-
data: [{ key: 1, doc_count: 10 }],
147-
stats: [1, 100],
148-
})
159+
getLegendText(
160+
{
161+
...validNumericChartData,
162+
data: [{ key: 1, doc_count: 10 }],
163+
stats: [1, 100],
164+
},
165+
euiThemeMock
166+
)
149167
).toBe('1 - 100');
150168
expect(
151-
getLegendText({
152-
...validNumericChartData,
153-
data: [{ key: 1, doc_count: 10 }],
154-
stats: [100, 100],
155-
})
169+
getLegendText(
170+
{
171+
...validNumericChartData,
172+
data: [{ key: 1, doc_count: 10 }],
173+
stats: [100, 100],
174+
},
175+
euiThemeMock
176+
)
156177
).toBe('100');
157178
expect(
158-
getLegendText({
159-
...validNumericChartData,
160-
data: [{ key: 1, doc_count: 10 }],
161-
stats: [1.2345, 6.3456],
162-
})
179+
getLegendText(
180+
{
181+
...validNumericChartData,
182+
data: [{ key: 1, doc_count: 10 }],
183+
stats: [1.2345, 6.3456],
184+
},
185+
euiThemeMock
186+
)
163187
).toBe('1.23 - 6.35');
164188
});
165189
});

x-pack/platform/packages/private/ml/data_grid/hooks/use_column_chart.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import { css } from '@emotion/react';
1212

1313
import useObservable from 'react-use/lib/useObservable';
1414

15-
import { euiPaletteColorBlind, type EuiDataGridColumn } from '@elastic/eui';
15+
import {
16+
useEuiTheme,
17+
euiPaletteColorBlind,
18+
type EuiDataGridColumn,
19+
type EuiThemeComputed,
20+
} from '@elastic/eui';
1621

17-
import { euiThemeVars } from '@kbn/ui-theme';
1822
import { i18n } from '@kbn/i18n';
1923
import { KBN_FIELD_TYPES } from '@kbn/field-types';
2024

@@ -29,14 +33,6 @@ import { isNumericChartData, isOrdinalChartData } from '../lib/field_histograms'
2933
import { NON_AGGREGATABLE } from '../lib/common';
3034
import type { DataGridItem } from '../lib/types';
3135

32-
const cssHistogramLegendBoolean = css({
33-
width: '100%',
34-
// This was originally $euiButtonMinWidth, but that
35-
// is no longer exported from the EUI package,
36-
// so we're replicating it here inline.
37-
minWidth: `calc(${euiThemeVars.euiSize} * 7)`,
38-
});
39-
4036
const cssTextAlignCenter = css({
4137
textAlign: 'center',
4238
});
@@ -97,6 +93,7 @@ export const getFieldType = (schema: EuiDataGridColumn['schema']): KBN_FIELD_TYP
9793
type LegendText = string | JSX.Element;
9894
export const getLegendText = (
9995
chartData: ChartData,
96+
euiTheme: EuiThemeComputed,
10097
maxChartColumns = MAX_CHART_COLUMNS
10198
): LegendText => {
10299
if (chartData.type === 'unsupported') {
@@ -112,6 +109,14 @@ export const getLegendText = (
112109
}
113110

114111
if (chartData.type === 'boolean') {
112+
const cssHistogramLegendBoolean = css({
113+
width: '100%',
114+
// This was originally $euiButtonMinWidth, but that
115+
// is no longer exported from the EUI package,
116+
// so we're replicating it here inline.
117+
minWidth: `calc(${euiTheme.size.base} * 7)`,
118+
});
119+
115120
return (
116121
<table css={cssHistogramLegendBoolean}>
117122
<tbody>
@@ -171,6 +176,8 @@ export const useColumnChart = (
171176
columnType: EuiDataGridColumn,
172177
maxChartColumns?: number
173178
): ColumnChart => {
179+
const { euiTheme } = useEuiTheme();
180+
174181
const fieldType = getFieldType(columnType.schema);
175182

176183
const hoveredRow = useObservable(hoveredRow$);
@@ -231,7 +238,7 @@ export const useColumnChart = (
231238

232239
return {
233240
data,
234-
legendText: getLegendText(chartData, maxChartColumns),
241+
legendText: getLegendText(chartData, euiTheme, maxChartColumns),
235242
xScaleType,
236243
};
237244
};

x-pack/platform/packages/private/ml/data_grid/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"@kbn/ml-agg-utils",
2929
"@kbn/ml-error-utils",
3030
"@kbn/ml-data-frame-analytics-utils",
31-
"@kbn/ui-theme",
3231
"@kbn/i18n-react",
3332
"@kbn/ml-is-populated-object",
3433
"@kbn/ml-date-picker",

x-pack/platform/packages/private/ml/field_stats_flyout/field_stats_flyout_provider.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import type { PropsWithChildren, FC } from 'react';
99
import React, { useCallback, useState } from 'react';
10-
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
1110
import type { DataView } from '@kbn/data-plugin/common';
1211
import type { FieldStatsServices } from '@kbn/unified-field-list/src/components/field_stats';
1312
import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker';
@@ -36,7 +35,6 @@ import { PopulatedFieldsCacheManager } from './populated_fields/populated_fields
3635
export type FieldStatsFlyoutProviderProps = PropsWithChildren<{
3736
dataView: DataView;
3837
fieldStatsServices: FieldStatsServices;
39-
theme: ThemeServiceStart;
4038
timeRangeMs?: TimeRangeMs;
4139
dslQuery?: FieldStatsProps['dslQuery'];
4240
disablePopulatedFields?: boolean;
@@ -65,7 +63,6 @@ export const FieldStatsFlyoutProvider: FC<FieldStatsFlyoutProviderProps> = (prop
6563
const {
6664
dataView,
6765
fieldStatsServices,
68-
theme,
6966
timeRangeMs,
7067
dslQuery,
7168
disablePopulatedFields = false,
@@ -174,7 +171,6 @@ export const FieldStatsFlyoutProvider: FC<FieldStatsFlyoutProviderProps> = (prop
174171
fieldValue,
175172
timeRangeMs,
176173
populatedFields,
177-
theme,
178174
}}
179175
>
180176
<FieldStatsFlyout

x-pack/platform/packages/private/ml/field_stats_flyout/field_stats_info_button.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
* 2.0.
66
*/
77

8-
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiToolTip, EuiText } from '@elastic/eui';
8+
import {
9+
useEuiTheme,
10+
EuiButtonIcon,
11+
EuiFlexGroup,
12+
EuiFlexItem,
13+
EuiToolTip,
14+
EuiText,
15+
} from '@elastic/eui';
916
import { i18n } from '@kbn/i18n';
1017
import React, { type FC } from 'react';
1118
import { FieldIcon } from '@kbn/react-field';
1219
import { type Field } from '@kbn/ml-anomaly-utils';
13-
import { useCurrentEuiThemeVars } from '@kbn/ml-kibana-theme';
14-
import { useFieldStatsFlyoutThemeVars } from './use_field_stats_flyout_context';
1520

1621
import { getKbnFieldIconType } from './get_kbn_field_icon_types';
1722

@@ -71,8 +76,7 @@ export interface FieldStatsInfoButtonProps {
7176
*/
7277
export const FieldStatsInfoButton: FC<FieldStatsInfoButtonProps> = (props) => {
7378
const { field, label, onButtonClick, disabled, isEmpty, hideTrigger } = props;
74-
const theme = useFieldStatsFlyoutThemeVars();
75-
const themeVars = useCurrentEuiThemeVars(theme);
79+
const { euiTheme } = useEuiTheme();
7680

7781
const emptyFieldMessage = isEmpty
7882
? ' ' +
@@ -100,7 +104,7 @@ export const FieldStatsInfoButton: FC<FieldStatsInfoButtonProps> = (props) => {
100104
disabled={disabled === true}
101105
size="xs"
102106
iconType="fieldStatistics"
103-
css={{ color: isEmpty ? themeVars.euiTheme.euiColorDisabled : undefined }}
107+
css={{ color: isEmpty ? euiTheme.colors.textDisabled : undefined }}
104108
onClick={(ev: React.MouseEvent<HTMLButtonElement>) => {
105109
if (ev.type === 'click') {
106110
ev.currentTarget.focus();
@@ -127,12 +131,12 @@ export const FieldStatsInfoButton: FC<FieldStatsInfoButtonProps> = (props) => {
127131
<EuiFlexItem
128132
grow={false}
129133
css={{
130-
paddingRight: themeVars.euiTheme.euiSizeXS,
134+
paddingRight: euiTheme.size.xs,
131135
}}
132136
>
133137
{!hideTrigger ? (
134138
<FieldIcon
135-
color={isEmpty ? themeVars.euiTheme.euiColorDisabled : undefined}
139+
color={isEmpty ? euiTheme.colors.textDisabled : undefined}
136140
type={getKbnFieldIconType(field.type)}
137141
fill="none"
138142
/>

x-pack/platform/packages/private/ml/field_stats_flyout/options_list_with_stats/option_list_popover_footer.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
*/
77
import React from 'react';
88
import type { FC } from 'react';
9-
import { EuiPopoverFooter, EuiSwitch, EuiProgress, useEuiBackgroundColor } from '@elastic/eui';
9+
import { EuiPopoverFooter, EuiSwitch, EuiProgress, useEuiTheme } from '@elastic/eui';
1010
import { css } from '@emotion/react';
1111
import { i18n } from '@kbn/i18n';
12-
import { euiThemeVars } from '@kbn/ui-theme';
1312

1413
export const OptionsListPopoverFooter: FC<{
1514
showEmptyFields: boolean;
1615
setShowEmptyFields: (showEmptyFields: boolean) => void;
1716
isLoading?: boolean;
1817
}> = ({ showEmptyFields, setShowEmptyFields, isLoading }) => {
18+
const { euiTheme } = useEuiTheme();
19+
1920
return (
2021
<EuiPopoverFooter
2122
paddingSize="none"
2223
css={css({
23-
height: euiThemeVars.euiButtonHeight,
24-
backgroundColor: useEuiBackgroundColor('subdued'),
24+
height: euiTheme.size.xxl,
25+
backgroundColor: euiTheme.colors.backgroundBaseSubdued,
2526
alignItems: 'center',
2627
display: 'flex',
27-
paddingLeft: euiThemeVars.euiSizeS,
28+
paddingLeft: euiTheme.size.s,
2829
})}
2930
>
3031
{isLoading ? (

x-pack/platform/packages/private/ml/field_stats_flyout/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
"@kbn/i18n",
2424
"@kbn/react-field",
2525
"@kbn/ml-anomaly-utils",
26-
"@kbn/ml-kibana-theme",
2726
"@kbn/ml-data-grid",
2827
"@kbn/ml-string-hash",
2928
"@kbn/ml-is-populated-object",
3029
"@kbn/ml-query-utils",
3130
"@kbn/ml-is-defined",
3231
"@kbn/field-types",
33-
"@kbn/ui-theme",
34-
"@kbn/core-theme-browser",
3532
]
3633
}

0 commit comments

Comments
 (0)