{"version":3,"file":"utils.cjs","sources":["../../../../src/grafana/contactPoints/utils.ts"],"sourcesContent":["import { countBy, isEmpty } from 'lodash';\n\nimport { Receiver } from '@grafana/api-clients/rtkq/notifications.alerting/v0alpha1';\n\nimport { ContactPoint } from '../api/notifications/v0alpha1/types';\n\n// Annotation key that indicates whether a contact point can be used in routes and rules\nconst CAN_USE_ANNOTATION = 'grafana.com/canUse';\n\n/**\n * Checks if a contact point can be used in routes and rules.\n * Contact points that are imported from external sources (e.g., Prometheus Alertmanager)\n * have the `grafana.com/canUse` annotation set to `false` and cannot be used.\n *\n * @param contactPoint - The ContactPoint object to check\n * @returns `true` if the contact point can be used, `false` otherwise\n */\nexport function isUsableContactPoint(contactPoint: ContactPoint | Receiver): boolean {\n  const canUse = contactPoint.metadata?.annotations?.[CAN_USE_ANNOTATION];\n  return canUse === 'true';\n}\n\n/**\n * Generates a human-readable description of a ContactPoint by summarizing its integrations.\n * If the ContactPoint has no integrations, it returns an empty placeholder text.\n *\n * For integrations, it counts the occurrences of each type and formats them as a comma-separated list.\n * Multiple integrations of the same type are indicated with a count in parentheses.\n *\n * @param contactPoint - The ContactPoint object to describe\n * @returns A string description of the ContactPoint's integrations\n */\nexport function getContactPointDescription(contactPoint: ContactPoint | Receiver): string {\n  if (isEmpty(contactPoint.spec.integrations)) {\n    return '<empty contact point>';\n  }\n\n  // Count the occurrences of each integration type\n  const integrationCounts = countBy(contactPoint.spec.integrations, (integration) => integration.type);\n\n  const description = Object.entries(integrationCounts)\n    .map(([type, count]) => {\n      // either \"email\" or \"email (2)\" but not \"email (1)\"\n      return count > 1 ? `${type} (${count})` : type;\n    })\n    .join(', ');\n\n  return description;\n}\n"],"names":["isEmpty","countBy"],"mappings":";;;;;;;AAOA,MAAM,kBAAA,GAAqB,oBAAA;AAUpB,SAAS,qBAAqB,YAAA,EAAgD;AAjBrF,EAAA,IAAA,EAAA,EAAA,EAAA;AAkBE,EAAA,MAAM,MAAA,GAAA,CAAS,EAAA,GAAA,CAAA,EAAA,GAAA,YAAA,CAAa,QAAA,KAAb,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAuB,gBAAvB,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAqC,kBAAA,CAAA;AACpD,EAAA,OAAO,MAAA,KAAW,MAAA;AACpB;AAYO,SAAS,2BAA2B,YAAA,EAA+C;AACxF,EAAA,IAAIA,cAAA,CAAQ,YAAA,CAAa,IAAA,CAAK,YAAY,CAAA,EAAG;AAC3C,IAAA,OAAO,uBAAA;AAAA,EACT;AAGA,EAAA,MAAM,iBAAA,GAAoBC,eAAQ,YAAA,CAAa,IAAA,CAAK,cAAc,CAAC,WAAA,KAAgB,YAAY,IAAI,CAAA;AAEnG,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,OAAA,CAAQ,iBAAiB,CAAA,CACjD,IAAI,CAAC,CAAC,IAAA,EAAM,KAAK,CAAA,KAAM;AAEtB,IAAA,OAAO,QAAQ,CAAA,GAAI,CAAA,EAAG,IAAI,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA,CAAA,GAAM,IAAA;AAAA,EAC5C,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AAEZ,EAAA,OAAO,WAAA;AACT;;;;;"}