mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
Prometheus: Fix UI bug where a label with empty string shows as populated with the deleted label filter value (#78153)
* preserve label with empty string * fix side effect of having undefined show up in the editor select for value * re render label item when label filters change
This commit is contained in:
+6
-4
@@ -73,8 +73,10 @@ export function LabelFilterItem({
|
||||
debounceDuration
|
||||
);
|
||||
|
||||
const itemValue = item?.value ?? '';
|
||||
|
||||
return (
|
||||
<div data-testid="prometheus-dimensions-filter-item">
|
||||
<div key={itemValue} data-testid="prometheus-dimensions-filter-item">
|
||||
<InputGroup>
|
||||
{/* Label name select, loads all values at once */}
|
||||
<Select
|
||||
@@ -136,8 +138,8 @@ export function LabelFilterItem({
|
||||
width="auto"
|
||||
value={
|
||||
isMultiSelect()
|
||||
? getSelectOptionsFromString(item?.value).map(toOption)
|
||||
: getSelectOptionsFromString(item?.value).map(toOption)[0]
|
||||
? getSelectOptionsFromString(itemValue).map(toOption)
|
||||
: getSelectOptionsFromString(itemValue).map(toOption)[0]
|
||||
}
|
||||
allowCustomValue
|
||||
onOpenMenu={async () => {
|
||||
@@ -179,7 +181,7 @@ export function LabelFilterItem({
|
||||
}}
|
||||
invalid={invalidValue}
|
||||
/>
|
||||
<AccessoryButton aria-label="remove" icon="times" variant="secondary" onClick={onDelete} />
|
||||
<AccessoryButton aria-label={`remove-${item.label}`} icon="times" variant="secondary" onClick={onDelete} />
|
||||
</InputGroup>
|
||||
</div>
|
||||
);
|
||||
|
||||
+17
-1
@@ -66,10 +66,26 @@ describe('LabelFilters', () => {
|
||||
|
||||
it('removes label', async () => {
|
||||
const { onChange } = setup({ labelsFilters: [{ label: 'foo', op: '=', value: 'bar' }] });
|
||||
await userEvent.click(screen.getByLabelText(/remove/));
|
||||
await userEvent.click(screen.getByLabelText(/remove-foo/));
|
||||
expect(onChange).toBeCalledWith([]);
|
||||
});
|
||||
|
||||
it('removes label but preserves a label with a value of empty string', async () => {
|
||||
const { onChange } = setup({
|
||||
labelsFilters: [
|
||||
{ label: 'lab', op: '=', value: 'bel' },
|
||||
{ label: 'foo', op: '=', value: 'bar' },
|
||||
{ label: 'le', op: '=', value: '' },
|
||||
],
|
||||
});
|
||||
await userEvent.click(screen.getByLabelText(/remove-foo/));
|
||||
expect(onChange).toBeCalledWith([
|
||||
{ label: 'lab', op: '=', value: 'bel' },
|
||||
{ label: 'le', op: '=', value: '' },
|
||||
]);
|
||||
expect(screen.queryByText('bar')).toBeNull();
|
||||
});
|
||||
|
||||
it('renders empty input when labels are deleted from outside ', async () => {
|
||||
const { rerender } = setup({ labelsFilters: [{ label: 'foo', op: '=', value: 'bar' }] });
|
||||
expect(screen.getByText(/foo/)).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user