From 0c35f79ed5c1335b28e7ef090e4d1caa31a3899e Mon Sep 17 00:00:00 2001 From: Heather Lee Date: Tue, 25 May 2021 15:17:26 -0700 Subject: [PATCH 1/5] Add card to display incorrect team annotation where team does not exist per the API Signed-off-by: Heather Lee --- .../src/components/SplunkOnCallCard.tsx | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx b/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx index a7079841a8..c4b5aaa11f 100644 --- a/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx +++ b/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx @@ -48,6 +48,16 @@ export const MissingTeamAnnotation = () => ( ); +export const InvalidTeamAnnotation = ({ teamName }: { teamName: string }) => ( + + + +); + export const MissingEventsRestEndpoint = () => ( { setShowDialog(x => !x); }, []); - const { value: users, loading, error } = useAsync(async () => { + const { value: usersAndTeam, loading, error } = useAsync(async () => { const allUsers = await api.getUsers(); const usersHashMap = allUsers.reduce( (map: Record, obj: User) => { @@ -94,7 +104,9 @@ export const SplunkOnCallCard = ({ entity }: Props) => { }, {}, ); - return { usersHashMap, userList: allUsers }; + const teams = await api.getTeams(); + const foundTeam = teams.find(teamValue => teamValue.name === team); + return { usersHashMap, foundTeam }; }); if (error instanceof UnauthorizedError) { @@ -118,6 +130,10 @@ export const SplunkOnCallCard = ({ entity }: Props) => { return ; } + if (!usersAndTeam?.foundTeam) { + return ; + } + if (!eventsRestEndpoint) { return ; } @@ -125,8 +141,8 @@ export const SplunkOnCallCard = ({ entity }: Props) => { return ( <> - {users?.usersHashMap && team && ( - + {usersAndTeam?.usersHashMap && team && ( + )} Date: Tue, 25 May 2021 15:37:24 -0700 Subject: [PATCH 2/5] Add changeset Signed-off-by: Heather Lee --- .changeset/olive-rocks-listen.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/olive-rocks-listen.md diff --git a/.changeset/olive-rocks-listen.md b/.changeset/olive-rocks-listen.md new file mode 100644 index 0000000000..cadaf6fcff --- /dev/null +++ b/.changeset/olive-rocks-listen.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-splunk-on-call': minor +--- + +Update Splunk On Call plugin to render warning message about incorrectly configured team annotation From 8eb2c2951c2ba93008ea9390df69cd33b85d9e26 Mon Sep 17 00:00:00 2001 From: Heather Lee Date: Tue, 25 May 2021 15:49:18 -0700 Subject: [PATCH 3/5] Update the tests to consider on call annotation for team as 'test' to match mock value Signed-off-by: Heather Lee --- .../src/components/EntitySplunkOnCallCard.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx index 119a6fc1f7..365de7b732 100644 --- a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx +++ b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx @@ -76,7 +76,7 @@ const mockEntityData = { metadata: { name: 'splunkoncall-test', annotations: { - 'splunk.com/on-call-team': 'Example', + 'splunk.com/on-call-team': 'test', }, }, } as Entity, From bfa0908de05edbe2136012497c1f2826f02fe3fc Mon Sep 17 00:00:00 2001 From: Heather Lee Date: Tue, 25 May 2021 16:57:43 -0700 Subject: [PATCH 4/5] Fix tests Signed-off-by: Heather Lee --- plugins/splunk-on-call/src/api/mocks.ts | 6 +++ .../EntitySplunkOnCallCard.test.tsx | 47 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/plugins/splunk-on-call/src/api/mocks.ts b/plugins/splunk-on-call/src/api/mocks.ts index 86df04275d..22f1a87788 100644 --- a/plugins/splunk-on-call/src/api/mocks.ts +++ b/plugins/splunk-on-call/src/api/mocks.ts @@ -88,6 +88,12 @@ export const MOCK_TEAM: Team = { isDefaultTeam: false, }; +export const MOCK_TEAM_NO_INCIDENTS: Team = { + ...MOCK_TEAM, + name: 'test-noincidents', + slug: 'team-O9SqT13fsnCstjMj', +}; + export const ESCALATION_POLICIES: EscalationPolicyInfo[] = [ { policy: { diff --git a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx index 365de7b732..838d9e4e4b 100644 --- a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx +++ b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx @@ -38,6 +38,7 @@ import { MOCKED_USER, MOCK_INCIDENT, MOCK_TEAM, + MOCK_TEAM_NO_INCIDENTS, } from '../api/mocks'; import { EntitySplunkOnCallCard } from './EntitySplunkOnCallCard'; @@ -82,16 +83,34 @@ const mockEntityData = { } as Entity, }; +const mockEntityDataNoIncidents = { + loading: false, + error: undefined, + entity: { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + name: 'splunkoncall-test', + annotations: { + 'splunk.com/on-call-team': 'test-noincidents', + }, + }, + } as Entity, +}; + describe('SplunkOnCallCard', () => { it('Render splunkoncall', async () => { mockSplunkOnCallApi.getUsers = jest .fn() .mockImplementationOnce(async () => [MOCKED_USER]); + mockSplunkOnCallApi.getTeams = jest + .fn() + .mockImplementation(async () => [MOCK_TEAM_NO_INCIDENTS]); const { getByText, queryByTestId } = render( wrapInTestApp( - + , @@ -148,10 +167,36 @@ describe('SplunkOnCallCard', () => { ).toBeInTheDocument(); }); + it('handles warning for incorrect team annotation', async () => { + mockSplunkOnCallApi.getUsers = jest + .fn() + .mockImplementationOnce(async () => [MOCKED_USER]); + mockSplunkOnCallApi.getTeams = jest + .fn() + .mockImplementationOnce(async () => []); + + const { getByText, queryByTestId } = render( + wrapInTestApp( + + + + + , + ), + ); + await waitFor(() => !queryByTestId('progress')); + expect( + getByText('Could not find team named "test" in the Splunk On-Call API'), + ).toBeInTheDocument(); + }); + it('opens the dialog when trigger button is clicked', async () => { mockSplunkOnCallApi.getUsers = jest .fn() .mockImplementationOnce(async () => [MOCKED_USER]); + mockSplunkOnCallApi.getTeams = jest + .fn() + .mockImplementationOnce(async () => [MOCK_TEAM]); const { getByText, queryByTestId, getByRole } = render( wrapInTestApp( From 0e8a2958fb1d84e9464d1d2ca9269a5857be0f02 Mon Sep 17 00:00:00 2001 From: Heather Lee Date: Wed, 26 May 2021 10:43:41 -0700 Subject: [PATCH 5/5] Update changeset to patch Signed-off-by: Heather Lee --- .changeset/olive-rocks-listen.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/olive-rocks-listen.md b/.changeset/olive-rocks-listen.md index cadaf6fcff..f40a1de497 100644 --- a/.changeset/olive-rocks-listen.md +++ b/.changeset/olive-rocks-listen.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-splunk-on-call': minor +'@backstage/plugin-splunk-on-call': patch --- Update Splunk On Call plugin to render warning message about incorrectly configured team annotation