From c55f6cb22d8caf54f6de98186d8f0c752433847d Mon Sep 17 00:00:00 2001 From: Jonathan Sundquist Date: Wed, 18 May 2022 10:53:27 -0500 Subject: [PATCH] feat(sentry): adding a check if sentry is available Signed-off-by: Jonathan Sundquist Signed-off-by: Jonathan Sundquist --- .changeset/fifty-dogs-collect.md | 5 +++++ plugins/sentry/api-report.md | 3 +++ plugins/sentry/src/components/index.ts | 1 + plugins/sentry/src/components/useProjectSlug.ts | 7 +++++++ 4 files changed, 16 insertions(+) create mode 100644 .changeset/fifty-dogs-collect.md diff --git a/.changeset/fifty-dogs-collect.md b/.changeset/fifty-dogs-collect.md new file mode 100644 index 0000000000..6e3d971bf5 --- /dev/null +++ b/.changeset/fifty-dogs-collect.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-sentry': patch +--- + +Providing a way for users to determine if sentry is available. diff --git a/plugins/sentry/api-report.md b/plugins/sentry/api-report.md index 5ad2992ee4..043fa7a1fd 100644 --- a/plugins/sentry/api-report.md +++ b/plugins/sentry/api-report.md @@ -31,6 +31,9 @@ export const EntitySentryContent: ({ tableOptions, }: SentryPageProps) => JSX.Element; +// @public +export const isSentryAvailable: (entity: Entity) => boolean; + // Warning: (ae-missing-release-tag) "MockSentryApi" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) diff --git a/plugins/sentry/src/components/index.ts b/plugins/sentry/src/components/index.ts index 210ba8d718..f2dddaff18 100644 --- a/plugins/sentry/src/components/index.ts +++ b/plugins/sentry/src/components/index.ts @@ -15,3 +15,4 @@ */ export * from './SentryIssuesWidget'; +export { isSentryAvailable } from './useProjectSlug'; diff --git a/plugins/sentry/src/components/useProjectSlug.ts b/plugins/sentry/src/components/useProjectSlug.ts index 0796e9e8df..a8f07436b0 100644 --- a/plugins/sentry/src/components/useProjectSlug.ts +++ b/plugins/sentry/src/components/useProjectSlug.ts @@ -18,6 +18,13 @@ import { Entity } from '@backstage/catalog-model'; export const SENTRY_PROJECT_SLUG_ANNOTATION = 'sentry.io/project-slug'; +/** + * @public + * Checks to see if sentry is available + */ +export const isSentryAvailable = (entity: Entity) => + Boolean(entity.metadata.annotations?.[SENTRY_PROJECT_SLUG_ANNOTATION]); + export const useProjectSlug = (entity: Entity) => { return entity?.metadata.annotations?.[SENTRY_PROJECT_SLUG_ANNOTATION] ?? ''; };