From 934c4043b4d8daf543e8d8e309228cd165725a0d Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Wed, 9 Dec 2020 16:33:32 +0100 Subject: [PATCH 1/4] add timezone to queries and sort oncalls --- plugins/pagerduty/src/api/client.ts | 6 +++--- .../src/components/Escalation/EscalationPolicy.tsx | 4 +++- plugins/pagerduty/src/components/types.ts | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/pagerduty/src/api/client.ts b/plugins/pagerduty/src/api/client.ts index 527a56b2af..34bba1b7b3 100644 --- a/plugins/pagerduty/src/api/client.ts +++ b/plugins/pagerduty/src/api/client.ts @@ -46,7 +46,7 @@ export class PagerDutyClient implements PagerDutyApi { constructor(private readonly config: ClientApiConfig) {} async getServiceByIntegrationKey(integrationKey: string): Promise { - const params = `include[]=integrations&include[]=escalation_policies&query=${integrationKey}`; + const params = `time_zone=UTC&include[]=integrations&include[]=escalation_policies&query=${integrationKey}`; const url = `${await this.config.discoveryApi.getBaseUrl( 'proxy', )}/pagerduty/services?${params}`; @@ -56,7 +56,7 @@ export class PagerDutyClient implements PagerDutyApi { } async getIncidentsByServiceId(serviceId: string): Promise { - const params = `statuses[]=triggered&statuses[]=acknowledged&service_ids[]=${serviceId}`; + const params = `time_zone=UTC&sort_by=created_at&statuses[]=triggered&statuses[]=acknowledged&service_ids[]=${serviceId}`; const url = `${await this.config.discoveryApi.getBaseUrl( 'proxy', )}/pagerduty/incidents?${params}`; @@ -66,7 +66,7 @@ export class PagerDutyClient implements PagerDutyApi { } async getOnCallByPolicyId(policyId: string): Promise { - const params = `include[]=users&escalation_policy_ids[]=${policyId}`; + const params = `time_zone=UTC&include[]=users&escalation_policy_ids[]=${policyId}&include[]=escalation_level`; const url = `${await this.config.discoveryApi.getBaseUrl( 'proxy', )}/pagerduty/oncalls?${params}`; diff --git a/plugins/pagerduty/src/components/Escalation/EscalationPolicy.tsx b/plugins/pagerduty/src/components/Escalation/EscalationPolicy.tsx index 5e67d52172..faa480f6e2 100644 --- a/plugins/pagerduty/src/components/Escalation/EscalationPolicy.tsx +++ b/plugins/pagerduty/src/components/Escalation/EscalationPolicy.tsx @@ -32,7 +32,9 @@ export const EscalationPolicy = ({ policyId }: Props) => { const { value: users, loading, error } = useAsync(async () => { const oncalls = await api.getOnCallByPolicyId(policyId); - const users = oncalls.map(oncall => oncall.user); + const users = oncalls + .sort((a, b) => a.escalation_level - b.escalation_level) + .map(oncall => oncall.user); return users; }); diff --git a/plugins/pagerduty/src/components/types.ts b/plugins/pagerduty/src/components/types.ts index 371f4eea6d..ff63c81518 100644 --- a/plugins/pagerduty/src/components/types.ts +++ b/plugins/pagerduty/src/components/types.ts @@ -41,6 +41,7 @@ export type Service = { export type OnCall = { user: User; + escalation_level: number; }; export type Assignee = { From e80423734873fc166a4df7574bd1cac9c17f3343 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Wed, 9 Dec 2020 17:01:08 +0100 Subject: [PATCH 2/4] make more responsive --- .../Incident/IncidentEmptyState.tsx | 2 +- .../components/Incident/IncidentListItem.tsx | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/pagerduty/src/components/Incident/IncidentEmptyState.tsx b/plugins/pagerduty/src/components/Incident/IncidentEmptyState.tsx index b697422b0f..f7a0398c55 100644 --- a/plugins/pagerduty/src/components/Incident/IncidentEmptyState.tsx +++ b/plugins/pagerduty/src/components/Incident/IncidentEmptyState.tsx @@ -22,7 +22,7 @@ export const IncidentsEmptyState = () => { return ( - Nice! No incidents found! + Nice! No incidents found! { className: classes.listItemPrimary, }} secondary={ - - Created {createdAt} ago and assigned to{' '} - - {user?.summary ?? 'nobody'} - - + + + + Created {createdAt} ago and assigned to{' '} + + + + + {user?.summary ?? 'nobody'} + + + } /> From 3b50f833dfedee33e868b1fbc165b3d59cbb15cd Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Mon, 14 Dec 2020 11:30:10 +0100 Subject: [PATCH 3/4] add changeset, revert some code --- .changeset/nice-trains-punch.md | 5 ++++ plugins/pagerduty/src/api/client.ts | 2 +- .../components/Incident/IncidentListItem.tsx | 27 +++++++------------ 3 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 .changeset/nice-trains-punch.md diff --git a/.changeset/nice-trains-punch.md b/.changeset/nice-trains-punch.md new file mode 100644 index 0000000000..a8698eff41 --- /dev/null +++ b/.changeset/nice-trains-punch.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-pagerduty': patch +--- + +Modifies queries diff --git a/plugins/pagerduty/src/api/client.ts b/plugins/pagerduty/src/api/client.ts index 34bba1b7b3..d1220f715f 100644 --- a/plugins/pagerduty/src/api/client.ts +++ b/plugins/pagerduty/src/api/client.ts @@ -66,7 +66,7 @@ export class PagerDutyClient implements PagerDutyApi { } async getOnCallByPolicyId(policyId: string): Promise { - const params = `time_zone=UTC&include[]=users&escalation_policy_ids[]=${policyId}&include[]=escalation_level`; + const params = `time_zone=UTC&include[]=users&escalation_policy_ids[]=${policyId}`; const url = `${await this.config.discoveryApi.getBaseUrl( 'proxy', )}/pagerduty/oncalls?${params}`; diff --git a/plugins/pagerduty/src/components/Incident/IncidentListItem.tsx b/plugins/pagerduty/src/components/Incident/IncidentListItem.tsx index c0143fa591..860623dcd4 100644 --- a/plugins/pagerduty/src/components/Incident/IncidentListItem.tsx +++ b/plugins/pagerduty/src/components/Incident/IncidentListItem.tsx @@ -25,7 +25,6 @@ import { IconButton, Link, Typography, - Grid, } from '@material-ui/core'; import { StatusError, StatusWarning } from '@backstage/core'; import { formatDistanceToNowStrict } from 'date-fns'; @@ -77,22 +76,16 @@ export const IncidentListItem = ({ incident }: Props) => { className: classes.listItemPrimary, }} secondary={ - - - - Created {createdAt} ago and assigned to{' '} - - - - - {user?.summary ?? 'nobody'} - - - + + Created {createdAt} ago and assigned to{' '} + + {user?.summary ?? 'nobody'} + + } /> From 90b25c83892a87dd6a7e1d6b4fa35c2c9dad4366 Mon Sep 17 00:00:00 2001 From: samiramkr Date: Mon, 14 Dec 2020 15:50:24 +0100 Subject: [PATCH 4/4] Update nice-trains-punch.md --- .changeset/nice-trains-punch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/nice-trains-punch.md b/.changeset/nice-trains-punch.md index a8698eff41..71225ac97c 100644 --- a/.changeset/nice-trains-punch.md +++ b/.changeset/nice-trains-punch.md @@ -2,4 +2,4 @@ '@backstage/plugin-pagerduty': patch --- -Modifies queries +Supporting Timezones