From 631419926bca1c8304cbbe7437e24c795caef626 Mon Sep 17 00:00:00 2001 From: Remi Date: Fri, 5 Feb 2021 14:58:57 +0100 Subject: [PATCH] feat(splunk-on-call-plugin): filter team incidents --- plugins/splunk-on-call/src/api/client.ts | 10 ++++++ plugins/splunk-on-call/src/api/types.ts | 6 ++++ .../src/components/Incident/Incidents.tsx | 13 ++++++-- .../src/components/SplunkOnCallCard.tsx | 2 +- .../splunk-on-call/src/components/types.ts | 31 +++++++++---------- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/plugins/splunk-on-call/src/api/client.ts b/plugins/splunk-on-call/src/api/client.ts index 09c3b6cf93..02b560b1db 100644 --- a/plugins/splunk-on-call/src/api/client.ts +++ b/plugins/splunk-on-call/src/api/client.ts @@ -20,6 +20,7 @@ import { OnCall, User, EscalationPolicyInfo, + Team, } from '../components/types'; import { SplunkOnCallApi, @@ -70,6 +71,15 @@ export class SplunkOnCallClient implements SplunkOnCallApi { return teamsOnCall; } + async getTeams(): Promise { + const url = `${await this.config.discoveryApi.getBaseUrl( + 'proxy', + )}/splunk-on-call/v1/team`; + const teams = await this.getByUrl(url); + + return teams; + } + async acknowledgeIncident({ userName, incidentNames, diff --git a/plugins/splunk-on-call/src/api/types.ts b/plugins/splunk-on-call/src/api/types.ts index cc3b1a1e8c..bf725ba158 100644 --- a/plugins/splunk-on-call/src/api/types.ts +++ b/plugins/splunk-on-call/src/api/types.ts @@ -19,6 +19,7 @@ import { Incident, OnCall, Service, + Team, User, } from '../components/types'; import { DiscoveryApi } from '@backstage/core'; @@ -77,6 +78,11 @@ export interface SplunkOnCallApi { /** * Get a list of users for your organization. */ + getTeams(): Promise; + + /** + * Get a list of escalation policies for your organization. + */ getEscalationPolicies(): Promise; } diff --git a/plugins/splunk-on-call/src/components/Incident/Incidents.tsx b/plugins/splunk-on-call/src/components/Incident/Incidents.tsx index 84b0866757..fad8a6030b 100644 --- a/plugins/splunk-on-call/src/components/Incident/Incidents.tsx +++ b/plugins/splunk-on-call/src/components/Incident/Incidents.tsx @@ -25,13 +25,22 @@ import { Alert } from '@material-ui/lab'; type Props = { refreshIncidents: boolean; + team: string; }; -export const Incidents = ({ refreshIncidents }: Props) => { +export const Incidents = ({ refreshIncidents, team }: Props) => { const api = useApi(splunkOnCallApiRef); const [{ value: incidents, loading, error }, getIncidents] = useAsyncFn( - async () => await api.getIncidents(), + async () => { + const incidents = await api.getIncidents(); + const teams = await api.getTeams(); + const teamSlug = teams.find(teamValue => teamValue.name === team)?.slug; + const filteredIncidents = teamSlug + ? incidents.filter(incident => incident.pagedTeams?.includes(teamSlug)) + : []; + return filteredIncidents; + }, ); useEffect(() => { diff --git a/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx b/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx index 3b80394b6f..0a9f20b1e0 100644 --- a/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx +++ b/plugins/splunk-on-call/src/components/SplunkOnCallCard.tsx @@ -127,7 +127,7 @@ export const SplunkOnCallCard = ({ entity }: Props) => { /> - + {users?.usersHashMap && ( )} diff --git a/plugins/splunk-on-call/src/components/types.ts b/plugins/splunk-on-call/src/components/types.ts index 5964c04f09..51ea17653d 100644 --- a/plugins/splunk-on-call/src/components/types.ts +++ b/plugins/splunk-on-call/src/components/types.ts @@ -40,21 +40,18 @@ export type SubHeaderLink = { action?: React.ReactNode; }; -// GET Escalation Policies - -// export type EscalationPolicyInfo = { -// policy: EscalationPolicySummary; -// team: Team; -// } -// export type EscalationPolicySummary = { -// name: string; -// slug: string; -// _selfUrl: string; -// } -// export type Team = { -// name: string; -// slug: string; -// } +// GET Teams +export type Team = { + name?: string; + slug?: string; + memberCount?: number; + version?: string; + isDefaultTeam?: boolean; + _selfUrl?: string; + _policiesUrl?: string; + _membersUrl?: string; + _adminsUrl?: string; +}; // GET oncall export type OnCall = { @@ -130,7 +127,7 @@ export type Incident = { export type EscalationPolicyInfo = { policy: EscalationPolicySummary; - team: Team; + team: EscalationPolicyTeam; }; export type IncidentTransition = { @@ -149,7 +146,7 @@ export type EscalationPolicySummary = { _selfUrl: string; }; -export type Team = { +export type EscalationPolicyTeam = { name: string; slug: string; };