From 21afe3dc62c05c6c38af2fe266a96eae8d29bf19 Mon Sep 17 00:00:00 2001 From: Nick Richmond <5732000+NWRichmond@users.noreply.github.com> Date: Thu, 2 May 2024 16:06:40 -0400 Subject: [PATCH] Prometheus: Ensure values in metric selector are visible (#87150) * fix: ensure selectable values are visible * refactor: remove unnecessary ternaries, strengthen types * docs: fix typo * style: comply with `betterer` guidelines * refactor: add clarity * fix: remove border for consistency's sake --- .../querybuilder/components/MetricSelect.tsx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/grafana-prometheus/src/querybuilder/components/MetricSelect.tsx b/packages/grafana-prometheus/src/querybuilder/components/MetricSelect.tsx index 35a10f7064c..f739a487844 100644 --- a/packages/grafana-prometheus/src/querybuilder/components/MetricSelect.tsx +++ b/packages/grafana-prometheus/src/querybuilder/components/MetricSelect.tsx @@ -56,7 +56,7 @@ export function MetricSelect({ metricLookupDisabled, onBlur, variableEditor, -}: MetricSelectProps) { +}: Readonly) { const styles = useStyles2(getStyles); const [state, setState] = useState<{ metrics?: SelectableValue[]; @@ -241,10 +241,16 @@ export function MetricSelect({
- + {children} {optionsLoaded && ( @@ -263,7 +269,7 @@ export function MetricSelect({ return ( { if (metricLookupDisabled) { return; @@ -286,7 +293,7 @@ export function MetricSelect({ if (prometheusMetricEncyclopedia) { setState({ - // add the modal butoon option to the options + // add the modal button option to the options metrics: [...metricsModalOption, ...metrics], isLoading: undefined, // pass the initial metrics into the metrics explorer @@ -303,7 +310,7 @@ export function MetricSelect({ }} loadOptions={metricLookupDisabled ? metricLookupDisabledSearch : debouncedSearch} isLoading={state.isLoading} - defaultOptions={state.metrics} + defaultOptions={state.metrics ?? Array.from(new Array(25), () => ({ value: '' }))} // We need empty values when `state.metrics` is falsy in order for the select to correctly determine top/bottom placement onChange={(input) => { const value = input?.value; if (value) { @@ -321,7 +328,7 @@ export function MetricSelect({ components={ prometheusMetricEncyclopedia ? { Option: CustomOption, MenuList: CustomMenu } : { MenuList: CustomMenu } } - onBlur={onBlur ? onBlur : () => {}} + onBlur={onBlur} /> ); };