mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Fix typescript strict null errors from 674 -> 565 (#26057)
* Chore: Fix typescript strict null errors * Added new limit * Fixed ts issue * fixed tests * trying to fix type inference * Fixing more ts errors * Revert tsconfig option * Fix * Fixed code * More fixes * fix tests * Updated snapshot
This commit is contained in:
@@ -119,19 +119,20 @@ export function expandRecordingRules(query: string, mapping: { [name: string]: s
|
||||
// Regex that matches occurences of ){ or }{ or ]{ which is a sign of incorrecly added labels.
|
||||
const invalidLabelsRegex = /(\)\{|\}\{|\]\{)/;
|
||||
const correctlyExpandedQueryArray = queryArray.map(query => {
|
||||
let expression = query;
|
||||
if (expression.match(invalidLabelsRegex)) {
|
||||
expression = addLabelsToExpression(expression, invalidLabelsRegex);
|
||||
}
|
||||
return expression;
|
||||
return addLabelsToExpression(query, invalidLabelsRegex);
|
||||
});
|
||||
|
||||
return correctlyExpandedQueryArray.join('');
|
||||
}
|
||||
|
||||
function addLabelsToExpression(expr: string, invalidLabelsRegexp: RegExp) {
|
||||
const match = expr.match(invalidLabelsRegexp);
|
||||
if (!match) {
|
||||
return expr;
|
||||
}
|
||||
|
||||
// Split query into 2 parts - before the invalidLabelsRegex match and after.
|
||||
const indexOfRegexMatch = expr.match(invalidLabelsRegexp).index;
|
||||
const indexOfRegexMatch = match.index ?? 0;
|
||||
const exprBeforeRegexMatch = expr.substr(0, indexOfRegexMatch + 1);
|
||||
const exprAfterRegexMatch = expr.substr(indexOfRegexMatch + 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user