Skip to content

Commit bf964cf

Browse files
eamodioaxosoft-ramint
authored andcommitted
Adds <gl-promo> element & refactors promo handling
1 parent b843c41 commit bf964cf

File tree

12 files changed

+151
-168
lines changed

12 files changed

+151
-168
lines changed

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17493,18 +17493,23 @@
1749317493
},
1749417494
{
1749517495
"view": "gitlens.views.worktrees",
17496-
"contents": "[Upgrade to Pro](command:gitlens.plus.upgrade?%7B%22source%22%3A%22worktrees%22%7D)\n\nYour Pro trial has ended. Please upgrade for full access to Worktrees and other Pro features.",
17496+
"contents": "[Upgrade to Pro](command:gitlens.plus.upgrade?%7B%22source%22%3A%22worktrees%22%7D)",
1749717497
"when": "gitlens:plus:required && gitlens:plus:state == 4"
1749817498
},
1749917499
{
1750017500
"view": "gitlens.views.worktrees",
17501-
"contents": "Special: 1st seat of Pro is now 50%+ off.",
17501+
"contents": "Special: 1st seat of Pro is now 50%+ off",
1750217502
"when": "gitlens:plus:required && gitlens:plus:state == 4 && (gitlens:promo == pro50 || !gitlens:promo)"
1750317503
},
1750417504
{
1750517505
"view": "gitlens.views.worktrees",
17506-
"contents": "Sale: Save up to 80% on GitLens Pro - lowest price of the year!",
17507-
"when": "gitlens:plus:required && gitlens:plus:state == 4 && gitlens:promo == devex-days"
17506+
"contents": "DevEx Days 24 Sale: Save up to 80% on GitLens Pro - lowest price of the year!",
17507+
"when": "gitlens:plus:required && gitlens:plus:state == 4 && gitlens:promo == devexdays24"
17508+
},
17509+
{
17510+
"view": "gitlens.views.worktrees",
17511+
"contents": "Your Pro trial has ended. Please upgrade for full access to Worktrees and other Pro features.",
17512+
"when": "gitlens:plus:required && gitlens:plus:state == 4"
1750817513
},
1750917514
{
1751017515
"view": "gitlens.views.worktrees",

src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ export type ContextKeys = {
703703
'gitlens:plus:required': boolean;
704704
'gitlens:plus:state': SubscriptionState;
705705
'gitlens:prerelease': boolean;
706-
'gitlens:promo': string;
706+
'gitlens:promo': PromoKeys;
707707
'gitlens:readonly': boolean;
708708
'gitlens:repos:withRemotes': string[];
709709
'gitlens:repos:withHostingIntegrations': string[];
@@ -840,6 +840,8 @@ export const keys = [
840840
] as const;
841841
export type Keys = (typeof keys)[number];
842842

843+
export type PromoKeys = 'devexdays24' | 'pro50';
844+
843845
export const enum Schemes {
844846
DebugConsole = 'debug',
845847
File = 'file',

src/plus/gk/account/promos.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1+
import type { PromoKeys } from '../../../constants';
12
import { SubscriptionState } from './subscription';
23

34
export interface Promo {
4-
readonly key: string;
5+
readonly key: PromoKeys;
6+
readonly code?: string;
57
readonly states?: SubscriptionState[];
68
readonly expiresOn?: number;
79
readonly startsOn?: number;
810

9-
readonly code?: string;
10-
readonly title?: string;
11-
readonly description?: string;
12-
readonly descriptionCTA?: string;
13-
readonly descriptionIntro?: string;
14-
readonly url?: string;
15-
readonly command?: string;
11+
readonly command?: `command:${string}`;
12+
readonly linkTooltip?: string;
1613
}
1714

1815
// Must be ordered by applicable order
1916
const promos: Promo[] = [
2017
{
21-
key: 'devex-days',
22-
expiresOn: new Date('2024-09-05T06:59:00.000Z').getTime(),
18+
key: 'devexdays24',
19+
code: 'DEVEXDAYS24',
2320
states: [
2421
SubscriptionState.FreePlusInTrial,
2522
SubscriptionState.FreePlusTrialExpired,
2623
SubscriptionState.FreePlusTrialReactivationEligible,
2724
],
28-
code: 'DEVEXDAYS24',
29-
description: 'Save up to 80% on GitLens Pro - lowest price of the year!',
30-
descriptionIntro: 'Sale',
25+
expiresOn: new Date('2024-09-05T06:59:00.000Z').getTime(),
26+
linkTooltip: 'Sale: Save up to 80% on GitLens Pro - lowest price of the year!',
3127
},
32-
3328
{
3429
key: 'pro50',
3530
states: [
@@ -39,12 +34,13 @@ const promos: Promo[] = [
3934
SubscriptionState.FreePlusTrialExpired,
4035
SubscriptionState.FreePlusTrialReactivationEligible,
4136
],
42-
description: '1st seat of Pro is now 50%+ off.',
43-
descriptionCTA: 'See your special price.',
37+
linkTooltip: 'Special: 1st seat of Pro is now 50%+ off. See your special price.',
4438
},
4539
];
4640

47-
export function getApplicablePromo(state: number): Promo | undefined {
41+
export function getApplicablePromo(state: number | undefined): Promo | undefined {
42+
if (state == null) return undefined;
43+
4844
const now = Date.now();
4945
for (const promo of promos) {
5046
if (

src/webviews/apps/home/home.html

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@
2222
data-vscode-context='{ "webview": "#{webviewId}", "webviewInstance": "#{webviewInstanceId}" }'
2323
>
2424
<div class="home__nav">
25-
<div class="promo-banner promo-banner--eyebrow" id="promo-pro50" hidden>
26-
<a
27-
class="promo-banner__link"
28-
href="command:gitlens.plus.upgrade"
29-
title="Special: 1st seat of Pro is now 50%+ off. See your special price."
30-
>Special: 1st seat of Pro is now 50%+ off. See your special price.</a
31-
>
32-
</div>
33-
<div class="promo-banner promo-banner--eyebrow" id="promo-devex-days" hidden>
34-
<a
35-
class="promo-banner__link"
36-
href="command:gitlens.plus.upgrade"
37-
title="Sale: Save up to 80% on GitLens Pro - lowest price of the year!"
38-
><gl-devex-days-svg></gl-devex-days-svg>Sale: Save up to 80% on GitLens Pro - lowest price of the
39-
year!</a
40-
>
41-
</div>
25+
<gl-promo class="promo-banner promo-banner--eyebrow" id="promo" type="link"></gl-promo>
4226
<nav class="inline-nav" id="links" aria-label="Help and Resources">
4327
<div class="inline-nav__group">
4428
<gl-tooltip hoist>
@@ -156,25 +140,6 @@ <h1 class="alert__title">Untrusted workspace</h1>
156140
<p data-requires="norepo">
157141
<code-icon icon="question"></code-icon> Features which need a repository are currently unavailable
158142
</p>
159-
<div class="promo-banner" id="promo-hs2023" hidden>
160-
<a
161-
class="promo-banner__link"
162-
href="https://gitkraken.com/hs23?utm_source=holiday_special&utm_medium=gitlens_banner&utm_campaign=holiday_special_2023"
163-
aria-label="Holiday Special: 1st seat of Pro (plus the entire GitKraken DevEx platform) is now 50%+ off. Includes all Pro versions: GitLens, GitKraken Client, CLI, Browser Extension & more! See your special price."
164-
>
165-
<img
166-
class="promo-banner__media is-dark"
167-
src="#{webroot}/media/holiday-2023-small-dark.webp"
168-
alt=""
169-
/>
170-
<img
171-
class="promo-banner__media is-light"
172-
src="#{webroot}/media/holiday-2023-small-light.webp"
173-
alt=""
174-
/><br />
175-
1st seat of Pro (plus the entire GitKraken DevEx platform) is now 50%+ off. See your special price.
176-
</a>
177-
</div>
178143
<div id="section-walkthrough" data-section-expand="walkthrough" class="alert">
179144
<h1 class="alert__title">Get Started with GitLens</h1>
180145
<div class="alert__description">

src/webviews/apps/home/home.scss

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,6 @@ ul {
112112
color: var(--color-foreground--50);
113113
margin-bottom: 0.2rem;
114114
}
115-
116-
&__link {
117-
display: inline-block;
118-
font-size: 1.1rem;
119-
font-weight: bold;
120-
color: inherit;
121-
text-align: center;
122-
text-decoration: none;
123-
124-
&:hover {
125-
color: inherit;
126-
text-decoration: underline;
127-
}
128-
}
129-
130-
&--eyebrow &__link {
131-
display: block;
132-
white-space: nowrap;
133-
font-weight: normal;
134-
max-width: 100%;
135-
text-overflow: ellipsis;
136-
overflow: hidden;
137-
}
138-
139-
&__media {
140-
// width: 100%;
141-
max-width: 9.9rem;
142-
height: auto;
143-
144-
&.is-light {
145-
display: var(--promo-banner-light-display, none);
146-
}
147-
148-
&.is-dark {
149-
display: var(--promo-banner-dark-display, none);
150-
}
151-
}
152115
}
153116

154117
.home {

src/webviews/apps/home/home.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*global*/
22
import './home.scss';
33
import type { Disposable } from 'vscode';
4+
import { getApplicablePromo } from '../../../plus/gk/account/promos';
45
import type { State } from '../../home/protocol';
56
import {
67
CollapseSectionCommand,
@@ -13,12 +14,13 @@ import type { IpcMessage } from '../../protocol';
1314
import { ExecuteCommand } from '../../protocol';
1415
import { App } from '../shared/appBase';
1516
import type { GlFeatureBadge } from '../shared/components/feature-badge';
17+
import type { GlPromo } from '../shared/components/promo';
1618
import { DOM } from '../shared/dom';
1719
import '../shared/components/button';
1820
import '../shared/components/code-icon';
1921
import '../shared/components/feature-badge';
2022
import '../shared/components/overlays/tooltip';
21-
import '../shared/components/svg-devExDays';
23+
import '../shared/components/promo';
2224

2325
export class HomeApp extends App<State> {
2426
constructor() {
@@ -64,7 +66,6 @@ export class HomeApp extends App<State> {
6466
break;
6567

6668
case DidChangeSubscription.is(msg):
67-
this.state.promoKey = msg.params.promoKey;
6869
this.state.subscription = msg.params.subscription;
6970
this.setState(this.state);
7071
this.updatePromos();
@@ -153,11 +154,10 @@ export class HomeApp extends App<State> {
153154
}
154155

155156
private updatePromos() {
156-
const { promoKey } = this.state;
157+
const promo = getApplicablePromo(this.state.subscription.state);
157158

158-
setElementVisibility('promo-hs2023', promoKey === 'hs2023');
159-
setElementVisibility('promo-pro50', promoKey === 'pro50');
160-
setElementVisibility('promo-devex-days', promoKey === 'devex-days');
159+
const $promo = document.getElementById('promo') as GlPromo;
160+
$promo.promo = promo;
161161
}
162162

163163
private updateOrgSettings() {

src/webviews/apps/plus/account/components/account-content.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { css, html, LitElement, nothing } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { when } from 'lit/directives/when.js';
44
import { urls } from '../../../../../constants';
5+
import type { Promo } from '../../../../../plus/gk/account/promos';
56
import { getApplicablePromo } from '../../../../../plus/gk/account/promos';
67
import type { Subscription } from '../../../../../plus/gk/account/subscription';
78
import {
@@ -16,7 +17,7 @@ import { elementBase, linkBase } from '../../../shared/components/styles/lit/bas
1617
import '../../../shared/components/button';
1718
import '../../../shared/components/button-container';
1819
import '../../../shared/components/code-icon';
19-
import '../../../shared/components/svg-devExDays';
20+
import '../../../shared/components/promo';
2021

2122
@customElement('account-content')
2223
export class AccountContent extends LitElement {
@@ -247,7 +248,7 @@ export class AccountContent extends LitElement {
247248
}
248249

249250
private renderAccountState() {
250-
const promo = this.state ? getApplicablePromo(this.state) : undefined;
251+
const promo = getApplicablePromo(this.state);
251252

252253
switch (this.state) {
253254
case SubscriptionState.Paid:
@@ -302,13 +303,7 @@ export class AccountContent extends LitElement {
302303
<button-container>
303304
<gl-button full href="command:gitlens.plus.upgrade">Upgrade to Pro</gl-button>
304305
</button-container>
305-
${promo?.description
306-
? html`<p class="special ${promo.key === 'pro50' ? 'special-dim' : ''}">
307-
${promo.key === 'devex-days' ? html`<gl-devex-days-svg></gl-devex-days-svg>` : nothing}
308-
${promo.descriptionIntro ?? 'Special'}: <b>${promo.description}</b><br />
309-
</p>`
310-
: nothing}
311-
${this.renderIncludesDevEx()}
306+
${this.renderPromo(promo)} ${this.renderIncludesDevEx()}
312307
`;
313308
}
314309

@@ -318,13 +313,7 @@ export class AccountContent extends LitElement {
318313
<button-container>
319314
<gl-button full href="command:gitlens.plus.upgrade">Upgrade to Pro</gl-button>
320315
</button-container>
321-
${promo?.description
322-
? html`<p class="special ${promo.key === 'pro50' ? 'special-dim' : ''}">
323-
${promo.key === 'devex-days' ? html`<gl-devex-days-svg></gl-devex-days-svg>` : nothing}
324-
${promo.descriptionIntro ?? 'Special'}: <b>${promo.description}</b><br />
325-
</p>`
326-
: nothing}
327-
${this.renderIncludesDevEx()}
316+
${this.renderPromo(promo)} ${this.renderIncludesDevEx()}
328317
`;
329318

330319
case SubscriptionState.FreePlusTrialReactivationEligible:
@@ -361,4 +350,8 @@ export class AccountContent extends LitElement {
361350
</p>
362351
`;
363352
}
353+
354+
private renderPromo(promo: Promo | undefined) {
355+
return html`<gl-promo .promo=${promo}></gl-promo>`;
356+
}
364357
}

src/webviews/apps/plus/shared/components/feature-gate-plus-state.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { css, html, LitElement, nothing } from 'lit';
22
import { customElement, property, query } from 'lit/decorators.js';
33
import type { Source } from '../../../../../constants';
44
import { Commands } from '../../../../../constants';
5+
import type { Promo } from '../../../../../plus/gk/account/promos';
56
import { getApplicablePromo } from '../../../../../plus/gk/account/promos';
67
import { SubscriptionState } from '../../../../../plus/gk/account/subscription';
78
import type { GlButton } from '../../../shared/components/button';
89
import { linkStyles } from './vscode.css';
910
import '../../../shared/components/button';
10-
import '../../../shared/components/svg-devExDays';
11+
import '../../../shared/components/promo';
1112

1213
declare global {
1314
interface HTMLElementTagNameMap {
@@ -61,15 +62,6 @@ export class GlFeatureGatePlusState extends LitElement {
6162
.hint {
6263
border-bottom: 1px dashed currentColor;
6364
}
64-
65-
.special {
66-
text-align: center;
67-
}
68-
69-
:host([appearance='welcome']) .special-dim {
70-
font-size: smaller;
71-
opacity: 0.6;
72-
}
7365
`,
7466
];
7567

@@ -165,17 +157,12 @@ export class GlFeatureGatePlusState extends LitElement {
165157
href="${generateCommandLink(Commands.PlusUpgrade, this.source)}"
166158
>Upgrade to Pro</gl-button
167159
>
160+
${this.renderPromo(promo)}
168161
<p>
169162
Your Pro trial has ended. Please upgrade for full access to
170163
${this.featureWithArticleIfNeeded ? `${this.featureWithArticleIfNeeded} and other ` : ''}Pro
171164
features.
172-
</p>
173-
${promo?.description
174-
? html`<p class="special ${promo.key === 'pro50' ? 'special-dim' : ''}">
175-
${promo.key === 'devex-days' ? html`<gl-devex-days-svg></gl-devex-days-svg>` : nothing}
176-
${promo.descriptionIntro ?? 'Special'}: <b>${promo.description}</b><br />
177-
</p>`
178-
: nothing}`;
165+
</p>`;
179166

180167
case SubscriptionState.FreePlusTrialReactivationEligible:
181168
return html`
@@ -194,6 +181,10 @@ export class GlFeatureGatePlusState extends LitElement {
194181

195182
return undefined;
196183
}
184+
185+
private renderPromo(promo: Promo | undefined) {
186+
return html`<gl-promo .promo=${promo}></gl-promo>`;
187+
}
197188
}
198189

199190
function generateCommandLink(command: Commands, source: Source | undefined) {

0 commit comments

Comments
 (0)