Merge pull request #15993 from simplybusiness/export-airbrake-plugin-helper-function

Export airbrake plugin helper function
This commit is contained in:
Ben Lambert
2023-01-30 15:01:36 +01:00
committed by GitHub
5 changed files with 55 additions and 5 deletions
+20 -5
View File
@@ -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 = (
<EntityLayoutWrapper>
<EntityLayout.Route path="/airbrake" title="Airbrake">
<EntityLayout.Route
if={isAirbrakeAvailable}
path="/airbrake"
title="Airbrake"
>
<EntityAirbrakeContent />
</EntityLayout.Route>
</EntityLayoutWrapper>
@@ -33,7 +40,11 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https:
const websiteEntityPage = (
<EntityLayoutWrapper>
<EntityLayout.Route path="/airbrake" title="Airbrake">
<EntityLayout.Route
if={isAirbrakeAvailable}
path="/airbrake"
title="Airbrake"
>
<EntityAirbrakeContent />
</EntityLayout.Route>
</EntityLayoutWrapper>
@@ -41,7 +52,11 @@ The Airbrake plugin provides connectivity between Backstage and Airbrake (https:
const defaultEntityPage = (
<EntityLayoutWrapper>
<EntityLayout.Route path="/airbrake" title="Airbrake">
<EntityLayout.Route
if={isAirbrakeAvailable}
path="/airbrake"
title="Airbrake"
>
<EntityAirbrakeContent />
</EntityLayout.Route>
</EntityLayoutWrapper>
+4
View File
@@ -6,6 +6,7 @@
/// <reference types="react" />
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;
```
@@ -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]);
+1
View File
@@ -22,3 +22,4 @@
export { airbrakePlugin } from './plugin';
export { EntityAirbrakeContent } from './extensions';
export { isAirbrakeAvailable } from './components/isAirbrakeAvailable';