Skip to content

Commit

Permalink
[Console]: incorrect position of console tour #198389 (#198636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruby-rc authored Nov 18, 2024
1 parent eddfe5b commit 81919c3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/plugins/console/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { MAJOR_VERSION } from './plugin';
export { MAJOR_VERSION, WELCOME_TOUR_DELAY } from './plugin';
export { API_BASE_PATH, KIBANA_API_PREFIX } from './api';
export { DEFAULT_VARIABLES } from './variables';
export {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/console/common/constants/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
*/

export const MAJOR_VERSION = '8.0.0';

export const WELCOME_TOUR_DELAY = 250;
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React, { ReactNode, ReactElement } from 'react';
import React, { ReactNode, ReactElement, useState, useEffect } from 'react';
import { EuiTourStep, PopoverAnchorPosition } from '@elastic/eui';
import { WELCOME_TOUR_DELAY } from '../../../common/constants';

export interface ConsoleTourStepProps {
step: number;
Expand Down Expand Up @@ -44,11 +45,31 @@ export const ConsoleTourStep = ({ tourStepProps, children }: Props) => {
css,
} = tourStepProps;

const [popoverVisible, setPopoverVisible] = useState(false);

useEffect(() => {
let timeoutId: any;

if (isStepOpen) {
timeoutId = setTimeout(() => {
setPopoverVisible(true);
}, WELCOME_TOUR_DELAY);
} else {
setPopoverVisible(false);
}

return () => {
if (timeoutId) {
clearTimeout(timeoutId);
}
};
}, [isStepOpen]);

return (
<EuiTourStep
step={step}
stepsTotal={stepsTotal}
isStepOpen={isStepOpen}
isStepOpen={popoverVisible}
title={title}
content={content}
onFinish={onFinish}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

import React, { useCallback, useEffect, useState, useRef } from 'react';
import { debounce } from 'lodash';
import { EuiResizableButton, useEuiTheme, keys, EuiThemeComputed } from '@elastic/eui';
import { WELCOME_TOUR_DELAY } from '../../../../common/constants';

const CONSOLE_MIN_HEIGHT = 200;

Expand Down Expand Up @@ -61,6 +63,21 @@ export const EmbeddedConsoleResizeButton = ({
const initialConsoleHeight = useRef(consoleHeight);
const initialMouseY = useRef(0);

// When the height changes, simulate a window resize to prompt
// the current onboarding tour step to adjust its layouts
useEffect(() => {
const debouncedResize = debounce(() => {
window.dispatchEvent(new Event('resize'));
}, WELCOME_TOUR_DELAY);

debouncedResize();

// Cleanup the debounce instance on unmount or dependency change
return () => {
debouncedResize.cancel();
};
}, [consoleHeight]);

useEffect(() => {
function handleResize() {
const newMaxConsoleHeight = getCurrentConsoleMaxSize(euiTheme);
Expand Down
26 changes: 22 additions & 4 deletions test/functional/apps/console/_onboarding_tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

// The euiTour shows with a small delay, so with 1s we should be safe
const DELAY_FOR = 1000;

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const browser = getService('browser');
Expand Down Expand Up @@ -40,22 +43,30 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await isTourStepOpen('filesTourStep')).to.be(false);
};

const waitUntilFinishedLoading = async () => {
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.sleep(DELAY_FOR);
};

it('displays all five steps in the tour', async () => {
const andWaitFor = DELAY_FOR;
await waitUntilFinishedLoading();

log.debug('on Shell tour step');
expect(await isTourStepOpen('shellTourStep')).to.be(true);
await PageObjects.console.clickNextTourStep();
await PageObjects.console.clickNextTourStep(andWaitFor);

log.debug('on Editor tour step');
expect(await isTourStepOpen('editorTourStep')).to.be(true);
await PageObjects.console.clickNextTourStep();
await PageObjects.console.clickNextTourStep(andWaitFor);

log.debug('on History tour step');
expect(await isTourStepOpen('historyTourStep')).to.be(true);
await PageObjects.console.clickNextTourStep();
await PageObjects.console.clickNextTourStep(andWaitFor);

log.debug('on Config tour step');
expect(await isTourStepOpen('configTourStep')).to.be(true);
await PageObjects.console.clickNextTourStep();
await PageObjects.console.clickNextTourStep(andWaitFor);

log.debug('on Files tour step');
expect(await isTourStepOpen('filesTourStep')).to.be(true);
Expand All @@ -73,10 +84,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// Tour should reset after clearing local storage
await browser.clearLocalStorage();
await browser.refresh();

await waitUntilFinishedLoading();
expect(await isTourStepOpen('shellTourStep')).to.be(true);
});

it('skipping the tour hides the tour steps', async () => {
await waitUntilFinishedLoading();

expect(await isTourStepOpen('shellTourStep')).to.be(true);
expect(await testSubjects.exists('consoleSkipTourButton')).to.be(true);
await PageObjects.console.clickSkipTour();
Expand All @@ -90,6 +105,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('allows re-running the tour', async () => {
await waitUntilFinishedLoading();

await PageObjects.console.skipTourIfExists();

// Verify that tour is hiddern
Expand All @@ -100,6 +117,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.console.clickRerunTour();

// Verify that first tour step is visible
await waitUntilFinishedLoading();
expect(await isTourStepOpen('shellTourStep')).to.be(true);
});
});
Expand Down
6 changes: 5 additions & 1 deletion test/functional/page_objects/console_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,12 @@ export class ConsolePageObject extends FtrService {
await this.testSubjects.click('consoleSkipTourButton');
}

public async clickNextTourStep() {
public async clickNextTourStep(andWaitFor: number = 0) {
await this.testSubjects.click('consoleNextTourStepButton');

if (andWaitFor) {
await this.common.sleep(andWaitFor);
}
}

public async clickCompleteTour() {
Expand Down

0 comments on commit 81919c3

Please sign in to comment.