diff --git a/.changeset/tall-years-relate.md b/.changeset/tall-years-relate.md new file mode 100644 index 0000000000..10198992ea --- /dev/null +++ b/.changeset/tall-years-relate.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-airbrake': patch +--- + +Adds a boolean helper function to airbrake plugin for use on the EntityPage to show/hide airbrake tab depending on whether the entity's catalog-info.yml has an airbrake id set in the metadata diff --git a/plugins/airbrake/README.md b/plugins/airbrake/README.md index bc30ca7896..f37ab08b75 100644 --- a/plugins/airbrake/README.md +++ b/plugins/airbrake/README.md @@ -18,14 +18,21 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https: yarn add --cwd packages/backend @backstage/plugin-airbrake-backend ``` -3. Add the `EntityAirbrakeContent` to `packages/app/src/components/catalog/EntityPage.tsx` for all the entity pages you want Airbrake to be in: +3. Add the `EntityAirbrakeContent` and `isAirbrakeAvailable` to `packages/app/src/components/catalog/EntityPage.tsx` for all the entity pages you want Airbrake to be in: ```typescript jsx - import { EntityAirbrakeContent } from '@backstage/plugin-airbrake'; + import { + EntityAirbrakeContent, + isAirbrakeAvailable, + } from '@backstage/plugin-airbrake'; const serviceEntityPage = ( - + @@ -33,7 +40,11 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https: const websiteEntityPage = ( - + @@ -41,7 +52,11 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https: const defaultEntityPage = ( - + diff --git a/plugins/airbrake/api-report.md b/plugins/airbrake/api-report.md index e48fbf9cde..773e2a029a 100644 --- a/plugins/airbrake/api-report.md +++ b/plugins/airbrake/api-report.md @@ -6,6 +6,7 @@ /// import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { Entity } from '@backstage/catalog-model'; import { RouteRef } from '@backstage/core-plugin-api'; // @public @@ -19,4 +20,7 @@ export const airbrakePlugin: BackstagePlugin< // @public export const EntityAirbrakeContent: () => JSX.Element; + +// @public +export const isAirbrakeAvailable: (entity: Entity) => boolean; ``` diff --git a/plugins/airbrake/src/components/isAirbrakeAvailable.ts b/plugins/airbrake/src/components/isAirbrakeAvailable.ts new file mode 100644 index 0000000000..01d59668ce --- /dev/null +++ b/plugins/airbrake/src/components/isAirbrakeAvailable.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Entity } from '@backstage/catalog-model'; +import { AIRBRAKE_PROJECT_ID_ANNOTATION } from './useProjectId'; + +/** + * Utility function to determine if the given entity has an Airbrake ID set in the repos catalog-info.yml . + * @public + */ +export const isAirbrakeAvailable = (entity: Entity) => + Boolean(entity.metadata.annotations?.[AIRBRAKE_PROJECT_ID_ANNOTATION]); diff --git a/plugins/airbrake/src/index.ts b/plugins/airbrake/src/index.ts index 2b2406776b..717d544dc9 100644 --- a/plugins/airbrake/src/index.ts +++ b/plugins/airbrake/src/index.ts @@ -22,3 +22,4 @@ export { airbrakePlugin } from './plugin'; export { EntityAirbrakeContent } from './extensions'; +export { isAirbrakeAvailable } from './components/isAirbrakeAvailable';