feat(splunk-on-call-plugin): filter team incidents

This commit is contained in:
Remi
2021-02-05 14:58:57 +01:00
parent 932d38840d
commit 631419926b
5 changed files with 42 additions and 20 deletions
+10
View File
@@ -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<Team[]> {
const url = `${await this.config.discoveryApi.getBaseUrl(
'proxy',
)}/splunk-on-call/v1/team`;
const teams = await this.getByUrl<Team[]>(url);
return teams;
}
async acknowledgeIncident({
userName,
incidentNames,
+6
View File
@@ -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<Team[]>;
/**
* Get a list of escalation policies for your organization.
*/
getEscalationPolicies(): Promise<EscalationPolicyInfo[]>;
}
@@ -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(() => {
@@ -127,7 +127,7 @@ export const SplunkOnCallCard = ({ entity }: Props) => {
/>
<Divider />
<CardContent>
<Incidents refreshIncidents={refreshIncidents} />
<Incidents team={team} refreshIncidents={refreshIncidents} />
{users?.usersHashMap && (
<EscalationPolicy team={team} users={users.usersHashMap} />
)}
+14 -17
View File
@@ -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;
};