Skip to content

Commit 300cf96

Browse files
committed
Improves integrations connected check in Inspect view
1 parent a9f83a4 commit 300cf96

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/webviews/commitDetails/commitDetailsWebview.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { ExplainStashCommandArgs } from '../../commands/explainStash';
1111
import type { ExplainWipCommandArgs } from '../../commands/explainWip';
1212
import type { OpenPullRequestOnRemoteCommandArgs } from '../../commands/openPullRequestOnRemote';
1313
import type { ContextKeys } from '../../constants.context';
14+
import { isSupportedCloudIntegrationId } from '../../constants.integrations';
1415
import type { InspectTelemetryContext, Sources } from '../../constants.telemetry';
1516
import type { Container } from '../../container';
1617
import type { CommitSelectedEvent } from '../../eventBus';
@@ -47,7 +48,7 @@ import { confirmDraftStorage } from '../../plus/drafts/utils/-webview/drafts.uti
4748
import type { Subscription } from '../../plus/gk/models/subscription';
4849
import type { SubscriptionChangeEvent } from '../../plus/gk/subscriptionService';
4950
import { ensureAccount } from '../../plus/gk/utils/-webview/acount.utils';
50-
import type { ConnectionStateChangeEvent } from '../../plus/integrations/integrationService';
51+
import type { ConfiguredIntegrationsChangeEvent } from '../../plus/integrations/authentication/configuredIntegrationService';
5152
import { supportsCodeSuggest } from '../../plus/integrations/providers/models';
5253
import { getEntityIdentifierInput } from '../../plus/integrations/providers/utils';
5354
import {
@@ -213,7 +214,7 @@ export class CommitDetailsWebviewProvider
213214
configuration.onDidChangeAny(this.onAnyConfigurationChanged, this),
214215
onDidChangeContext(this.onContextChanged, this),
215216
this.container.subscription.onDidChange(this.onSubscriptionChanged, this),
216-
container.integrations.onDidChangeConnectionState(this.onIntegrationConnectionStateChanged, this),
217+
container.integrations.onDidChangeConfiguredIntegrations(this.onIntegrationsChanged, this),
217218
);
218219
}
219220

@@ -913,20 +914,27 @@ export class CommitDetailsWebviewProvider
913914
return this._context.hasAccount;
914915
}
915916

916-
private async onIntegrationConnectionStateChanged(e: ConnectionStateChangeEvent) {
917-
const isConnected = e.reason === 'connected';
918-
if (this._context.hasIntegrationsConnected === isConnected) return;
917+
private async onIntegrationsChanged(_e: ConfiguredIntegrationsChangeEvent) {
918+
const previous = this._context.hasIntegrationsConnected;
919+
const current = await this.getHasIntegrationsConnected(true);
920+
if (previous === current) return;
919921

920922
void this.host.notify(DidChangeIntegrationsNotification, {
921-
hasIntegrationsConnected: await this.getHasIntegrationsConnected(true),
923+
hasIntegrationsConnected: current,
922924
});
923925
}
924926

925927
async getHasIntegrationsConnected(force = false): Promise<boolean> {
926-
if (this._context.hasIntegrationsConnected != null && !force) return this._context.hasIntegrationsConnected;
927-
928-
const hasAny = (await this.container.integrations.getConfigured()).length > 0;
929-
this._context.hasIntegrationsConnected = hasAny;
928+
if (force || this._context.hasIntegrationsConnected == null) {
929+
const configured = await this.container.integrations.getConfigured();
930+
if (configured.length > 0) {
931+
this._context.hasIntegrationsConnected = configured.some(i =>
932+
isSupportedCloudIntegrationId(i.integrationId),
933+
);
934+
} else {
935+
this._context.hasIntegrationsConnected = false;
936+
}
937+
}
930938

931939
return this._context.hasIntegrationsConnected;
932940
}

0 commit comments

Comments
 (0)