diff --git a/.changeset/tall-rats-lie.md b/.changeset/tall-rats-lie.md new file mode 100644 index 0000000000..ed76970df4 --- /dev/null +++ b/.changeset/tall-rats-lie.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-pagerduty': patch +--- + +Fix change events tab error when change events exist diff --git a/plugins/pagerduty/README.md b/plugins/pagerduty/README.md index e357b8e801..923610db5e 100644 --- a/plugins/pagerduty/README.md +++ b/plugins/pagerduty/README.md @@ -7,6 +7,7 @@ - The Backstage PagerDuty plugin allows PagerDuty information about a Backstage entity to be displayed within Backstage. This includes active incidents, recent change events, as well as the current on-call responders' names, email addresses, and links to their profiles in PagerDuty. - Incidents can be manually triggered via the plugin with a user-provided description, which will in turn notify the current on-call responders. +- Change events will be displayed in a separate tab. If the change event payload has additional links the first link only will be rendered. # Requirements diff --git a/plugins/pagerduty/src/components/ChangeEvents/ChangeEventListItem.tsx b/plugins/pagerduty/src/components/ChangeEvents/ChangeEventListItem.tsx index 703d9d1edf..4912277cee 100644 --- a/plugins/pagerduty/src/components/ChangeEvents/ChangeEventListItem.tsx +++ b/plugins/pagerduty/src/components/ChangeEvents/ChangeEventListItem.tsx @@ -15,6 +15,7 @@ */ import React from 'react'; +import { Link } from '@backstage/core-components'; import { ListItem, ListItemSecondaryAction, @@ -28,7 +29,6 @@ import { DateTime, Duration } from 'luxon'; import { ChangeEvent } from '../types'; import OpenInBrowserIcon from '@material-ui/icons/OpenInBrowser'; import { BackstageTheme } from '@backstage/theme'; -import { Link } from '@backstage/core-components'; const useStyles = makeStyles({ denseListIcon: { @@ -86,15 +86,17 @@ export const ChangeEventListItem = ({ changeEvent }: Props) => { /> {externalLinkElem} - - - - - + {changeEvent.html_url === undefined ? null : ( + + + + + + )} ); diff --git a/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx b/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx index 723e7b7b19..fca2422198 100644 --- a/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx +++ b/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx @@ -92,6 +92,54 @@ describe('Incidents', () => { expect(getAllByTitle('View in PagerDuty').length).toEqual(2); }); + it('Does not render a pagerduty link when html_url is not present in response', async () => { + mockPagerDutyApi.getChangeEventsByServiceId = jest + .fn() + .mockImplementationOnce( + async () => + [ + { + id: 'id1', + source: 'changeSource1', + links: [ + { + href: 'www.externalLink1.com', + text: 'link1', + }, + ], + summary: 'summary of event', + timestamp: '2020-07-17T08:42:58.315+0000', + }, + { + id: 'id2', + source: 'changeSource1', + html_url: 'www.pdlink.com/link', + links: [ + { + href: 'www.externalLink1.com', + text: 'link1', + }, + ], + summary: 'sum of EVENT', + timestamp: '2020-07-18T08:42:58.315+0000', + }, + ] as ChangeEvent[], + ); + const { getByText, getAllByTitle, queryByTestId } = render( + wrapInTestApp( + + + , + ), + ); + await waitFor(() => !queryByTestId('progress')); + expect(getByText('summary of event')).toBeInTheDocument(); + expect(getByText('sum of EVENT')).toBeInTheDocument(); + + // assert links, mailto and hrefs, date calculation + expect(getAllByTitle('View in PagerDuty').length).toEqual(1); + }); + it('Handle errors', async () => { mockPagerDutyApi.getChangeEventsByServiceId = jest .fn()