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} /> ); };