mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix adding of multiple values for regex operator (#52978)
* Prometheus, Loki: Fix adding of multiple values for regex operator * Refactor
This commit is contained in:
parent
87004cc22d
commit
1eb3513781
@ -25,7 +25,7 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
|
|||||||
}>({});
|
}>({});
|
||||||
|
|
||||||
const isMultiSelect = () => {
|
const isMultiSelect = () => {
|
||||||
return item.op === operators[0].label;
|
return operators.find((op) => op.label === item.op)?.isMultiValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSelectOptionsFromString = (item?: string): string[] => {
|
const getSelectOptionsFromString = (item?: string): string[] => {
|
||||||
@ -127,8 +127,8 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe
|
|||||||
}
|
}
|
||||||
|
|
||||||
const operators = [
|
const operators = [
|
||||||
{ label: '=~', value: '=~' },
|
{ label: '=~', value: '=~', isMultiValue: true },
|
||||||
{ label: '=', value: '=' },
|
{ label: '=', value: '=', isMultiValue: false },
|
||||||
{ label: '!=', value: '!=' },
|
{ label: '!=', value: '!=', isMultiValue: false },
|
||||||
{ label: '!~', value: '!~' },
|
{ label: '!~', value: '!~', isMultiValue: true },
|
||||||
];
|
];
|
||||||
|
@ -31,6 +31,21 @@ describe('LabelFilters', () => {
|
|||||||
expect(getAddButton()).toBeInTheDocument();
|
expect(getAddButton()).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders multiple values for regex selectors', async () => {
|
||||||
|
setup([
|
||||||
|
{ label: 'bar', op: '!~', value: 'baz|bat|bau' },
|
||||||
|
{ label: 'foo', op: '!~', value: 'fop|for|fos' },
|
||||||
|
]);
|
||||||
|
expect(screen.getByText(/bar/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/baz/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/bat/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/bau/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/foo/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/for/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/fos/)).toBeInTheDocument();
|
||||||
|
expect(getAddButton()).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it('adds new label', async () => {
|
it('adds new label', async () => {
|
||||||
const { onChange } = setup([{ label: 'foo', op: '=', value: 'bar' }]);
|
const { onChange } = setup([{ label: 'foo', op: '=', value: 'bar' }]);
|
||||||
await userEvent.click(getAddButton());
|
await userEvent.click(getAddButton());
|
||||||
|
Loading…
Reference in New Issue
Block a user