Skip to content

Commit

Permalink
fix(onboarding): wizard become visible -> don't close common hint
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-wave committed Jul 12, 2024
1 parent 611e10a commit 72399e1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
30 changes: 30 additions & 0 deletions src/plugins/promo-presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,33 @@ describe('promo preset', function () {
});
});
});

it('open wizard -> close promo hint', async function () {
const options = getOptionsWithPromo();
options.plugins = [new PromoPresetsPlugin()];
const controller = new Controller(options);

await controller.stepElementReached({
stepSlug: 'showCoolFeature',
element: getAnchorElement(),
});

await controller.setWizardState('visible');

expect(controller.hintStore.state.open).toBe(false);
});

it('open wizard -> NOT close common hint', async function () {
const options = getOptionsWithPromo();
options.plugins = [new PromoPresetsPlugin()];
const controller = new Controller(options);

await controller.stepElementReached({
stepSlug: 'openBoard',
element: getAnchorElement(),
});

await controller.setWizardState('visible');

expect(controller.hintStore.state.open).toBe(true);
});
39 changes: 31 additions & 8 deletions src/plugins/promo-presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ export class PromoPresetsPlugin implements OnboardingPlugin {
onboarding.events.subscribe('beforeShowHint', this.onHintShow);

onboarding.events.subscribe('beforeSuggestPreset', this.onSuggestPreset);

onboarding.events.subscribe('wizardStateChanged', this.onWizardStateChanged);
};

onHintShow = ({stepData}: EventsMap['beforeShowHint']) => {
if (!this.onboardingInstance) {
return true;
}

const preset = this.onboardingInstance.options.config.presets[stepData.preset];

const {wizardState} = this.onboardingInstance.state.base;

const isPromoPreset = preset?.type !== 'internal' && preset?.visibility === 'alwaysHidden';
const isPromoPreset = this.checkIsPromoPreset(stepData.preset);

const isGuideVisible = wizardState === 'visible' || wizardState === 'collapsed';

Expand Down Expand Up @@ -66,13 +66,36 @@ export class PromoPresetsPlugin implements OnboardingPlugin {
return;
}

const preset = this.onboardingInstance.options.config.presets[presetSlug];

const isPromoPreset = preset?.type !== 'internal' && preset?.visibility === 'alwaysHidden';

if (isPromoPreset) {
if (this.checkIsPromoPreset(presetSlug)) {
this.onboardingInstance.state.base.enabled = true;
this.onboardingInstance.emitStateChange();
}
};

onWizardStateChanged = async ({wizardState}: EventsMap['wizardStateChanged']) => {
if (!this.onboardingInstance) {
return;
}

if (wizardState === 'visible') {
const isHintOpen = this.onboardingInstance.hintStore.state.open;
const isPromoPreset = this.checkIsPromoPreset(
this.onboardingInstance.hintStore.state.hint?.preset,
);

if (isHintOpen && isPromoPreset) {
this.onboardingInstance.closeHint();
}
}
};

private checkIsPromoPreset = (presetSlug: string) => {
if (!this.onboardingInstance) {
return false;
}

const preset = this.onboardingInstance.options.config.presets[presetSlug];

return preset?.type !== 'internal' && preset?.visibility === 'alwaysHidden';
};
}
15 changes: 0 additions & 15 deletions src/plugins/wizard-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ describe('open wizard', function () {

expect(options.getProgressState).toHaveBeenCalled();
});

it('become visible -> close hint', async function () {
const options = getOptions({wizardState: 'hidden'});
options.plugins = [new WizardPlugin()];
const controller = new Controller(options);

await controller.stepElementReached({
stepSlug: 'createSprint',
element: getAnchorElement(),
});

await controller.setWizardState('visible');

expect(controller.hintStore.state.open).toBe(false);
});
});

describe('close wizard', function () {
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/wizard-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class WizardPlugin implements OnboardingPlugin {
return;
}

if (wizardState === 'visible') {
await this.onboardingInstance.closeHint();
}

if (wizardState === 'visible' || wizardState === 'collapsed') {
await this.onboardingInstance.ensureRunning();
}
Expand Down

0 comments on commit 72399e1

Please sign in to comment.