From c6616e6fc9e7fb4e72c497c83d6aaf96b9f48eff Mon Sep 17 00:00:00 2001 From: Alex Rybchenko Date: Mon, 28 Mar 2022 15:06:19 +0200 Subject: [PATCH 1/4] Fixed issue when not all calendars were fetched for some accounts Signed-off-by: Alex Rybchenko --- .changeset/tasty-goats-shout.md | 5 +++++ plugins/gcalendar/src/api/client.ts | 4 ++-- plugins/gcalendar/src/api/types.ts | 2 ++ .../components/CalendarCard/CalendarCard.tsx | 10 +++++----- .../gcalendar/src/hooks/useCalendarsQuery.ts | 20 +++++++++++++++---- 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 .changeset/tasty-goats-shout.md diff --git a/.changeset/tasty-goats-shout.md b/.changeset/tasty-goats-shout.md new file mode 100644 index 0000000000..617485bead --- /dev/null +++ b/.changeset/tasty-goats-shout.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-gcalendar': patch +--- + +Fixed issue when not all calendars were fetched for some accounts diff --git a/plugins/gcalendar/src/api/client.ts b/plugins/gcalendar/src/api/client.ts index 5b6ea96339..084c302636 100644 --- a/plugins/gcalendar/src/api/client.ts +++ b/plugins/gcalendar/src/api/client.ts @@ -15,7 +15,7 @@ */ import { OAuthApi, createApiRef, FetchApi } from '@backstage/core-plugin-api'; -import { GCalendar, GCalendarEvent } from './types'; +import { GCalendarEvent, GCalendarList } from './types'; import { ResponseError } from '@backstage/errors'; type Options = { @@ -58,7 +58,7 @@ export class GCalendarApiClient { } public async getCalendars(params?: any) { - return this.get<{ items: GCalendar[] }>( + return this.get( '/calendar/v3/users/me/calendarList', params, ); diff --git a/plugins/gcalendar/src/api/types.ts b/plugins/gcalendar/src/api/types.ts index 1423b91aca..b6d9a36eb9 100644 --- a/plugins/gcalendar/src/api/types.ts +++ b/plugins/gcalendar/src/api/types.ts @@ -17,6 +17,8 @@ /// /// +export type GCalendarList = gapi.client.calendar.CalendarList; + export type GCalendar = gapi.client.calendar.CalendarListEntry; export type EventAttendee = gapi.client.calendar.EventAttendee; diff --git a/plugins/gcalendar/src/components/CalendarCard/CalendarCard.tsx b/plugins/gcalendar/src/components/CalendarCard/CalendarCard.tsx index 7b7c02b883..b698c23ea1 100644 --- a/plugins/gcalendar/src/components/CalendarCard/CalendarCard.tsx +++ b/plugins/gcalendar/src/components/CalendarCard/CalendarCard.tsx @@ -15,7 +15,7 @@ */ import { sortBy } from 'lodash'; import { DateTime } from 'luxon'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { InfoCard, Progress } from '@backstage/core-components'; import { useAnalytics } from '@backstage/core-plugin-api'; @@ -51,10 +51,10 @@ export const CalendarCard = () => { signIn(true); }, [signIn]); - const { isLoading: isCalendarLoading, data } = useCalendarsQuery({ - enabled: isSignedIn, - }); - const calendars = useMemo(() => data?.items || [], [data]); + const { isLoading: isCalendarLoading, data: calendars = [] } = + useCalendarsQuery({ + enabled: isSignedIn, + }); const primaryCalendarId = calendars.find(c => c.primary === true)?.id; const defaultSelectedCalendars = primaryCalendarId ? [primaryCalendarId] : []; const [storedCalendars, setStoredCalendars] = useStoredCalendars( diff --git a/plugins/gcalendar/src/hooks/useCalendarsQuery.ts b/plugins/gcalendar/src/hooks/useCalendarsQuery.ts index ed31e23c79..a76142ff09 100644 --- a/plugins/gcalendar/src/hooks/useCalendarsQuery.ts +++ b/plugins/gcalendar/src/hooks/useCalendarsQuery.ts @@ -30,10 +30,22 @@ export const useCalendarsQuery = ({ enabled }: Options) => { return useQuery( ['calendars'], - async () => - calendarApi.getCalendars({ - minAccessRole: 'reader', - }), + async () => { + const calendars = []; + let token = ''; + do { + const { nextPageToken = '', items = [] } = + await calendarApi.getCalendars({ + maxResults: 100, + minAccessRole: 'reader', + pageToken: token, + }); + token = nextPageToken; + calendars.push(...items); + } while (token); + + return calendars; + }, { enabled, keepPreviousData: true, From d5e0531122fccbfacf6b5696844d4e83abc5c7dc Mon Sep 17 00:00:00 2001 From: Alex Rybchenko Date: Mon, 28 Mar 2022 15:07:05 +0200 Subject: [PATCH 2/4] updated gcalendar codeowners Signed-off-by: Alex Rybchenko --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index cfe405b7d3..3665a4952d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -32,6 +32,7 @@ /plugins/explore @backstage/reviewers @backstage/sda-se-reviewers /plugins/explore-react @backstage/reviewers @backstage/sda-se-reviewers /plugins/fossa @backstage/reviewers @backstage/sda-se-reviewers +/plugins/gcalendar @backstage/reviewers @szubster @ptychu @kielosz @alexrybch /plugins/git-release-manager @backstage/reviewers @erikengervall /plugins/home @backstage/reviewers @backstage/techdocs-core /plugins/ilert @backstage/reviewers @yacut From a3ba359d73c0e48f29b0740ce2909f933149373c Mon Sep 17 00:00:00 2001 From: Alex Rybchenko Date: Mon, 28 Mar 2022 17:11:28 +0200 Subject: [PATCH 3/4] updated api report Signed-off-by: Alex Rybchenko --- plugins/gcalendar/api-report.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/gcalendar/api-report.md b/plugins/gcalendar/api-report.md index 276c144400..b4aebf1ff3 100644 --- a/plugins/gcalendar/api-report.md +++ b/plugins/gcalendar/api-report.md @@ -29,9 +29,7 @@ export class GCalendarApiClient { // Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts constructor(options: Options); // (undocumented) - getCalendars(params?: any): Promise<{ - items: GCalendar[]; - }>; + getCalendars(params?: any): Promise; // (undocumented) getEvents( calendarId: string, @@ -55,6 +53,11 @@ export type GCalendarEvent = gapi.client.calendar.Event & calendarId?: string; }; +// Warning: (ae-missing-release-tag) "GCalendarList" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type GCalendarList = gapi.client.calendar.CalendarList; + // Warning: (ae-missing-release-tag) "gcalendarPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) From 686db64cac93058d3a0c54e75533dc0a7a17bdfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 29 Mar 2022 09:53:51 +0200 Subject: [PATCH 4/4] review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/tasty-goats-shout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tasty-goats-shout.md b/.changeset/tasty-goats-shout.md index 617485bead..5b9356122f 100644 --- a/.changeset/tasty-goats-shout.md +++ b/.changeset/tasty-goats-shout.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-gcalendar': patch +'@backstage/plugin-gcalendar': minor --- Fixed issue when not all calendars were fetched for some accounts