Skip to content

Commit 92c5e3b

Browse files
committed
Improves promo metadata
1 parent b5d4338 commit 92c5e3b

File tree

9 files changed

+44
-29
lines changed

9 files changed

+44
-29
lines changed

src/commands/quickCommand.steps.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,20 +2634,8 @@ export async function* ensureAccessStep<
26342634
} else {
26352635
if (access.subscription.required == null) return access;
26362636

2637-
let detail;
2638-
const promo = getApplicablePromo(access.subscription.current.state);
2639-
if (promo != null) {
2640-
// NOTE: Don't add a default case, so that if we add a new promo the build will break without handling it
2641-
switch (promo.key) {
2642-
case 'pro50':
2643-
detail = '$(star-full) Limited-Time Sale: Save 33% or more on your 1st seat of Pro';
2644-
break;
2645-
case 'launchpad':
2646-
case 'launchpad-extended':
2647-
detail = `$(rocket) Launchpad Sale: Save 75% or more on GitLens Pro`;
2648-
break;
2649-
}
2650-
}
2637+
const promo = getApplicablePromo(access.subscription.current.state, 'gate');
2638+
const detail = promo?.quickpick.detail;
26512639

26522640
placeholder = 'Pro feature — requires a trial or paid plan for use on privately-hosted repos';
26532641
if (isSubscriptionPaidPlan(access.subscription.required) && access.subscription.current.account != null) {

src/git/gitProviderService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ export class GitProviderService implements Disposable {
779779

780780
if (feature === 'launchpad') {
781781
// If our launchpad graduation promo is active allow access for everyone
782-
if (getApplicablePromo(subscription.state, 'launchpad')) {
782+
if (getApplicablePromo(subscription.state, undefined, 'launchpad')) {
783783
return { allowed: true, subscription: { current: subscription } };
784784
}
785785
return { allowed: false, subscription: { current: subscription, required: SubscriptionPlanId.Pro } };

src/plus/gk/account/promos.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import type { PromoKeys } from '../../../constants.subscription';
22
import { SubscriptionState } from '../../../constants.subscription';
33

4+
export type PromoLocation = 'account' | 'badge' | 'gate' | 'home';
5+
46
export interface Promo {
57
readonly key: PromoKeys;
68
readonly code?: string;
79
readonly states?: SubscriptionState[];
810
readonly expiresOn?: number;
911
readonly startsOn?: number;
1012

11-
readonly command?: `command:${string}`;
12-
readonly commandTooltip?: string;
13+
readonly command?: {
14+
command?: `command:${string}`;
15+
tooltip: string;
16+
};
17+
readonly locations?: PromoLocation[];
18+
readonly quickpick: { detail: string };
1319
}
1420

1521
// Must be ordered by applicable order
@@ -26,7 +32,10 @@ const promos: Promo[] = [
2632
SubscriptionState.ProTrialReactivationEligible,
2733
],
2834
expiresOn: new Date('2024-09-27T06:59:00.000Z').getTime(),
29-
commandTooltip: 'Launchpad Sale: Save 75% or more on GitLens Pro',
35+
command: { tooltip: 'Launchpad Sale: Save 75% or more on GitLens Pro' },
36+
quickpick: {
37+
detail: '$(rocket) Launchpad Sale: Save 75% or more on GitLens Pro',
38+
},
3039
},
3140
{
3241
key: 'launchpad-extended',
@@ -41,7 +50,10 @@ const promos: Promo[] = [
4150
],
4251
startsOn: new Date('2024-09-27T06:59:00.000Z').getTime(),
4352
expiresOn: new Date('2024-10-14T06:59:00.000Z').getTime(),
44-
commandTooltip: 'Launchpad Sale: Save 75% or more on GitLens Pro',
53+
command: { tooltip: 'Launchpad Sale: Save 75% or more on GitLens Pro' },
54+
quickpick: {
55+
detail: '$(rocket) Launchpad Sale: Save 75% or more on GitLens Pro',
56+
},
4557
},
4658
{
4759
key: 'pro50',
@@ -53,15 +65,28 @@ const promos: Promo[] = [
5365
SubscriptionState.ProTrialExpired,
5466
SubscriptionState.ProTrialReactivationEligible,
5567
],
56-
commandTooltip: 'Limited-Time Sale: Save 33% or more on your 1st seat of Pro. See your special price',
68+
command: { tooltip: 'Limited-Time Sale: Save 33% or more on your 1st seat of Pro. See your special price' },
69+
quickpick: {
70+
detail: '$(star-full) Limited-Time Sale: Save 33% or more on your 1st seat of Pro',
71+
},
5772
},
5873
];
5974

60-
export function getApplicablePromo(state: number | undefined, key?: PromoKeys): Promo | undefined {
75+
export function getApplicablePromo(
76+
state: number | undefined,
77+
location?: PromoLocation,
78+
key?: PromoKeys,
79+
): Promo | undefined {
6180
if (state == null) return undefined;
6281

6382
for (const promo of promos) {
64-
if ((key == null || key === promo.key) && isPromoApplicable(promo, state)) return promo;
83+
if ((key == null || key === promo.key) && isPromoApplicable(promo, state)) {
84+
if (location == null || promo.locations == null || promo.locations.includes(location)) {
85+
return promo;
86+
}
87+
88+
break;
89+
}
6590
}
6691

6792
return undefined;

src/plus/launchpad/launchpad.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ export class LaunchpadCommand extends QuickCommand<State> {
266266
const result = yield* ensureAccessStep(state, context, PlusFeatures.Launchpad);
267267
if (result === StepResultBreak) continue;
268268

269-
context.showGraduationPromo = getApplicablePromo(result.subscription.current.state, 'launchpad') != null;
269+
context.showGraduationPromo =
270+
getApplicablePromo(result.subscription.current.state, undefined, 'launchpad') != null;
270271

271272
await updateContextItems(this.container, context, { force: newlyConnected });
272273

src/webviews/apps/home/components/home-nav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class GlHomeNav extends LitElement {
3030
override render() {
3131
return html`
3232
<gl-promo
33-
.promo=${getApplicablePromo(this._state.subscription.state)}
33+
.promo=${getApplicablePromo(this._state.subscription.state, 'home')}
3434
class="promo-banner promo-banner--eyebrow"
3535
id="promo"
3636
type="link"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class GlFeatureGatePlusState extends LitElement {
9595

9696
this.hidden = false;
9797
const appearance = (this.appearance ?? 'alert') === 'alert' ? 'alert' : nothing;
98-
const promo = this.state ? getApplicablePromo(this.state) : undefined;
98+
const promo = this.state ? getApplicablePromo(this.state, 'gate') : undefined;
9999

100100
switch (this.state) {
101101
case SubscriptionState.VerificationRequired:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export class GLHomeAccountContent extends LitElement {
280280
}
281281

282282
private renderAccountState() {
283-
const promo = getApplicablePromo(this.state);
283+
const promo = getApplicablePromo(this.state, 'account');
284284

285285
switch (this.state) {
286286
case SubscriptionState.Paid:

src/webviews/apps/shared/components/feature-badge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class GlFeatureBadge extends LitElement {
263263

264264
case SubscriptionState.ProTrialExpired:
265265
content = html`<p>
266-
Your Pro trial as ended. You can now only use Pro features on publicly-hosted repos.
266+
Your Pro trial has ended. You can now only use Pro features on publicly-hosted repos.
267267
</p>
268268
${this.renderUpgradeActions(html`<p>Please upgrade for full access to Pro features:</p>`)}`;
269269
break;
@@ -329,7 +329,7 @@ export class GlFeatureBadge extends LitElement {
329329
}
330330

331331
private renderUpgradeActions(leadin?: TemplateResult) {
332-
const promo = getApplicablePromo(this.state);
332+
const promo = getApplicablePromo(this.state, 'badge');
333333

334334
return html`<div class="actions">
335335
${leadin ?? nothing}

src/webviews/apps/shared/components/promo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { css, html, LitElement, nothing } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
3+
import { ifDefined } from 'lit/directives/if-defined.js';
34
import type { Promo } from '../../../../plus/gk/account/promos';
45

56
@customElement('gl-promo')
@@ -67,7 +68,7 @@ export class GlPromo extends LitElement {
6768
return html`<a
6869
class="link"
6970
href="${this.promo.command ?? 'command:gitlens.plus.upgrade'}"
70-
title="${this.promo.commandTooltip}"
71+
title="${ifDefined(this.promo.command?.tooltip)}"
7172
>${promoHtml}</a
7273
>`;
7374
}

0 commit comments

Comments
 (0)