diff --git a/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilterItem.tsx b/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilterItem.tsx index 8b24d9e452b..6fefc2dceea 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilterItem.tsx +++ b/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilterItem.tsx @@ -25,7 +25,7 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe }>({}); const isMultiSelect = () => { - return item.op === operators[0].label; + return operators.find((op) => op.label === item.op)?.isMultiValue; }; const getSelectOptionsFromString = (item?: string): string[] => { @@ -127,8 +127,8 @@ export function LabelFilterItem({ item, defaultOp, onChange, onDelete, onGetLabe } const operators = [ - { label: '=~', value: '=~' }, - { label: '=', value: '=' }, - { label: '!=', value: '!=' }, - { label: '!~', value: '!~' }, + { label: '=~', value: '=~', isMultiValue: true }, + { label: '=', value: '=', isMultiValue: false }, + { label: '!=', value: '!=', isMultiValue: false }, + { label: '!~', value: '!~', isMultiValue: true }, ]; diff --git a/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilters.test.tsx b/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilters.test.tsx index 62dc1a169e7..fb7d8154ee7 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilters.test.tsx +++ b/public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilters.test.tsx @@ -31,6 +31,21 @@ describe('LabelFilters', () => { 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 () => { const { onChange } = setup([{ label: 'foo', op: '=', value: 'bar' }]); await userEvent.click(getAddButton());