Browse Source

Tracks dimissed trial banner

main
Keith Daulton 2 years ago
parent
commit
2e79705450
4 changed files with 47 additions and 24 deletions
  1. +20
    -9
      src/plus/webviews/graph/graphWebview.ts
  2. +5
    -1
      src/plus/webviews/graph/protocol.ts
  3. +12
    -9
      src/webviews/apps/plus/graph/GraphWrapper.tsx
  4. +10
    -5
      src/webviews/apps/plus/graph/graph.tsx

+ 20
- 9
src/plus/webviews/graph/graphWebview.ts View File

@ -26,14 +26,14 @@ import { onIpc } from '../../../webviews/protocol';
import { WebviewBase } from '../../../webviews/webviewBase'; import { WebviewBase } from '../../../webviews/webviewBase';
import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService'; import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService';
import { ensurePlusFeaturesEnabled } from '../../subscription/utils'; import { ensurePlusFeaturesEnabled } from '../../subscription/utils';
import type { GraphCompositeConfig, GraphRepository, State } from './protocol';
import type { DismissBannerParams, GraphCompositeConfig, GraphRepository, State } from './protocol';
import { import {
DidChangeCommitsNotificationType, DidChangeCommitsNotificationType,
DidChangeGraphConfigurationNotificationType, DidChangeGraphConfigurationNotificationType,
DidChangeNotificationType, DidChangeNotificationType,
DidChangeSelectionNotificationType, DidChangeSelectionNotificationType,
DidChangeSubscriptionNotificationType, DidChangeSubscriptionNotificationType,
DismissPreviewCommandType,
DismissBannerCommandType,
GetMoreCommitsCommandType, GetMoreCommitsCommandType,
UpdateColumnCommandType, UpdateColumnCommandType,
UpdateSelectedRepositoryCommandType, UpdateSelectedRepositoryCommandType,
@ -90,6 +90,7 @@ export class GraphWebview extends WebviewBase {
private _theme: ColorTheme | undefined; private _theme: ColorTheme | undefined;
private previewBanner?: boolean; private previewBanner?: boolean;
private trialBanner?: boolean;
constructor(container: Container) { constructor(container: Container) {
super( super(
@ -176,8 +177,8 @@ export class GraphWebview extends WebviewBase {
protected override onMessageReceived(e: IpcMessage) { protected override onMessageReceived(e: IpcMessage) {
switch (e.method) { switch (e.method) {
case DismissPreviewCommandType.method:
onIpc(DismissPreviewCommandType, e, () => this.dismissPreview());
case DismissBannerCommandType.method:
onIpc(DismissBannerCommandType, e, params => this.dismissBanner(params.key));
break; break;
case GetMoreCommitsCommandType.method: case GetMoreCommitsCommandType.method:
onIpc(GetMoreCommitsCommandType, e, params => this.onGetMoreCommits(params.limit)); onIpc(GetMoreCommitsCommandType, e, params => this.onGetMoreCommits(params.limit));
@ -286,11 +287,15 @@ export class GraphWebview extends WebviewBase {
this.updateState(); this.updateState();
} }
private dismissPreview() {
this.previewBanner = false;
private dismissBanner(key: DismissBannerParams['key']) {
if (key === 'preview') {
this.previewBanner = false;
} else if (key === 'trial') {
this.trialBanner = false;
}
let banners = this.container.storage.getWorkspace('graph:banners:dismissed'); let banners = this.container.storage.getWorkspace('graph:banners:dismissed');
banners = updateRecordValue(banners, 'preview', true);
banners = updateRecordValue(banners, key, true);
void this.container.storage.storeWorkspace('graph:banners:dismissed', banners); void this.container.storage.storeWorkspace('graph:banners:dismissed', banners);
} }
@ -436,9 +441,14 @@ export class GraphWebview extends WebviewBase {
private async getState(): Promise<State> { private async getState(): Promise<State> {
if (this.container.git.repositoryCount === 0) return { repositories: [] }; if (this.container.git.repositoryCount === 0) return { repositories: [] };
if (this.previewBanner == null) {
if (this.previewBanner == null || this.trialBanner == null) {
const banners = this.container.storage.getWorkspace('graph:banners:dismissed'); const banners = this.container.storage.getWorkspace('graph:banners:dismissed');
this.previewBanner = !banners?.['preview'];
if (this.previewBanner == null) {
this.previewBanner = !banners?.['preview'];
}
if (this.trialBanner == null) {
this.trialBanner = !banners?.['trial'];
}
} }
if (this.repository == null) { if (this.repository == null) {
@ -476,6 +486,7 @@ export class GraphWebview extends WebviewBase {
return { return {
previewBanner: this.previewBanner, previewBanner: this.previewBanner,
trialBanner: this.trialBanner,
repositories: formatRepositories(this.container.git.openRepositories), repositories: formatRepositories(this.container.git.openRepositories),
selectedRepository: this.repository.path, selectedRepository: this.repository.path,
selectedSha: this._selectedSha, selectedSha: this._selectedSha,

+ 5
- 1
src/plus/webviews/graph/protocol.ts View File

@ -17,6 +17,7 @@ export interface State {
config?: GraphCompositeConfig; config?: GraphCompositeConfig;
nonce?: string; nonce?: string;
previewBanner?: boolean; previewBanner?: boolean;
trialBanner?: boolean;
// Props below are computed in the webview (not passed) // Props below are computed in the webview (not passed)
mixedColumnColors?: Record<string, string>; mixedColumnColors?: Record<string, string>;
@ -63,7 +64,10 @@ export interface CommitListCallback {
} }
// Commands // Commands
export const DismissPreviewCommandType = new IpcCommandType<undefined>('graph/dismissPreview');
export interface DismissBannerParams {
key: 'preview' | 'trial';
}
export const DismissBannerCommandType = new IpcCommandType<DismissBannerParams>('graph/dismissBanner');
export interface GetMoreCommitsParams { export interface GetMoreCommitsParams {
limit?: number; limit?: number;

+ 12
- 9
src/webviews/apps/plus/graph/GraphWrapper.tsx View File

@ -12,6 +12,7 @@ import { RepositoryVisibility } from '../../../../git/gitProvider';
import type { GitGraphRowType } from '../../../../git/models/graph'; import type { GitGraphRowType } from '../../../../git/models/graph';
import type { import type {
CommitListCallback, CommitListCallback,
DismissBannerParams,
GraphCompositeConfig, GraphCompositeConfig,
GraphRepository, GraphRepository,
State, State,
@ -26,7 +27,7 @@ export interface GraphWrapperProps extends State {
onSelectRepository?: (repository: GraphRepository) => void; onSelectRepository?: (repository: GraphRepository) => void;
onColumnChange?: (name: string, settings: GraphColumnConfig) => void; onColumnChange?: (name: string, settings: GraphColumnConfig) => void;
onMoreCommits?: (limit?: number) => void; onMoreCommits?: (limit?: number) => void;
onDismissPreview?: () => void;
onDismissBanner?: (key: DismissBannerParams['key']) => void;
onSelectionChange?: (selection: { id: string; type: GitGraphRowType }[]) => void; onSelectionChange?: (selection: { id: string; type: GitGraphRowType }[]) => void;
} }
@ -132,7 +133,8 @@ export function GraphWrapper({
nonce, nonce,
mixedColumnColors, mixedColumnColors,
previewBanner = true, previewBanner = true,
onDismissPreview,
trialBanner = true,
onDismissBanner,
}: GraphWrapperProps) { }: GraphWrapperProps) {
const [graphList, setGraphList] = useState(rows); const [graphList, setGraphList] = useState(rows);
const [reposList, setReposList] = useState(repositories); const [reposList, setReposList] = useState(repositories);
@ -152,7 +154,7 @@ export function GraphWrapper({
// banner // banner
const [showPreview, setShowPreview] = useState(previewBanner); const [showPreview, setShowPreview] = useState(previewBanner);
// account // account
const [showAccount, setShowAccount] = useState(true);
const [showAccount, setShowAccount] = useState(trialBanner);
const [isAllowed, setIsAllowed] = useState(allowed ?? false); const [isAllowed, setIsAllowed] = useState(allowed ?? false);
const [isPrivateRepo, setIsPrivateRepo] = useState(selectedVisibility === RepositoryVisibility.Private); const [isPrivateRepo, setIsPrivateRepo] = useState(selectedVisibility === RepositoryVisibility.Private);
const [subscriptionSnapshot, setSubscriptionSnapshot] = useState<Subscription | undefined>(subscription); const [subscriptionSnapshot, setSubscriptionSnapshot] = useState<Subscription | undefined>(subscription);
@ -230,11 +232,12 @@ export function GraphWrapper({
const handleDismissPreview = () => { const handleDismissPreview = () => {
setShowPreview(false); setShowPreview(false);
onDismissPreview?.();
onDismissBanner?.('preview');
}; };
const handleDismissAccount = () => { const handleDismissAccount = () => {
setShowAccount(false); setShowAccount(false);
onDismissBanner?.('trial');
}; };
const renderAlertContent = () => { const renderAlertContent = () => {
@ -303,13 +306,13 @@ export function GraphWrapper({
<p className="alert__message"> <p className="alert__message">
Upgrade your account to use the Commit Graph and other GitLens+ features on private repos. Upgrade your account to use the Commit Graph and other GitLens+ features on private repos.
</p> </p>
<p>
<a className="alert-action" href="command:gitlens.plus.purchase">
Upgrade Your Account
</a>
</p>
</> </>
); );
actions = (
<a className="alert-action" href="command:gitlens.plus.purchase">
Upgrade Your Account
</a>
);
break; break;
case SubscriptionState.VerificationRequired: case SubscriptionState.VerificationRequired:
icon = 'unverified'; icon = 'unverified';

+ 10
- 5
src/webviews/apps/plus/graph/graph.tsx View File

@ -4,14 +4,19 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom'; import { render, unmountComponentAtNode } from 'react-dom';
import type { GitGraphRowType } from 'src/git/models/graph'; import type { GitGraphRowType } from 'src/git/models/graph';
import type { GraphColumnConfig } from '../../../../config'; import type { GraphColumnConfig } from '../../../../config';
import type { CommitListCallback, GraphRepository, State } from '../../../../plus/webviews/graph/protocol';
import type {
CommitListCallback,
DismissBannerParams,
GraphRepository,
State,
} from '../../../../plus/webviews/graph/protocol';
import { import {
DidChangeCommitsNotificationType, DidChangeCommitsNotificationType,
DidChangeGraphConfigurationNotificationType, DidChangeGraphConfigurationNotificationType,
DidChangeNotificationType, DidChangeNotificationType,
DidChangeSelectionNotificationType, DidChangeSelectionNotificationType,
DidChangeSubscriptionNotificationType, DidChangeSubscriptionNotificationType,
DismissPreviewCommandType,
DismissBannerCommandType,
GetMoreCommitsCommandType, GetMoreCommitsCommandType,
UpdateColumnCommandType, UpdateColumnCommandType,
UpdateSelectedRepositoryCommandType as UpdateRepositorySelectionCommandType, UpdateSelectedRepositoryCommandType as UpdateRepositorySelectionCommandType,
@ -68,7 +73,7 @@ export class GraphApp extends App {
(selection: { id: string; type: GitGraphRowType }[]) => this.onSelectionChanged(selection), (selection: { id: string; type: GitGraphRowType }[]) => this.onSelectionChanged(selection),
250, 250,
)} )}
onDismissPreview={() => this.onDismissPreview()}
onDismissBanner={key => this.onDismissBanner(key)}
{...this.state} {...this.state}
/>, />,
$root, $root,
@ -218,8 +223,8 @@ export class GraphApp extends App {
return mixedGraphColors; return mixedGraphColors;
} }
private onDismissPreview() {
this.sendCommand(DismissPreviewCommandType, undefined);
private onDismissBanner(key: DismissBannerParams['key']) {
this.sendCommand(DismissBannerCommandType, { key: key });
} }
private onColumnChanged(name: string, settings: GraphColumnConfig) { private onColumnChanged(name: string, settings: GraphColumnConfig) {

Loading…
Cancel
Save