From da2962418df27d02ea784cc44b1c37a60fd186ce Mon Sep 17 00:00:00 2001 From: Brendan O'Handley Date: Fri, 12 Jul 2024 08:57:00 -0500 Subject: [PATCH] Explore metrics: Use state for variables to fix labels loading bug (#90017) * use variable state for loading labels * UI fix for missing metadata fields * remove extra space * add for betterer * import Trans from core, this will need to be addressed when we externalize explore metrics * make i18n-extract for drone --- .betterer.results | 9 ---- .../trails/ActionTabs/MetricOverviewScene.tsx | 47 ++++++++++++++----- public/locales/en-US/grafana.json | 6 +++ public/locales/pseudo-LOCALE/grafana.json | 6 +++ 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.betterer.results b/.betterer.results index f009e948ed7..29a7fcff218 100644 --- a/.betterer.results +++ b/.betterer.results @@ -5468,15 +5468,6 @@ exports[`better eslint`] = { "public/app/features/trails/ActionTabs/BreakdownScene.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] ], - "public/app/features/trails/ActionTabs/MetricOverviewScene.tsx:5381": [ - [0, 0, 0, "No untranslated strings. Wrap text with ", "0"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "1"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "2"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "3"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "4"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "5"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "6"] - ], "public/app/features/trails/ActionTabs/utils.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], diff --git a/public/app/features/trails/ActionTabs/MetricOverviewScene.tsx b/public/app/features/trails/ActionTabs/MetricOverviewScene.tsx index 7d6906d21cb..4948504c077 100644 --- a/public/app/features/trails/ActionTabs/MetricOverviewScene.tsx +++ b/public/app/features/trails/ActionTabs/MetricOverviewScene.tsx @@ -8,16 +8,14 @@ import { VariableDependencyConfig, } from '@grafana/scenes'; import { Stack, Text, TextLink } from '@grafana/ui'; +import { Trans } from 'app/core/internationalization'; -import { ALL_VARIABLE_VALUE } from '../../variables/constants'; import { MetricScene } from '../MetricScene'; import { StatusWrapper } from '../StatusWrapper'; import { reportExploreMetrics } from '../interactions'; import { VAR_DATASOURCE_EXPR, VAR_GROUP_BY } from '../shared'; import { getMetricSceneFor, getTrailFor } from '../utils'; -import { getLabelOptions } from './utils'; - export interface MetricOverviewSceneState extends SceneObjectState { metadata?: PromMetricsMetadataItem; metadataLoading?: boolean; @@ -67,29 +65,54 @@ export class MetricOverviewScene extends SceneObjectBase) => { const { metadata, metadataLoading } = model.useState(); const variable = model.getVariable(); - const { loading: labelsLoading } = variable.useState(); - const labelOptions = getLabelOptions(model, variable).filter((l) => l.value !== ALL_VARIABLE_VALUE); + const { loading: labelsLoading, options: labelOptions } = variable.useState(); return ( <> - Description + + Description +
- {metadata?.help ?
{metadata?.help}
: No description available} + {metadata?.help ? ( +
{metadata?.help}
+ ) : ( + + No description available + + )}
- Type - {metadata?.type ?
{metadata?.type}
: Unknown} + + Type + + {metadata?.type ? ( +
{metadata?.type}
+ ) : ( + + Unknown + + )}
- Unit - {metadata?.unit ?
{metadata?.unit}
: Unknown} + + Unit + + {metadata?.unit ? ( +
{metadata?.unit}
+ ) : ( + + Unknown + + )}
- Labels + + Labels + {labelOptions.length === 0 && 'Unable to fetch labels.'} {labelOptions.map((l) => (