export function getExpressions()

in scripts/dashboard-importer/src/dashboards/converter/expression.ts [24:59]


export function getExpressions(
  targets: Target[],
  panelTitle: string,
  templateVariables = new Map<string, string>(),
): Result<Expression[]> {
  const expressions: Expression[] = [];
  const warnings = [];
  let index = 0;
  for (const target of targets) {
    if (target.expr === undefined) {
      warnings.push(
        `panel ${panelTitle} target at index ${index} does not have an expression`,
      );
      continue;
    }
    const interpolationAttempt = interpolateExpression(
      target.expr,
      templateVariables,
    );
    warnings.push(
      ...interpolationAttempt.warnings.map(
        (warning: string) => `panel ${panelTitle}: ${warning}`,
      ),
    );
    const expr = interpolationAttempt.result;
    if (expr) {
      const legend = replaceDoubleBraces(target.legendFormat || '');
      expressions.push({
        expression: convertMatchToRegexMatch(expr),
        legend: legend
      });
    }
    index++;
  }
  return success(expressions, warnings);
}