From f408cabe8f93bdc828e661c3fb75bde42c309bf4 Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Thu, 3 Feb 2022 17:09:17 -0500 Subject: [PATCH] handle invalid Splunk On-Call annotations If a `splunk.com/on-call-team` annotation is provided and the API returns no associated team, render... ``` Splunk On-Call API returned no record of teams associated with the "foo" team name Escalation Policy and incident information unavailable. Splunk On-Call requires a valid team name or routing key. ``` If a `splunk.com/on-call-routing-key` annotation is provided and the API returns no associated team, render... ``` Splunk On-Call API returned no record of teams associated with the "foo" routing key Escalation Policy and incident information unavailable. Splunk On-Call requires a valid team name or routing key. ``` Signed-off-by: Mike Ball --- .../src/components/EntitySplunkOnCallCard.tsx | 60 +++++++++++++------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx index 5f9db7e415..559f7c551e 100644 --- a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx +++ b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx @@ -59,15 +59,36 @@ export const MissingAnnotation = () => ( ); -export const InvalidTeamAnnotation = ({ teamName }: { teamName: string }) => ( - - - -); +export const InvalidAnnotation = ({ + teamName, + routingKey, +}: { + teamName: string | undefined; + routingKey: string | undefined; +}) => { + let titleSuffix = 'provided annotation'; + + if (teamName) { + titleSuffix = `"${teamName}" team name`; + } + + if (routingKey) { + titleSuffix = `"${routingKey}" routing key`; + } + + return ( + + + + + + + ); +}; export const MissingEventsRestEndpoint = () => ( @@ -181,17 +202,9 @@ export const EntitySplunkOnCallCard = () => { usersHashMap, }: { team: Team | undefined; - usersHashMap: any | undefined; + usersHashMap: any; }) => { - if (!team) { - return ( - - ); - } - - const teamName = team.name || ''; + const teamName = team && team.name ? team.name : ''; return ( <> @@ -224,6 +237,15 @@ export const EntitySplunkOnCallCard = () => { const teams = usersAndTeams?.foundTeams || []; + if (!teams.length) { + return ( + + ); + } + return ( <> {teams.map((team, i) => (