mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Transformations: Relax regexp format in refIdMatcher (#97216)
This commit is contained in:
parent
acf67d5911
commit
88621d6fa0
@ -1,4 +1,4 @@
|
||||
import { stringStartsAsRegEx, stringToJsRegex } from '../../text/string';
|
||||
import { escapeStringForRegex, stringStartsAsRegEx, stringToJsRegex } from '../../text/string';
|
||||
import { DataFrame } from '../../types/dataFrame';
|
||||
import { FrameMatcherInfo } from '../../types/transformations';
|
||||
|
||||
@ -23,6 +23,12 @@ const refIdMatcher: FrameMatcherInfo<string> = {
|
||||
}
|
||||
}
|
||||
}
|
||||
// old format that was simply unescaped pipe-joined strings -> regexp
|
||||
else if (pattern.includes('|')) {
|
||||
// convert A|B -> /^(?:A|B)$/, regexp-escaping all chars between pipes
|
||||
const escapedUnion = pattern.split('|').map(escapeStringForRegex).join('|');
|
||||
regex = new RegExp(`^(?:${escapedUnion})$`);
|
||||
}
|
||||
|
||||
return (frame: DataFrame) => {
|
||||
return regex?.test(frame.refId || '') ?? frame.refId === pattern;
|
||||
|
@ -37,8 +37,22 @@ describe('filterByRefId transformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('respects', () => {
|
||||
it('inclusion', async () => {
|
||||
describe('respects inclusion', () => {
|
||||
it('pipe delimited literals', async () => {
|
||||
const cfg = {
|
||||
id: DataTransformerID.filterByRefId,
|
||||
options: {
|
||||
include: 'A|B',
|
||||
},
|
||||
};
|
||||
|
||||
await expect(transformDataFrame([cfg], allSeries)).toEmitValuesWith((received) => {
|
||||
const filtered = received[0];
|
||||
expect(filtered.map((f) => f.refId)).toEqual(['A', 'B']);
|
||||
});
|
||||
});
|
||||
|
||||
it('explicit regexp', async () => {
|
||||
const cfg = {
|
||||
id: DataTransformerID.filterByRefId,
|
||||
options: {
|
||||
|
Loading…
Reference in New Issue
Block a user