From 122410f1ab388d0bd48480d9d486c2b4ecd89212 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Thu, 5 Nov 2020 10:49:11 +0100 Subject: [PATCH] fix typings --- .../pagerduty/src/components/Escalation.tsx | 12 +-- .../pagerduty/src/components/Incidents.tsx | 15 +-- plugins/pagerduty/src/components/types.tsx | 92 +++++++++++++++---- 3 files changed, 88 insertions(+), 31 deletions(-) diff --git a/plugins/pagerduty/src/components/Escalation.tsx b/plugins/pagerduty/src/components/Escalation.tsx index 69a4543c4b..19c6a15096 100644 --- a/plugins/pagerduty/src/components/Escalation.tsx +++ b/plugins/pagerduty/src/components/Escalation.tsx @@ -30,7 +30,7 @@ import UserIcon from '@material-ui/icons/Person'; import EmailIcon from '@material-ui/icons/Email'; import { StatusWarning } from '@backstage/core'; import Pagerduty from '../assets/pd.svg'; -import { PagerDutyUserData } from './types'; +import { Oncall, PagerDutyEscalationPolicy } from './types'; const useStyles = makeStyles({ denseListIcon: { @@ -45,11 +45,7 @@ const useStyles = makeStyles({ }, }); -type EscalationUserProps = { - user: PagerDutyUserData; -}; - -const EscalationUser = ({ user }: EscalationUserProps) => { +const EscalationUser = ({ user }: PagerDutyEscalationPolicy) => { const classes = useStyles(); return ( @@ -65,7 +61,7 @@ const EscalationUser = ({ user }: EscalationUserProps) => { @@ -96,7 +92,7 @@ const EscalationUsersEmptyState = () => { }; type EscalationPolicyProps = { - escalation: PagerDutyUserData[]; + escalation: Oncall[]; }; export const EscalationPolicy = ({ escalation }: EscalationPolicyProps) => ( diff --git a/plugins/pagerduty/src/components/Incidents.tsx b/plugins/pagerduty/src/components/Incidents.tsx index d2f6fc7128..0117281a0e 100644 --- a/plugins/pagerduty/src/components/Incidents.tsx +++ b/plugins/pagerduty/src/components/Incidents.tsx @@ -29,6 +29,7 @@ import { import { StatusError, StatusWarning, StatusOK } from '@backstage/core'; import Pagerduty from '../assets/pd.svg'; import moment from 'moment'; +import { Incident } from '../components/types'; const useStyles = makeStyles({ denseListIcon: { @@ -57,13 +58,13 @@ const IncidentsEmptyState = () => { ); }; -type IncidentListProps = { - incidents: any; +type IncidentListItemProps = { + incident: Incident; }; -const IncidentList = ({ incidents }: IncidentListProps) => { +const IncidentListItem = ({ incident }: IncidentListItemProps) => { const classes = useStyles(); - return incidents.map((incident: any) => ( + return ( @@ -103,17 +104,17 @@ const IncidentList = ({ incidents }: IncidentListProps) => { - )); + ); }; type IncidentsProps = { - incidents: Array; + incidents: Incident[]; }; export const Incidents = ({ incidents }: IncidentsProps) => ( Incidents}> {incidents.length ? ( - + incidents.map(incident => ) ) : ( )} diff --git a/plugins/pagerduty/src/components/types.tsx b/plugins/pagerduty/src/components/types.tsx index b3b94f0200..377ae6d0ea 100644 --- a/plugins/pagerduty/src/components/types.tsx +++ b/plugins/pagerduty/src/components/types.tsx @@ -1,27 +1,87 @@ -export type PagerDutyIncident = { +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export type Incident = { id: string; title: string; status: string; - createdAt: string; homepageUrl: string; - assignees: Partial[]; + assignments: [ + { + assignee: User; + }, + ]; + serviceId: string; + created_at: string; }; -export type PagerDutyUserData = { +export type Service = { + id: string; + name: string; + html_url: string; + integrationKey: string; + escalation_policy: PagerDutyEscalationPolicy; +}; + +export type ResponseService = { + services: Service[]; + more: boolean; +}; + +export type ResponseOncall = { + id: string; + name: string; email: string; - name: string; - homepageUrl: string; - id: string; -}; - -export type PagerDutyServicesData = { - activeIncidents: PagerDutyIncident[]; - escalationPolicy: any; // PagerDutyUserData[]; - id: string; - name: string; homepageUrl: string; }; -export type PagerDutyData = { - pagerDutyServices: PagerDutyServicesData[]; +export type Options = { + method: string; + headers: HeadersInit; + body?: BodyInit; +}; + +export type PagerDutyClientConfig = { + token?: string; +}; + +export type ServicesResponse = { + services: Service[]; +}; + +export type IncidentResponse = { + incidents: Incident[]; +}; + +export type OncallsResponse = { + oncalls: Oncall[]; +}; + +export type PagerDutyEscalationPolicy = { + user: User; +}; + +export type User = { + id: string; + summary: string; + email: string; + html_url: string; + name: string; +}; + +export type Oncall = { + escalation_policy: PagerDutyEscalationPolicy; + user: User; };