diff --git a/plugins/pagerduty/api-report.md b/plugins/pagerduty/api-report.md index 854b7b6f29..7ab3a5e1af 100644 --- a/plugins/pagerduty/api-report.md +++ b/plugins/pagerduty/api-report.md @@ -20,7 +20,19 @@ export const EntityPagerDutyCard: ( ) => JSX.Element; // @public (undocumented) -export type EntityPagerDutyCardProps = { +type EntityPagerDutyCardProps = { + readOnly?: boolean; +}; +export { EntityPagerDutyCardProps }; +export { EntityPagerDutyCardProps as PagerDutyCardProps }; + +// @public (undocumented) +export const HomePagePagerDutyCard: ( + props: CardExtensionProps, +) => JSX.Element; + +// @public (undocumented) +export type HomePagePagerDutyCardProps = PagerDutyEntity & { readOnly?: boolean; }; @@ -55,6 +67,9 @@ export type PagerDutyAssignee = { html_url: string; }; +// @public (undocumented) +export const PagerDutyCard: (props: EntityPagerDutyCardProps) => JSX.Element; + // @public (undocumented) export type PagerDutyChangeEvent = { id: string; @@ -126,16 +141,6 @@ export type PagerDutyEntity = { name: string; }; -// @public (undocumented) -export const PagerDutyHomepageCard: ( - props: CardExtensionProps, -) => JSX.Element; - -// @public (undocumented) -export type PagerDutyHomepageCardProps = PagerDutyEntity & { - readOnly?: boolean; -}; - // @public (undocumented) export type PagerDutyIncident = { id: string; diff --git a/plugins/pagerduty/dev/index.tsx b/plugins/pagerduty/dev/index.tsx index 0dca77cc76..4ed8e07263 100644 --- a/plugins/pagerduty/dev/index.tsx +++ b/plugins/pagerduty/dev/index.tsx @@ -15,159 +15,12 @@ */ import React from 'react'; -import { Entity } from '@backstage/catalog-model'; import { EntityProvider } from '@backstage/plugin-catalog-react'; import { createDevApp } from '@backstage/dev-utils'; import { pagerDutyPlugin, EntityPagerDutyCard } from '../src/plugin'; import { pagerDutyApiRef } from '../src/api'; -import { PagerDutyApi, PagerDutyTriggerAlarmRequest } from '../src/api/types'; -import { - PagerDutyIncident, - PagerDutyChangeEvent, -} from '../src/components/types'; -import { PagerDutyEntity } from '../src'; - -const mockEntity: Entity = { - apiVersion: 'backstage.io/v1alpha1', - kind: 'Component', - metadata: { - name: 'backstage', - description: 'backstage.io', - annotations: { - 'github.com/project-slug': 'backstage/backstage', - 'pagerduty.com/service-id': 'foo', - 'pagerduty.com/integration-key': 'foo', - }, - }, - spec: { - lifecycle: 'production', - type: 'website', - owner: 'user:guest', - }, -}; - -const mockPagerDutyApi: PagerDutyApi = { - async getServiceByPagerDutyEntity(pagerDutyEntity: PagerDutyEntity) { - return { - service: { - name: pagerDutyEntity.name, - integrationKey: 'key', - id: '123', - html_url: 'http://service', - escalation_policy: { - id: '123', - html_url: 'http://escalationpolicy', - user: { - id: '123', - summary: 'summary', - email: 'email@email.com', - html_url: 'http://user', - name: 'some-user', - }, - }, - }, - }; - }, - - async getServiceByEntity(entity: Entity) { - return { - service: { - name: entity.metadata.name, - integrationKey: 'key', - id: '123', - html_url: 'http://service', - escalation_policy: { - id: '123', - html_url: 'http://escalationpolicy', - user: { - id: '123', - summary: 'summary', - email: 'email@email.com', - html_url: 'http://user', - name: 'some-user', - }, - }, - }, - }; - }, - - async getIncidentsByServiceId(serviceId: string) { - const incident = (title: string) => { - return { - id: '123', - title: title, - status: 'acknowledged', - html_url: 'http://incident', - assignments: [ - { - assignee: { - id: '123', - summary: 'Jane Doe', - html_url: 'http://assignee', - }, - }, - ], - serviceId: serviceId, - created_at: '2015-10-06T21:30:42Z', - } as PagerDutyIncident; - }; - - return { - incidents: [ - incident('Some Alerting Incident'), - incident('Another Alerting Incident'), - ], - }; - }, - - async getChangeEventsByServiceId(serviceId: string) { - const changeEvent = (description: string) => { - return { - id: serviceId, - source: 'some-source', - html_url: 'http://changeevent', - links: [ - { - href: 'http://link', - text: 'link text', - }, - ], - summary: description, - timestamp: '2018-10-06T21:30:42Z', - } as PagerDutyChangeEvent; - }; - - return { - change_events: [ - changeEvent('us-east-1 deployment'), - changeEvent('us-west-2 deployment'), - ], - }; - }, - - async getOnCallByPolicyId() { - const oncall = (name: string, escalation: number) => { - return { - user: { - id: '123', - name: name, - html_url: 'http://assignee', - summary: 'summary', - email: 'email@email.com', - }, - escalation_level: escalation, - }; - }; - - return { - oncalls: [oncall('Jane Doe', 1), oncall('John Doe', 2)], - }; - }, - - async triggerAlarm(request: PagerDutyTriggerAlarmRequest) { - return new Response(request.description); - }, -}; +import { mockPagerDutyApi } from './mockPagerDutyApi'; +import { mockEntity } from './mockEntity'; createDevApp() .registerApi({ diff --git a/plugins/pagerduty/dev/mockEntity.ts b/plugins/pagerduty/dev/mockEntity.ts new file mode 100644 index 0000000000..251ba80706 --- /dev/null +++ b/plugins/pagerduty/dev/mockEntity.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2023 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'; + +export const mockEntity: Entity = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + name: 'backstage', + description: 'backstage.io', + annotations: { + 'github.com/project-slug': 'backstage/backstage', + 'pagerduty.com/service-id': 'foo', + 'pagerduty.com/integration-key': 'foo', + }, + }, + spec: { + lifecycle: 'production', + type: 'website', + owner: 'user:guest', + }, +}; diff --git a/plugins/pagerduty/dev/mockPagerDutyApi.ts b/plugins/pagerduty/dev/mockPagerDutyApi.ts new file mode 100644 index 0000000000..f8836d7043 --- /dev/null +++ b/plugins/pagerduty/dev/mockPagerDutyApi.ts @@ -0,0 +1,146 @@ +/* + * Copyright 2023 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 { + PagerDutyApi, + PagerDutyChangeEvent, + PagerDutyEntity, + PagerDutyIncident, + PagerDutyTriggerAlarmRequest, +} from '../src'; +import { Entity } from '@backstage/catalog-model'; + +export const mockPagerDutyApi: PagerDutyApi = { + async getServiceByPagerDutyEntity(pagerDutyEntity: PagerDutyEntity) { + return { + service: { + name: pagerDutyEntity.name, + integrationKey: 'key', + id: '123', + html_url: 'http://service', + escalation_policy: { + id: '123', + html_url: 'http://escalationpolicy', + user: { + id: '123', + summary: 'summary', + email: 'email@email.com', + html_url: 'http://user', + name: 'some-user', + }, + }, + }, + }; + }, + + async getServiceByEntity(entity: Entity) { + return { + service: { + name: entity.metadata.name, + integrationKey: 'key', + id: '123', + html_url: 'http://service', + escalation_policy: { + id: '123', + html_url: 'http://escalationpolicy', + user: { + id: '123', + summary: 'summary', + email: 'email@email.com', + html_url: 'http://user', + name: 'some-user', + }, + }, + }, + }; + }, + + async getIncidentsByServiceId(serviceId: string) { + const incident = (title: string) => { + return { + id: '123', + title: title, + status: 'acknowledged', + html_url: 'http://incident', + assignments: [ + { + assignee: { + id: '123', + summary: 'Jane Doe', + html_url: 'http://assignee', + }, + }, + ], + serviceId: serviceId, + created_at: '2015-10-06T21:30:42Z', + } as PagerDutyIncident; + }; + + return { + incidents: [ + incident('Some Alerting Incident'), + incident('Another Alerting Incident'), + ], + }; + }, + + async getChangeEventsByServiceId(serviceId: string) { + const changeEvent = (description: string) => { + return { + id: serviceId, + source: 'some-source', + html_url: 'http://changeevent', + links: [ + { + href: 'http://link', + text: 'link text', + }, + ], + summary: description, + timestamp: '2018-10-06T21:30:42Z', + } as PagerDutyChangeEvent; + }; + + return { + change_events: [ + changeEvent('us-east-1 deployment'), + changeEvent('us-west-2 deployment'), + ], + }; + }, + + async getOnCallByPolicyId() { + const oncall = (name: string, escalation: number) => { + return { + user: { + id: '123', + name: name, + html_url: 'http://assignee', + summary: 'summary', + email: 'email@email.com', + }, + escalation_level: escalation, + }; + }; + + return { + oncalls: [oncall('Jane Doe', 1), oncall('John Doe', 2)], + }; + }, + + async triggerAlarm(request: PagerDutyTriggerAlarmRequest) { + return new Response(request.description); + }, +}; diff --git a/plugins/pagerduty/src/components/PagerDutyHomepageCard/Content.tsx b/plugins/pagerduty/src/components/HomePagePagerDutyCard/Content.tsx similarity index 86% rename from plugins/pagerduty/src/components/PagerDutyHomepageCard/Content.tsx rename to plugins/pagerduty/src/components/HomePagePagerDutyCard/Content.tsx index 017c83e564..b665a6c294 100644 --- a/plugins/pagerduty/src/components/PagerDutyHomepageCard/Content.tsx +++ b/plugins/pagerduty/src/components/HomePagePagerDutyCard/Content.tsx @@ -19,11 +19,11 @@ import { PagerDutyEntity } from '../../types'; import { PagerDutyCard } from '../PagerDutyCard'; /** @public */ -export type PagerDutyHomepageCardProps = PagerDutyEntity & { +export type HomePagePagerDutyCardProps = PagerDutyEntity & { readOnly?: boolean; }; /** @public */ -export const Content = (props: PagerDutyHomepageCardProps) => { +export const Content = (props: HomePagePagerDutyCardProps) => { return ; }; diff --git a/plugins/pagerduty/src/components/PagerDutyHomepageCard/index.ts b/plugins/pagerduty/src/components/HomePagePagerDutyCard/index.ts similarity index 91% rename from plugins/pagerduty/src/components/PagerDutyHomepageCard/index.ts rename to plugins/pagerduty/src/components/HomePagePagerDutyCard/index.ts index 834c01199f..e9038852a6 100644 --- a/plugins/pagerduty/src/components/PagerDutyHomepageCard/index.ts +++ b/plugins/pagerduty/src/components/HomePagePagerDutyCard/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ export { Content } from './Content'; -export type { PagerDutyHomepageCardProps } from './Content'; +export type { HomePagePagerDutyCardProps } from './Content'; diff --git a/plugins/pagerduty/src/components/index.ts b/plugins/pagerduty/src/components/index.ts index 892290e401..264d7195e9 100644 --- a/plugins/pagerduty/src/components/index.ts +++ b/plugins/pagerduty/src/components/index.ts @@ -24,7 +24,7 @@ export type { } from './types'; export type { EntityPagerDutyCardProps } from './EntityPagerDutyCard'; -export type { PagerDutyHomepageCardProps } from './PagerDutyHomepageCard'; +export type { HomePagePagerDutyCardProps } from './HomePagePagerDutyCard'; export { isPluginApplicableToEntity, diff --git a/plugins/pagerduty/src/index.ts b/plugins/pagerduty/src/index.ts index 0517b0752a..19b8456476 100644 --- a/plugins/pagerduty/src/index.ts +++ b/plugins/pagerduty/src/index.ts @@ -24,10 +24,15 @@ export { pagerDutyPlugin, pagerDutyPlugin as plugin, EntityPagerDutyCard, - PagerDutyHomepageCard, + HomePagePagerDutyCard, } from './plugin'; export * from './components'; + +// @deprecated Please use EntityPagerDutyCard +export { EntityPagerDutyCard as PagerDutyCard } from './components'; +export type { EntityPagerDutyCardProps as PagerDutyCardProps } from './components'; + export * from './api'; export type { PagerDutyEntity } from './types'; diff --git a/plugins/pagerduty/src/plugin.ts b/plugins/pagerduty/src/plugin.ts index 8916690a24..408df991e2 100644 --- a/plugins/pagerduty/src/plugin.ts +++ b/plugins/pagerduty/src/plugin.ts @@ -24,7 +24,7 @@ import { createComponentExtension, } from '@backstage/core-plugin-api'; import { createCardExtension } from '@backstage/plugin-home'; -import { PagerDutyHomepageCardProps } from './components/PagerDutyHomepageCard/Content'; +import { HomePagePagerDutyCardProps } from './components/HomePagePagerDutyCard/Content'; export const rootRouteRef = createRouteRef({ id: 'pagerduty', @@ -68,26 +68,26 @@ export const homePlugin = createPlugin({ }); /** @public */ -export const PagerDutyHomepageCard = homePlugin.provide( - createCardExtension({ - name: 'PagerDutyHomepageCard', - title: 'Pager Duty Homepage Card', - components: () => import('./components/PagerDutyHomepageCard'), +export const HomePagePagerDutyCard = homePlugin.provide( + createCardExtension({ + name: 'HomePagePagerDutyCard', + title: 'PagerDuty Homepage Card', + components: () => import('./components/HomePagePagerDutyCard'), settings: { schema: { title: 'Pagerduty', type: 'object', properties: { integrationKey: { - title: 'Pager duty integration key', + title: 'PagerDuty integration key', type: 'string', }, serviceId: { - title: 'Pager duty service id', + title: 'PagerDuty service id', type: 'string', }, name: { - title: 'Pager duty service name', + title: 'PagerDuty service name', type: 'string', }, },