diff --git a/x-pack/plugins/aiops/common/api/stream_reducer.ts b/x-pack/plugins/aiops/common/api/stream_reducer.ts index 5e37df418c6ab..597527e80daef 100644 --- a/x-pack/plugins/aiops/common/api/stream_reducer.ts +++ b/x-pack/plugins/aiops/common/api/stream_reducer.ts @@ -37,7 +37,7 @@ export function streamReducer( case API_ACTION_NAME.ADD_CHANGE_POINTS_HISTOGRAM: const changePoints = state.changePoints.map((cp) => { const cpHistogram = action.payload.find( - (h) => h.fieldName === cp.fieldName && h.fieldValue && cp.fieldName + (h) => h.fieldName === cp.fieldName && h.fieldValue === cp.fieldValue ); if (cpHistogram) { cp.histogram = cpHistogram.histogram; diff --git a/x-pack/plugins/aiops/public/components/mini_histogram/mini_histogram.tsx b/x-pack/plugins/aiops/public/components/mini_histogram/mini_histogram.tsx index 8eaa9d7e7215e..2940983aaabbf 100644 --- a/x-pack/plugins/aiops/public/components/mini_histogram/mini_histogram.tsx +++ b/x-pack/plugins/aiops/public/components/mini_histogram/mini_histogram.tsx @@ -6,18 +6,32 @@ */ import React, { FC } from 'react'; +import { css } from '@emotion/react'; import { Chart, BarSeries, PartialTheme, ScaleType, Settings } from '@elastic/charts'; +import { EuiLoadingChart, EuiTextColor } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; import type { ChangePointHistogramItem } from '@kbn/ml-agg-utils'; +import { useAiOpsKibana } from '../../kibana_context'; +import { useEuiTheme } from '../../hooks/use_eui_theme'; + interface MiniHistogramProps { - chartData: ChangePointHistogramItem[]; + chartData?: ChangePointHistogramItem[]; + isLoading: boolean; label: string; } -export const MiniHistogram: FC = ({ chartData, label }) => { - const theme: PartialTheme = { +export const MiniHistogram: FC = ({ chartData, isLoading, label }) => { + const { + services: { charts }, + } = useAiOpsKibana(); + + const euiTheme = useEuiTheme(); + const defaultChartTheme = charts.theme.useChartsTheme(); + + const miniHistogramChartTheme: PartialTheme = { chartMargins: { left: 0, right: 0, @@ -33,18 +47,49 @@ export const MiniHistogram: FC = ({ chartData, label }) => { scales: { barsPadding: 0.1, }, + background: { + color: 'transparent', + }, }; + const cssChartSize = css({ + width: '80px', + height: euiTheme.euiSizeL, + margin: '0px', + }); + + const cssCenter = css({ + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }); + + if (isLoading) { + return ( +
+ +
+ ); + } + + if (!chartData) { + return ( +
+ + + +
+ ); + } + return ( -
+
- + = ({ onSelectedChangePoint, selectedChangePoint, }) => { + const euiTheme = useEuiTheme(); + const [pageIndex, setPageIndex] = useState(0); const [pageSize, setPageSize] = useState(10); const [sortField, setSortField] = useState(DEFAULT_SORT_FIELD); @@ -72,6 +78,7 @@ export const SpikeAnalysisTable: FC = ({ sortable: true, }, { + width: NARROW_COLUMN_WIDTH, field: 'pValue', name: ( = ({ ), - render: (_, { histogram, fieldName, fieldValue }) => { - return histogram ? ( - - ) : null; - }, + render: (_, { histogram, fieldName, fieldValue }) => ( + + ), sortable: false, }, { + width: NARROW_COLUMN_WIDTH, field: 'pValue', name: ( = ({ sortable: true, }, { + width: NARROW_COLUMN_WIDTH, field: 'pValue', name: ( = ({ selectedChangePoint.fieldValue === changePoint.fieldValue && selectedChangePoint.fieldName === changePoint.fieldName ? { - // TODO use euiTheme - // backgroundColor: euiTheme.eui.euiColorLightestShade, - backgroundColor: '#ddd', + backgroundColor: euiTheme.euiColorLightestShade, } : null, }; diff --git a/x-pack/plugins/aiops/public/hooks/use_eui_theme.ts b/x-pack/plugins/aiops/public/hooks/use_eui_theme.ts new file mode 100644 index 0000000000000..86ab38db9077a --- /dev/null +++ b/x-pack/plugins/aiops/public/hooks/use_eui_theme.ts @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useMemo } from 'react'; + +import { euiLightVars as euiThemeLight, euiDarkVars as euiThemeDark } from '@kbn/ui-theme'; + +import { useAiOpsKibana } from '../kibana_context'; + +export type EuiThemeType = typeof euiThemeLight | typeof euiThemeDark; + +export function useEuiTheme() { + const { + services: { uiSettings }, + } = useAiOpsKibana(); + + return useMemo( + () => (uiSettings.get('theme:darkMode') ? euiThemeDark : euiThemeLight), + [uiSettings] + ); +}