From 5665be5db7fe572ff91ee1d480a38ca67d453b28 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 31 May 2023 18:38:16 -0400 Subject: [PATCH] Adopts feature gate component in Focus view --- src/plus/webviews/focus/focusWebview.ts | 56 ++---- src/plus/webviews/focus/protocol.ts | 28 +-- src/webviews/apps/plus/focus/focus.html | 295 ++++++++++++++------------------ src/webviews/apps/plus/focus/focus.scss | 20 +++ src/webviews/apps/plus/focus/focus.ts | 96 +++-------- 5 files changed, 190 insertions(+), 305 deletions(-) diff --git a/src/plus/webviews/focus/focusWebview.ts b/src/plus/webviews/focus/focusWebview.ts index e791f7a..77bf8d8 100644 --- a/src/plus/webviews/focus/focusWebview.ts +++ b/src/plus/webviews/focus/focusWebview.ts @@ -22,8 +22,6 @@ import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/m import { getWorktreeForBranch } from '../../../git/models/worktree'; import { parseGitRemoteUrl } from '../../../git/parsers/remoteParser'; import type { RichRemoteProvider } from '../../../git/remotes/richRemoteProvider'; -import type { Subscription } from '../../../subscription'; -import { SubscriptionState } from '../../../subscription'; import { executeCommand, registerCommand } from '../../../system/command'; import { setContext } from '../../../system/context'; import type { IpcMessage } from '../../../webviews/protocol'; @@ -31,12 +29,7 @@ import { onIpc } from '../../../webviews/protocol'; import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController'; import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService'; import type { OpenWorktreeParams, State, SwitchToBranchParams } from './protocol'; -import { - DidChangeStateNotificationType, - DidChangeSubscriptionNotificationType, - OpenWorktreeCommandType, - SwitchToBranchCommandType, -} from './protocol'; +import { DidChangeNotificationType, OpenWorktreeCommandType, SwitchToBranchCommandType } from './protocol'; interface RepoWithRichRemote { repo: Repository; @@ -226,44 +219,19 @@ export class FocusWebviewProvider implements WebviewProvider { }); } - private async onSubscriptionChanged(e: SubscriptionChangeEvent) { + private onSubscriptionChanged(e: SubscriptionChangeEvent) { if (e.etag === this._etagSubscription) return; this._etagSubscription = e.etag; - - const access = await this.container.git.access(PlusFeatures.Focus); - const { subscription, isPlus } = await this.getSubscription(access.subscription.current); - if (isPlus) { - void this.notifyDidChangeState(); - } - return this.host.notify(DidChangeSubscriptionNotificationType, { - subscription: subscription, - isPlus: isPlus, - }); - } - - private async getSubscription(subscription?: Subscription) { - const currentSubscription = subscription ?? (await this.container.subscription.getSubscription(true)); - const isPlus = ![ - SubscriptionState.Free, - SubscriptionState.FreePreviewTrialExpired, - SubscriptionState.FreePlusTrialExpired, - SubscriptionState.VerificationRequired, - ].includes(currentSubscription.state); - - return { - subscription: currentSubscription, - isPlus: isPlus, - }; + void this.notifyDidChangeState(); } private async getState(deferState = false): Promise { - const { subscription, isPlus } = await this.getSubscription(); - if (!isPlus) { + const access = await this.container.git.access(PlusFeatures.Focus); + if (access.allowed !== true) { return { timestamp: Date.now(), - isPlus: isPlus, - subscription: subscription, + access: access, }; } @@ -275,8 +243,7 @@ export class FocusWebviewProvider implements WebviewProvider { if (deferState || !hasConnectedRepos) { return { timestamp: Date.now(), - isPlus: isPlus, - subscription: subscription, + access: access, repos: (hasConnectedRepos ? connectedRepos : githubRepos).map(r => serializeRepoWithRichRemote(r)), }; } @@ -299,8 +266,7 @@ export class FocusWebviewProvider implements WebviewProvider { return { timestamp: Date.now(), - isPlus: isPlus, - subscription: subscription, + access: access, pullRequests: serializedPrs, issues: serializedIssues, repos: connectedRepos.map(r => serializeRepoWithRichRemote(r)), @@ -310,7 +276,7 @@ export class FocusWebviewProvider implements WebviewProvider { async includeBootstrap(): Promise { if (this._bootstrapping) { const state = await this.getState(true); - if (state.isPlus) { + if (state.access.allowed === true) { void this.notifyDidChangeState(); } return state; @@ -460,11 +426,11 @@ export class FocusWebviewProvider implements WebviewProvider { } private async notifyDidChangeState() { - if (!this.host.visible) return; + // if (!this.host.visible) return; const state = await this.getState(); this._bootstrapping = false; - void this.host.notify(DidChangeStateNotificationType, { state: state }); + void this.host.notify(DidChangeNotificationType, { state: state }); } } diff --git a/src/plus/webviews/focus/protocol.ts b/src/plus/webviews/focus/protocol.ts index 48c5e2a..db7e0ab 100644 --- a/src/plus/webviews/focus/protocol.ts +++ b/src/plus/webviews/focus/protocol.ts @@ -1,18 +1,16 @@ +import type { FeatureAccess } from '../../../features'; import type { IssueShape } from '../../../git/models/issue'; import type { PullRequestShape } from '../../../git/models/pullRequest'; -import type { Subscription } from '../../../subscription'; import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol'; -export type State = { +export interface State { timestamp: number; - isPlus: boolean; - subscription: Subscription; + access: FeatureAccess; pullRequests?: PullRequestResult[]; issues?: IssueResult[]; repos?: RepoWithRichProvider[]; - [key: string]: unknown; -}; +} export interface SearchResultBase { reasons: string[]; @@ -41,30 +39,16 @@ export interface RepoWithRichProvider { export interface OpenWorktreeParams { pullRequest: PullRequestShape; } - export const OpenWorktreeCommandType = new IpcCommandType('focus/pr/openWorktree'); export interface SwitchToBranchParams { pullRequest: PullRequestShape; } - export const SwitchToBranchCommandType = new IpcCommandType('focus/pr/switchToBranch'); // Notifications -export interface DidChangeStateNotificationParams { +export interface DidChangeParams { state: State; } - -export const DidChangeStateNotificationType = new IpcNotificationType( - 'focus/state/didChange', - true, -); - -export interface DidChangeSubscriptionParams { - subscription: Subscription; - isPlus: boolean; -} -export const DidChangeSubscriptionNotificationType = new IpcNotificationType( - 'graph/subscription/didChange', -); +export const DidChangeNotificationType = new IpcNotificationType('focus/didChange', true); diff --git a/src/webviews/apps/plus/focus/focus.html b/src/webviews/apps/plus/focus/focus.html index a8264ec..a0f9919 100644 --- a/src/webviews/apps/plus/focus/focus.html +++ b/src/webviews/apps/plus/focus/focus.html @@ -4,178 +4,143 @@ - - + +

+ Helps you focus on what's important by providing you with a comprehensive list of all your pull requests + and issues on your GitHub repos. +

+ +

No GitHub remotes are connected

+

+ This enables access to Pull Requests and Issues in the Focus View as well as provide additional + information inside hovers and the Commit Details view, such as auto-linked issues and pull requests and + avatars. +

+ Connect to GitHub +
+
+ -
-
-
-
-
-

My Pull Requests

- -
-
- - - - - - - Pull Request - - - - - - - - - - - - - - -
- Loading + + + + + + + + + + + + + +
+ Loading +
+
+ No pull requests found +
-
- No pull requests found -
-
-
-
-
-

My Issues

- -
-
- - - - - - - - - Title - - - - - - - - - - - - - -
- Loading -
- -
-
-
-
- - - - - #{endOfBody}