Add card to display incorrect team annotation where team does not exist per the API

Signed-off-by: Heather Lee <heatherl@splunk.com>
This commit is contained in:
Heather Lee
2021-05-25 15:17:26 -07:00
parent 37ca09566a
commit 0c35f79ed5
@@ -48,6 +48,16 @@ export const MissingTeamAnnotation = () => (
<MissingAnnotationEmptyState annotation={SPLUNK_ON_CALL_TEAM} />
);
export const InvalidTeamAnnotation = ({ teamName }: { teamName: string }) => (
<CardContent>
<EmptyState
title={`Could not find team named "${teamName}" in the Splunk On-Call API`}
missing="info"
description={`Escalation Policy and incident information unavailable. Please verify that the team you added "${teamName}" is valid if you want to enable Splunk On-Call.`}
/>
</CardContent>
);
export const MissingEventsRestEndpoint = () => (
<CardContent>
<EmptyState
@@ -83,7 +93,7 @@ export const SplunkOnCallCard = ({ entity }: Props) => {
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<string, User>, 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 <MissingTeamAnnotation />;
}
if (!usersAndTeam?.foundTeam) {
return <InvalidTeamAnnotation teamName={team} />;
}
if (!eventsRestEndpoint) {
return <MissingEventsRestEndpoint />;
}
@@ -125,8 +141,8 @@ export const SplunkOnCallCard = ({ entity }: Props) => {
return (
<>
<Incidents team={team} refreshIncidents={refreshIncidents} />
{users?.usersHashMap && team && (
<EscalationPolicy team={team} users={users.usersHashMap} />
{usersAndTeam?.usersHashMap && team && (
<EscalationPolicy team={team} users={usersAndTeam.usersHashMap} />
)}
<TriggerDialog
team={team}