{"version":3,"file":"usePluginInteractionReporter.mjs","sources":["../../../../src/analytics/plugins/usePluginInteractionReporter.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport { isDataSourcePluginContext, usePluginContext } from '@grafana/data';\n\nimport { reportInteraction } from '../utils';\n\nimport { createDataSourcePluginEventProperties, createPluginEventProperties } from './eventProperties';\n\nconst namePrefix = 'grafana_plugin_';\n\nexport function usePluginInteractionReporter(): typeof reportInteraction {\n  const context = usePluginContext();\n\n  return useMemo(() => {\n    // Happens when the hook is not used inside a plugin (e.g. in core Grafana)\n    if (!context) {\n      throw new Error(\n        `No PluginContext found. The usePluginInteractionReporter() hook can only be used from a plugin.`\n      );\n    }\n\n    const info = isDataSourcePluginContext(context)\n      ? createDataSourcePluginEventProperties(context.instanceSettings)\n      : createPluginEventProperties(context.meta);\n\n    return (interactionName: string, properties?: Record<string, unknown>) => {\n      if (!validInteractionName(interactionName)) {\n        throw new Error(`Interactions reported in plugins should start with: \"${namePrefix}\".`);\n      }\n      return reportInteraction(interactionName, { ...properties, ...info });\n    };\n  }, [context]);\n}\n\nfunction validInteractionName(interactionName: string): boolean {\n  return interactionName.startsWith(namePrefix) && interactionName.length > namePrefix.length;\n}\n"],"names":[],"mappings":";;;;;AAQA,MAAM,UAAa,GAAA,iBAAA;AAEZ,SAAS,4BAAyD,GAAA;AACvE,EAAA,MAAM,UAAU,gBAAiB,EAAA;AAEjC,EAAA,OAAO,QAAQ,MAAM;AAEnB,IAAA,IAAI,CAAC,OAAS,EAAA;AACZ,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,+FAAA;AAAA,OACF;AAAA;AAGF,IAAM,MAAA,IAAA,GAAO,yBAA0B,CAAA,OAAO,CAC1C,GAAA,qCAAA,CAAsC,QAAQ,gBAAgB,CAAA,GAC9D,2BAA4B,CAAA,OAAA,CAAQ,IAAI,CAAA;AAE5C,IAAO,OAAA,CAAC,iBAAyB,UAAyC,KAAA;AACxE,MAAI,IAAA,CAAC,oBAAqB,CAAA,eAAe,CAAG,EAAA;AAC1C,QAAA,MAAM,IAAI,KAAA,CAAM,CAAwD,qDAAA,EAAA,UAAU,CAAI,EAAA,CAAA,CAAA;AAAA;AAExF,MAAA,OAAO,kBAAkB,eAAiB,EAAA,EAAE,GAAG,UAAY,EAAA,GAAG,MAAM,CAAA;AAAA,KACtE;AAAA,GACF,EAAG,CAAC,OAAO,CAAC,CAAA;AACd;AAEA,SAAS,qBAAqB,eAAkC,EAAA;AAC9D,EAAA,OAAO,gBAAgB,UAAW,CAAA,UAAU,CAAK,IAAA,eAAA,CAAgB,SAAS,UAAW,CAAA,MAAA;AACvF;;;;"}