export function generateWarningSummary()

in scripts/dashboard-importer/src/common/report.ts [79:102]


export function generateWarningSummary(warnings: string[], numPanels: number): string {
  let hasCollapsibleGroupWarning = false;
  let hasMaxTileWarning = false;
  // Warnings array is an array of text, priority tuples
  const warningsArr: Array<[text: string, priority: number]> = warnings.reduce(
    (acc, curr) => {
      if (curr.includes('Collapsible groups currently are not yet fully supported.')) {
        if (!hasCollapsibleGroupWarning) {
          acc.push(['- This dashboard contains collapsible groups that were not imported because the importer doesn\'t support their conversion. Tiles in collapsible groups will be unnested.', 0]);
          hasCollapsibleGroupWarning = true;
        }
      } else if (curr.includes('skipped as the maximum number of tiles')) {
        if (!hasMaxTileWarning) {
          acc.push([`- Cloud Monitoring only supports up to 40 tiles, ${numPanels - MAX_TILE_COUNT} tiles have been skipped`, 1]);
          hasMaxTileWarning = true;
        }
      } else {
        acc.push([`- ${curr}`, Infinity])
      }
      return acc;
    }, <Array<[string, number]>>[]);
  warningsArr.sort((a, b) => a[1] - b[1]);
  return warningsArr.map(warning => warning[0]).join('\n');
}