pagerduty: migrate to new composability API

This commit is contained in:
Patrik Oldsberg
2021-02-04 00:52:33 +01:00
parent accdfeb30b
commit b288a291ee
7 changed files with 31 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-pagerduty': patch
---
Migrated to new composability API, exporting the plugin instance as `pagerDutyPlugin`, entity card as `EntityPagerDutyCard`, and entity conditional as `isPagerDutyAvailable`.
+2 -2
View File
@@ -14,6 +14,6 @@
* limitations under the License.
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src/plugin';
import { pagerDutyPlugin } from '../src/plugin';
createDevApp().registerPlugin(plugin).render();
createDevApp().registerPlugin(pagerDutyPlugin).render();
+1
View File
@@ -31,6 +31,7 @@
},
"dependencies": {
"@backstage/catalog-model": "^0.7.1",
"@backstage/plugin-catalog-react": "^0.0.2",
"@backstage/core": "^0.6.0",
"@backstage/theme": "^0.2.3",
"@material-ui/core": "^4.11.0",
@@ -16,6 +16,7 @@
import React, { useState, useCallback } from 'react';
import { useApi, Progress, HeaderIconLinkRow } from '@backstage/core';
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import {
Button,
makeStyles,
@@ -56,11 +57,13 @@ export const isPluginApplicableToEntity = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[PAGERDUTY_INTEGRATION_KEY]);
type Props = {
/** @deprecated The entity is now grabbed from context instead */
entity: Entity;
};
export const PagerDutyCard = ({ entity }: Props) => {
export const PagerDutyCard = (_props: Props) => {
const classes = useStyles();
const { entity } = useEntity();
const api = useApi(pagerDutyApiRef);
const [showDialog, setShowDialog] = useState<boolean>(false);
const [refreshIncidents, setRefreshIncidents] = useState<boolean>(false);
+6 -1
View File
@@ -13,9 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { plugin } from './plugin';
export {
pagerDutyPlugin,
pagerDutyPlugin as plugin,
EntityPagerDutyCard,
} from './plugin';
export {
isPluginApplicableToEntity,
isPluginApplicableToEntity as isPagerDutyAvailable,
PagerDutyCard,
} from './components/PagerDutyCard';
export {
+2 -2
View File
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { plugin } from './plugin';
import { pagerDutyPlugin } from './plugin';
describe('pagerduty', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(pagerDutyPlugin).toBeDefined();
});
});
+11 -1
View File
@@ -19,6 +19,7 @@ import {
createRouteRef,
discoveryApiRef,
configApiRef,
createComponentExtension,
} from '@backstage/core';
import { pagerDutyApiRef, PagerDutyClient } from './api';
@@ -27,7 +28,7 @@ export const rootRouteRef = createRouteRef({
title: 'pagerduty',
});
export const plugin = createPlugin({
export const pagerDutyPlugin = createPlugin({
id: 'pagerduty',
apis: [
createApiFactory({
@@ -38,3 +39,12 @@ export const plugin = createPlugin({
}),
],
});
export const EntityPagerDutyCard = pagerDutyPlugin.provide(
createComponentExtension({
component: {
lazy: () =>
import('./components/PagerDutyCard').then(m => m.PagerDutyCard),
},
}),
);