Merge pull request #10479 from alexrybch/gcalendar-list-fix

gcalendar plugin calendar list fix
This commit is contained in:
Fredrik Adelöw
2022-03-29 10:06:27 +02:00
committed by GitHub
7 changed files with 37 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-gcalendar': minor
---
Fixed issue when not all calendars were fetched for some accounts
+1
View File
@@ -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
+6 -3
View File
@@ -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<gapi.client.calendar.CalendarList>;
// (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)
+2 -2
View File
@@ -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<GCalendarList>(
'/calendar/v3/users/me/calendarList',
params,
);
+2
View File
@@ -17,6 +17,8 @@
/// <reference types="gapi.auth2" />
/// <reference types="gapi.client.calendar" />
export type GCalendarList = gapi.client.calendar.CalendarList;
export type GCalendar = gapi.client.calendar.CalendarListEntry;
export type EventAttendee = gapi.client.calendar.EventAttendee;
@@ -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(
@@ -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,