Skip to content

Commit

Permalink
Tracks dimissed trial banner
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed Aug 29, 2022
1 parent a271c2b commit 2e79705
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
29 changes: 20 additions & 9 deletions src/plus/webviews/graph/graphWebview.ts
Expand Up @@ -26,14 +26,14 @@ import { onIpc } from '../../../webviews/protocol';
import { WebviewBase } from '../../../webviews/webviewBase';
import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService';
import { ensurePlusFeaturesEnabled } from '../../subscription/utils';
import type { GraphCompositeConfig, GraphRepository, State } from './protocol';
import type { DismissBannerParams, GraphCompositeConfig, GraphRepository, State } from './protocol';
import {
DidChangeCommitsNotificationType,
DidChangeGraphConfigurationNotificationType,
DidChangeNotificationType,
DidChangeSelectionNotificationType,
DidChangeSubscriptionNotificationType,
DismissPreviewCommandType,
DismissBannerCommandType,
GetMoreCommitsCommandType,
UpdateColumnCommandType,
UpdateSelectedRepositoryCommandType,
Expand Down Expand Up @@ -90,6 +90,7 @@ export class GraphWebview extends WebviewBase<State> {
private _theme: ColorTheme | undefined;

private previewBanner?: boolean;
private trialBanner?: boolean;

constructor(container: Container) {
super(
Expand Down Expand Up @@ -176,8 +177,8 @@ export class GraphWebview extends WebviewBase<State> {

protected override onMessageReceived(e: IpcMessage) {
switch (e.method) {
case DismissPreviewCommandType.method:
onIpc(DismissPreviewCommandType, e, () => this.dismissPreview());
case DismissBannerCommandType.method:
onIpc(DismissBannerCommandType, e, params => this.dismissBanner(params.key));
break;
case GetMoreCommitsCommandType.method:
onIpc(GetMoreCommitsCommandType, e, params => this.onGetMoreCommits(params.limit));
Expand Down Expand Up @@ -286,11 +287,15 @@ export class GraphWebview extends WebviewBase<State> {
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');
banners = updateRecordValue(banners, 'preview', true);
banners = updateRecordValue(banners, key, true);
void this.container.storage.storeWorkspace('graph:banners:dismissed', banners);
}

Expand Down Expand Up @@ -436,9 +441,14 @@ export class GraphWebview extends WebviewBase<State> {
private async getState(): Promise<State> {
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');
this.previewBanner = !banners?.['preview'];
if (this.previewBanner == null) {
this.previewBanner = !banners?.['preview'];
}
if (this.trialBanner == null) {
this.trialBanner = !banners?.['trial'];
}
}

if (this.repository == null) {
Expand Down Expand Up @@ -476,6 +486,7 @@ export class GraphWebview extends WebviewBase<State> {

return {
previewBanner: this.previewBanner,
trialBanner: this.trialBanner,
repositories: formatRepositories(this.container.git.openRepositories),
selectedRepository: this.repository.path,
selectedSha: this._selectedSha,
Expand Down
6 changes: 5 additions & 1 deletion src/plus/webviews/graph/protocol.ts
Expand Up @@ -17,6 +17,7 @@ export interface State {
config?: GraphCompositeConfig;
nonce?: string;
previewBanner?: boolean;
trialBanner?: boolean;

// Props below are computed in the webview (not passed)
mixedColumnColors?: Record<string, string>;
Expand Down Expand Up @@ -63,7 +64,10 @@ export interface CommitListCallback {
}

// 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 {
limit?: number;
Expand Down
21 changes: 12 additions & 9 deletions src/webviews/apps/plus/graph/GraphWrapper.tsx
Expand Up @@ -12,6 +12,7 @@ import { RepositoryVisibility } from '../../../../git/gitProvider';
import type { GitGraphRowType } from '../../../../git/models/graph';
import type {
CommitListCallback,
DismissBannerParams,
GraphCompositeConfig,
GraphRepository,
State,
Expand All @@ -26,7 +27,7 @@ export interface GraphWrapperProps extends State {
onSelectRepository?: (repository: GraphRepository) => void;
onColumnChange?: (name: string, settings: GraphColumnConfig) => void;
onMoreCommits?: (limit?: number) => void;
onDismissPreview?: () => void;
onDismissBanner?: (key: DismissBannerParams['key']) => void;
onSelectionChange?: (selection: { id: string; type: GitGraphRowType }[]) => void;
}

Expand Down Expand Up @@ -132,7 +133,8 @@ export function GraphWrapper({
nonce,
mixedColumnColors,
previewBanner = true,
onDismissPreview,
trialBanner = true,
onDismissBanner,
}: GraphWrapperProps) {
const [graphList, setGraphList] = useState(rows);
const [reposList, setReposList] = useState(repositories);
Expand All @@ -152,7 +154,7 @@ export function GraphWrapper({
// banner
const [showPreview, setShowPreview] = useState(previewBanner);
// account
const [showAccount, setShowAccount] = useState(true);
const [showAccount, setShowAccount] = useState(trialBanner);
const [isAllowed, setIsAllowed] = useState(allowed ?? false);
const [isPrivateRepo, setIsPrivateRepo] = useState(selectedVisibility === RepositoryVisibility.Private);
const [subscriptionSnapshot, setSubscriptionSnapshot] = useState<Subscription | undefined>(subscription);
Expand Down Expand Up @@ -230,11 +232,12 @@ export function GraphWrapper({

const handleDismissPreview = () => {
setShowPreview(false);
onDismissPreview?.();
onDismissBanner?.('preview');
};

const handleDismissAccount = () => {
setShowAccount(false);
onDismissBanner?.('trial');
};

const renderAlertContent = () => {
Expand Down Expand Up @@ -303,13 +306,13 @@ export function GraphWrapper({
<p className="alert__message">
Upgrade your account to use the Commit Graph and other GitLens+ features on private repos.
</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;
case SubscriptionState.VerificationRequired:
icon = 'unverified';
Expand Down
15 changes: 10 additions & 5 deletions src/webviews/apps/plus/graph/graph.tsx
Expand Up @@ -4,14 +4,19 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import type { GitGraphRowType } from 'src/git/models/graph';
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 {
DidChangeCommitsNotificationType,
DidChangeGraphConfigurationNotificationType,
DidChangeNotificationType,
DidChangeSelectionNotificationType,
DidChangeSubscriptionNotificationType,
DismissPreviewCommandType,
DismissBannerCommandType,
GetMoreCommitsCommandType,
UpdateColumnCommandType,
UpdateSelectedRepositoryCommandType as UpdateRepositorySelectionCommandType,
Expand Down Expand Up @@ -68,7 +73,7 @@ export class GraphApp extends App<State> {
(selection: { id: string; type: GitGraphRowType }[]) => this.onSelectionChanged(selection),
250,
)}
onDismissPreview={() => this.onDismissPreview()}
onDismissBanner={key => this.onDismissBanner(key)}
{...this.state}
/>,
$root,
Expand Down Expand Up @@ -218,8 +223,8 @@ export class GraphApp extends App<State> {
return mixedGraphColors;
}

private onDismissPreview() {
this.sendCommand(DismissPreviewCommandType, undefined);
private onDismissBanner(key: DismissBannerParams['key']) {
this.sendCommand(DismissBannerCommandType, { key: key });
}

private onColumnChanged(name: string, settings: GraphColumnConfig) {
Expand Down

0 comments on commit 2e79705

Please sign in to comment.