mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Transformation: Add variable support for filter by value regex matcher (#90926)
* add support for template vars in filter by value transformation for regex matcher * less code is more code * add test to confirm interpolation works for regex * suggestions input for regex editor --------- Co-authored-by: Adela Almasan <adela.almasan@grafana.com>
This commit is contained in:
@@ -305,6 +305,51 @@ describe('FilterByValue transformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should interpolate dashboard variables for regex matcher', async () => {
|
||||
mockTransformationsVariableSupport.mockReturnValue(true);
|
||||
|
||||
const regex: MatcherConfig<BasicValueMatcherOptions<string | number>> = {
|
||||
id: ValueMatcherID.regex,
|
||||
options: { value: '.*thiswillinterpolateto6' },
|
||||
};
|
||||
|
||||
const cfg: DataTransformerConfig<FilterByValueTransformerOptions> = {
|
||||
id: DataTransformerID.filterByValue,
|
||||
options: {
|
||||
type: FilterByValueType.include,
|
||||
match: FilterByValueMatch.all,
|
||||
filters: [
|
||||
{
|
||||
fieldName: 'numbers',
|
||||
config: regex,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const ctxmock = { interpolate: jest.fn(() => '6') };
|
||||
|
||||
await expect(transformDataFrame([cfg], [seriesAWithSingleField], ctxmock)).toEmitValuesWith((received) => {
|
||||
const processed = received[0];
|
||||
|
||||
expect(processed.length).toEqual(1);
|
||||
expect(processed[0].fields).toEqual([
|
||||
{
|
||||
name: 'time',
|
||||
type: FieldType.time,
|
||||
values: [6000],
|
||||
state: {},
|
||||
},
|
||||
{
|
||||
name: 'numbers',
|
||||
type: FieldType.number,
|
||||
values: [6],
|
||||
state: {},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not interpolate dashboard variables when feature toggle is off', async () => {
|
||||
mockTransformationsVariableSupport.mockReturnValue(false);
|
||||
|
||||
|
||||
@@ -77,9 +77,6 @@ export const filterByValueTransformer: DataTransformerInfo<FilterByValueTransfor
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (filter.config.id === ValueMatcherID.regex) {
|
||||
// Due to colliding syntaxes, interpolating regex filters will cause issues.
|
||||
return filter;
|
||||
} else if (filter.config.options.value) {
|
||||
let value = filter.config.options.value;
|
||||
if (typeof filter.config.options.value === 'string') {
|
||||
|
||||
Reference in New Issue
Block a user