Skip to content

Commit

Permalink
fix(TDC-7452/Tour): Fix tour is changing to first step when closing (#…
Browse files Browse the repository at this point in the history
…5311)

* fix(TDC-7452/Tour): Fix tour is changing to first step when closing

* Update packages/components/src/AppGuidedTour/AppGuidedTour.component.js

Co-authored-by: Alexandre Amalric <119614409+aamalric-talend@users.noreply.github.com>

---------

Co-authored-by: Alexandre Amalric <119614409+aamalric-talend@users.noreply.github.com>
  • Loading branch information
hbhong and aamalric-talend committed May 20, 2024
1 parent 3d14e99 commit 003c7a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-apes-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talend/react-components": patch
---

fix(TDC-7452/Tour): Fix tour is changing to first step when closing
18 changes: 11 additions & 7 deletions packages/components/src/AppGuidedTour/AppGuidedTour.component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import useLocalStorage from 'react-use/lib/useLocalStorage';

import PropTypes from 'prop-types';

import I18N_DOMAIN_COMPONENTS from '../constants';
import GuidedTour from '../GuidedTour';
import Toggle from '../Toggle';
import Stepper from '../Stepper';
import I18N_DOMAIN_COMPONENTS from '../constants';
import Toggle from '../Toggle';
import DemoContentStep from './DemoContentStep.component';

const DEMO_CONTENT_STEP_ID = 1;
Expand Down Expand Up @@ -73,8 +75,10 @@ function AppGuidedTour({
onRequestClose={() => {
onRequestClose();
setIsAlreadyViewed(true);
setCurrentStep(0);
setImportDemoContent(false);
if (importDemoContent) {
setImportDemoContent(false);
setCurrentStep(Math.max(0, currentStep - 1));
}
}}
steps={[
{
Expand Down
17 changes: 17 additions & 0 deletions packages/components/src/AppGuidedTour/AppGuidedTour.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,21 @@ describe('AppGuidedTour', () => {
);
expect(screen.queryByText('Import demo content')).not.toBeInTheDocument();
});
it('Should stay on the last page when finished', async () => {
const user = userEvent.setup();
const steps = [
{
content: {
header: 'Header',
body: () => 'Last page',
},
},
];
render(<AppGuidedTour {...DEFAULT_PROPS} steps={steps} demoContentSteps={null} />);
expect(screen.queryByText(/Last page/i)).not.toBeInTheDocument();
const nextBtn = document.querySelector('button[data-tour-elem="right-arrow"]');
await user.click(nextBtn);
await user.click(screen.getByText('Let me try'));
expect(screen.queryByText(/Last page/i)).toBeInTheDocument();
});
});

0 comments on commit 003c7a4

Please sign in to comment.