mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: query builder, handle regex in parentheses for label filters value (#78238)
handle regex in parentheses for label filter value
This commit is contained in:
committed by
GitHub
parent
e5c2e123ef
commit
13d67be0a9
@@ -52,9 +52,17 @@ export function LabelFilterItem({
|
||||
|
||||
const getSelectOptionsFromString = (item?: string): string[] => {
|
||||
if (item) {
|
||||
const regExp = /\(([^)]+)\)/;
|
||||
const matches = item?.match(regExp);
|
||||
|
||||
if (matches && matches[0].indexOf('|') > 0) {
|
||||
return [item];
|
||||
}
|
||||
|
||||
if (item.indexOf('|') > 0) {
|
||||
return item.split('|');
|
||||
}
|
||||
|
||||
return [item];
|
||||
}
|
||||
return [];
|
||||
|
||||
@@ -90,6 +90,18 @@ describe('LabelFilters', () => {
|
||||
expect(getAddButton()).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does split regex in the middle of a label value when the value contains the char |', () => {
|
||||
setup({ labelsFilters: [{ label: 'foo', op: '=~', value: 'boop|par' }] });
|
||||
|
||||
expect(screen.getByText('boop')).toBeInTheDocument();
|
||||
expect(screen.getByText('par')).toBeInTheDocument();
|
||||
});
|
||||
it('does not split regex in between parentheses inside of a label value that contains the char |', () => {
|
||||
setup({ labelsFilters: [{ label: 'foo', op: '=~', value: '(b|p)ar' }] });
|
||||
|
||||
expect(screen.getByText('(b|p)ar')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows error when filter with empty strings and label filter is required', async () => {
|
||||
setup({ labelsFilters: [{ label: '', op: '=', value: '' }], labelFilterRequired: true });
|
||||
expect(screen.getByText(MISSING_LABEL_FILTER_ERROR_MESSAGE)).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user