Skip to content

Commit 7ef3a72

Browse files
committed
Updates to new Org Members route
1 parent c982edb commit 7ef3a72

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

src/plus/gk/models/organization.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ export enum OrganizationType {
2929

3030
export type OrganizationConnection = Record<string, unknown>;
3131

32+
export type OrganizationMemberStatus = 'activated' | 'pending';
33+
3234
export interface OrganizationMember {
35+
readonly id: string;
36+
readonly email: string;
37+
readonly name: string;
38+
readonly username: string;
39+
readonly role: OrganizationRole;
40+
readonly status: OrganizationMemberStatus;
41+
}
42+
43+
export interface OrganizationMemberOld {
3344
readonly id: string;
3445
readonly email: string;
3546
readonly name: string;

src/plus/gk/organizationService.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const organizationsCacheExpiration = 24 * 60 * 60 * 1000; // 1 day
2020
export class OrganizationService implements Disposable {
2121
private _disposable: Disposable;
2222
private _organizations: Organization[] | null | undefined;
23-
private _fullOrganizations: Map<FullOrganization['id'], FullOrganization> | undefined;
2423
private _organizationSettings: Map<FullOrganization['id'], OrganizationSettings> | undefined;
24+
private _organizationMembers: Map<Organization['id'], OrganizationMember[]> | undefined;
2525

2626
constructor(
2727
private readonly container: Container,
@@ -147,43 +147,34 @@ export class OrganizationService implements Disposable {
147147
}
148148

149149
@gate()
150-
private async getFullOrganization(
151-
id: string,
152-
options?: { force?: boolean },
153-
): Promise<FullOrganization | undefined> {
154-
if (!this._fullOrganizations?.has(id) || options?.force === true) {
155-
const rsp = await this.connection.fetchGkApi(`organization/${id}`, { method: 'GET' });
150+
async getMembers(id?: string | undefined, options?: { force?: boolean }): Promise<OrganizationMember[]> {
151+
if (id == null) {
152+
id = await this.getActiveOrganizationId();
153+
if (id == null) return [];
154+
}
155+
156+
if (!this._organizationMembers?.has(id) || options?.force === true) {
157+
type MemberResponse = {
158+
members: OrganizationMember[];
159+
};
160+
const rsp = await this.connection.fetchGkApi(`organization/${id}/members`, { method: 'GET' });
156161
if (!rsp.ok) {
157162
Logger.error(
158163
'',
159164
getLogScope(),
160-
`Unable to get organization; status=(${rsp.status}): ${rsp.statusText}`,
165+
`Unable to get organization members; status=(${rsp.status}): ${rsp.statusText}`,
161166
);
162-
return undefined;
167+
return [];
163168
}
164169

165-
const organization = (await rsp.json()) as FullOrganization;
166-
if (this._fullOrganizations == null) {
167-
this._fullOrganizations = new Map();
168-
}
169-
organization.members.sort((a, b) => (a.name ?? a.username).localeCompare(b.name ?? b.username));
170-
this._fullOrganizations.set(id, organization);
171-
}
172-
return this._fullOrganizations.get(id);
173-
}
170+
const members: OrganizationMember[] = ((await rsp.json()) as MemberResponse).members;
171+
sortOrgMembers(members);
174172

175-
@gate()
176-
async getMembers(
177-
organizationId?: string | undefined,
178-
options?: { force?: boolean },
179-
): Promise<OrganizationMember[]> {
180-
if (organizationId == null) {
181-
organizationId = await this.getActiveOrganizationId();
182-
if (organizationId == null) return [];
173+
this._organizationMembers ??= new Map();
174+
this._organizationMembers.set(id, members);
183175
}
184176

185-
const organization = await this.getFullOrganization(organizationId, options);
186-
return organization?.members ?? [];
177+
return this._organizationMembers.get(id) ?? [];
187178
}
188179

189180
async getMemberById(id: string, organizationId: string): Promise<OrganizationMember | undefined> {
@@ -245,3 +236,7 @@ export class OrganizationService implements Disposable {
245236
return this._organizationSettings.get(id);
246237
}
247238
}
239+
240+
function sortOrgMembers(members: OrganizationMember[]): OrganizationMember[] {
241+
return members.sort((a, b) => (a.name ?? a.username).localeCompare(b.name ?? b.username));
242+
}

src/plus/integrations/authentication/configuredIntegrationService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Event } from 'vscode';
2+
import { EventEmitter } from 'vscode';
13
import type { IntegrationId } from '../../../constants.integrations';
24
import { HostingIntegrationId } from '../../../constants.integrations';
35
import type { StoredConfiguredIntegrationDescriptor } from '../../../constants.storage';
@@ -27,6 +29,11 @@ export type ConfiguredIntegrationType = 'cloud' | 'local';
2729
export class ConfiguredIntegrationService {
2830
private _configured?: Map<IntegrationId, ConfiguredIntegrationDescriptor[]>;
2931

32+
private readonly _onDidChangeConfiguredIntegrations = new EventEmitter<void>();
33+
get onDidChangeConfiguredIntegrations(): Event<void> {
34+
return this._onDidChangeConfiguredIntegrations.event;
35+
}
36+
3037
constructor(private readonly container: Container) {}
3138

3239
private get configured(): Map<IntegrationId, ConfiguredIntegrationDescriptor[]> {

0 commit comments

Comments
 (0)