Prometheus: Variable query editor, display selected label when using query type of label values (#92513)

display label, add test
This commit is contained in:
Brendan O'Handley 2024-09-04 08:11:17 -05:00 committed by GitHub
parent cffaefddc3
commit 4bf350cc62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -265,6 +265,8 @@ describe('PromVariableQueryEditor', () => {
const labelSelect = screen.getByLabelText('label-select');
await userEvent.type(labelSelect, 'this');
await selectOptionInTest(labelSelect, 'this');
//display label in label select
await waitFor(() => expect(screen.getByText('this')).toBeInTheDocument());
await waitFor(() =>
expect(onChange).toHaveBeenCalledWith({

View File

@ -2,7 +2,7 @@
import debounce from 'debounce-promise';
import { FormEvent, useCallback, useEffect, useState } from 'react';
import { QueryEditorProps, SelectableValue } from '@grafana/data';
import { QueryEditorProps, SelectableValue, toOption } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { AsyncSelect, InlineField, InlineFieldRow, Input, Select, TextArea } from '@grafana/ui';
@ -286,7 +286,7 @@ export const PromVariableQueryEditor = ({ onChange, query, datasource, range }:
<AsyncSelect
aria-label="label-select"
onChange={onLabelChange}
value={label}
value={label ? toOption(label) : null}
defaultOptions={truncatedLabelOptions}
width={25}
allowCustomValue