diff --git a/public/app/features/trails/banners/NativeHistogramBanner.tsx b/public/app/features/trails/banners/NativeHistogramBanner.tsx index fc466119b46..1d65676c6f3 100644 --- a/public/app/features/trails/banners/NativeHistogramBanner.tsx +++ b/public/app/features/trails/banners/NativeHistogramBanner.tsx @@ -1,18 +1,18 @@ import { css } from '@emotion/css'; -import { useState } from 'react'; +import { useState, type Dispatch, type SetStateAction } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; -import { useStyles2, useTheme, Alert, Button } from '@grafana/ui'; +import { useStyles2, useTheme2, Alert, Button } from '@grafana/ui'; import { Trans } from '@grafana/ui/src/utils/i18n'; import { DataTrail } from '../DataTrail'; import { MetricSelectedEvent } from '../shared'; -type NativeHistogramInfoProps = { +interface NativeHistogramInfoProps { histogramsLoaded: boolean; nativeHistograms: string[]; trail: DataTrail; -}; +} export function NativeHistogramBanner(props: NativeHistogramInfoProps) { const { histogramsLoaded, nativeHistograms, trail } = props; @@ -20,29 +20,13 @@ export function NativeHistogramBanner(props: NativeHistogramInfoProps) { const [showHistogramExamples, setShowHistogramExamples] = useState(false); const styles = useStyles2(getStyles, 0); - const isDark = useTheme().isDark; - const images = { - nativeHeatmap: isDark - ? 'public/img/native-histograms/DarkModeHeatmapNativeHistogram.png' - : 'public/img/native-histograms/LightModeHeatmapNativeHistogram.png', - classicHeatmap: isDark - ? 'public/img/native-histograms/DarkModeHeatmapClassicHistogram.png' - : 'public/img/native-histograms/LightModeHeatmapClassicHistogram.png', - nativeHistogram: isDark - ? 'public/img/native-histograms/DarkModeHistogramNativehistogram.png' - : 'public/img/native-histograms/LightModeHistogramClassicHistogram.png', - classicHistogram: isDark - ? 'public/img/native-histograms/DarkModeHistogramClassicHistogram.png' - : 'public/img/native-histograms/LightModeHistogramClassicHistogram.png', - }; - - const selectNativeHistogram = (metric: string) => { - trail.publishEvent(new MetricSelectedEvent(metric), true); - }; + if (!histogramsLoaded || nativeHistograms.length === 0 || !histogramMessage) { + return null; + } return ( <> - {histogramsLoaded && (nativeHistograms ?? []).length > 0 && histogramMessage && ( + { - {!showHistogramExamples && ( -
- -
- )} + {showHistogramExamples && ( - <> -
-
-
- Now: -
-
-
-
- Previously: -
-
+ + )} + + } + + ); +} + +interface NativeHistogramExamplesButtonProps { + showHistogramExamples: boolean; + setShowHistogramExamples: Dispatch>; +} + +const NativeHistogramExamplesButton = ({ + showHistogramExamples, + setShowHistogramExamples, +}: NativeHistogramExamplesButtonProps) => { + const styles = useStyles2(getStyles, 0); + + return ( +
+ +
+ ); +}; + +type NativeHistogramExamplesProps = Pick & { + setHistogramMessage: Dispatch>; +}; + +const NativeHistogramExamples = ({ trail, nativeHistograms, setHistogramMessage }: NativeHistogramExamplesProps) => { + const styles = useStyles2(getStyles, 0); + const isDark = useTheme2().isDark; + const selectNativeHistogram = (metric: string) => { + trail.publishEvent(new MetricSelectedEvent(metric), true); + }; + const images = { + nativeHeatmap: isDark + ? 'public/img/native-histograms/DarkModeHeatmapNativeHistogram.png' + : 'public/img/native-histograms/LightModeHeatmapNativeHistogram.png', + classicHeatmap: isDark + ? 'public/img/native-histograms/DarkModeHeatmapClassicHistogram.png' + : 'public/img/native-histograms/LightModeHeatmapClassicHistogram.png', + nativeHistogram: isDark + ? 'public/img/native-histograms/DarkModeHistogramNativehistogram.png' + : 'public/img/native-histograms/LightModeHistogramClassicHistogram.png', + classicHistogram: isDark + ? 'public/img/native-histograms/DarkModeHistogramClassicHistogram.png' + : 'public/img/native-histograms/LightModeHistogramClassicHistogram.png', + }; + + return ( + <> +
+
+
+ Now: +
+
+
+
+ Previously: +
+
+
+
+
+
+
+
+ + Native Histogram displayed as heatmap: + +
+
+ Native Histogram displayed as heatmap +
+
+
+
+ + Native Histogram displayed as histogram: + +
+
+ Native Histogram displayed as histogram
-
-
-
-
-
- - Native Histogram displayed as heatmap: - -
-
- Native Histogram displayed as heatmap -
-
-
-
- - Native Histogram displayed as histogram: - -
-
- Native Histogram displayed as histogram -
-
-
-
-
-
-
-
- - Classic Histogram displayed as heatmap: - -
-
- Classic Histogram displayed as heatmap -
-
-
-
- - Classic Histogram displayed as histogram: - -
-
- Classic Histogram displayed as histogram -
-
-
-
+
+
+
+
+
+
+
+ + Classic Histogram displayed as heatmap: +
-
- - Click any of the native histograms below to explore them: + Classic Histogram displayed as heatmap +
+
+
+
+ + Classic Histogram displayed as histogram:
- {nativeHistograms.map((el) => { - return ( -
- -
- ); - })} + Classic Histogram displayed as histogram
- - )} - - )} +
+
+
+
+
+
+ + Click any of the native histograms below to explore them: + +
+
+ {nativeHistograms.map((el) => { + return ( +
+ +
+ ); + })} +
); -} +}; -function getStyles(theme: GrafanaTheme2, chromeHeaderHeight: number) { +function getStyles(theme: GrafanaTheme2, _chromeHeaderHeight: number) { return { histogramRow: css({ display: 'flex',