Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Add a tour for Document Explorer #131125

Merged
merged 36 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0de46ce
[Discover] Add "Take a tour" button to the Document Explorer callout
jughosta Apr 26, 2022
a130dc6
[Discover] Tmp
jughosta Apr 26, 2022
bce3d08
[Discover] Add a first Document Explorer tour step
jughosta Apr 27, 2022
52effd5
[Discover] Add other Document Explorer tour steps
jughosta Apr 27, 2022
6b4c925
[Discover] Update tour steps positioning
jughosta Apr 27, 2022
9045b72
[Discover] Add gifs to tour steps
jughosta Apr 28, 2022
1de42b9
[Discover] Refactor how tour steps are registered
jughosta May 5, 2022
30e4e82
[Discover] Add new step to the tour. Update tour steps text.
jughosta May 6, 2022
e6dfa0e
[Discover] Improve steps positioning
jughosta May 6, 2022
0a41fa8
[Discover] Fix positioning for Add field step
jughosta May 6, 2022
03d0643
[Discover] Add icons to tour steps
jughosta May 6, 2022
8ef167f
[Discover] Reorganize components
jughosta May 6, 2022
9253ce7
[Discover] Skip Columns step when it's not available
jughosta May 6, 2022
fe9be1a
[Discover] Rename components
jughosta May 9, 2022
31caa7e
[Discover] Add some tests
jughosta May 9, 2022
6887aa3
[Discover] Fix positioning
jughosta May 9, 2022
06692b4
[Discover] Fix props
jughosta May 9, 2022
5f1a6aa
[Discover] Render steps only if the tour is active
jughosta May 10, 2022
579f4c2
[Discover] Update gifs
jughosta May 10, 2022
39a15b8
[Discover] Add image alt text for gifs
jughosta May 10, 2022
c453834
[Discover] Tag the Take tour button
jughosta May 10, 2022
6801bd0
[Discover] Update text and tests
jughosta May 10, 2022
c5e9ec8
[Discover] Add more tests
jughosta May 10, 2022
ac7d329
[Discover] Rename assets directory
jughosta May 10, 2022
c273fa0
[Discover] Fix tour in mobile view. Improve steps positioning and ani…
jughosta May 10, 2022
7ad9033
[Discover] Update text in tour steps
jughosta May 11, 2022
1b5b36f
[Discover] Update sort.gif
jughosta May 12, 2022
d6cd452
[Discover] Update image width
jughosta May 12, 2022
24389ea
Update src/plugins/discover/public/components/discover_tour/discover_…
jughosta May 12, 2022
f91034c
Update src/plugins/discover/public/components/discover_tour/discover_…
jughosta May 12, 2022
a1ab85e
Merge branch 'main' into document-explorer-take-tour
kibanamachine May 12, 2022
5edd1c2
Merge branch 'main' into document-explorer-take-tour
kibanamachine May 12, 2022
ce7d6d5
[Discover] Update sort.gif
jughosta May 13, 2022
7614081
Merge branch 'main' into document-explorer-take-tour
kibanamachine May 16, 2022
85729fb
Merge branch 'main' into document-explorer-take-tour
kibanamachine May 17, 2022
a8eec09
[Discover] Fix code style
jughosta May 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/plugins/discover/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

export const PLUGIN_ID = 'discover';
export const APP_ICON = 'discoverApp';
export const DEFAULT_COLUMNS_SETTING = 'defaultColumns';
export const SAMPLE_SIZE_SETTING = 'discover:sampleSize';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
*/

import React from 'react';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { mountWithIntl, findTestSubject } from '@kbn/test-jest-helpers';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import {
CALLOUT_STATE_KEY,
DocumentExplorerUpdateCallout,
} from './document_explorer_update_callout';
import { LocalStorageMock } from '../../../../__mocks__/local_storage_mock';
import { DiscoverServices } from '../../../../build_services';
import { discoverServiceMock } from '../../../../__mocks__/services';
import { DiscoverTourProvider } from '../../../../components/discover_tour';

const defaultServices = {
addBasePath: () => '',
docLinks: { links: { discover: { documentExplorer: '' } } },
capabilities: { advancedSettings: { save: true } },
...discoverServiceMock,
capabilities: { ...discoverServiceMock.capabilities, advancedSettings: { save: true } },
storage: new LocalStorageMock({ [CALLOUT_STATE_KEY]: false }),
} as unknown as DiscoverServices;

Expand Down Expand Up @@ -57,4 +58,18 @@ describe('Document Explorer Update callout', () => {

expect(result.find('.dscDocumentExplorerCallout').exists()).toBeFalsy();
});

it('should start a tour when the button is clicked', () => {
const result = mountWithIntl(
<KibanaContextProvider services={defaultServices}>
<DiscoverTourProvider>
<DocumentExplorerUpdateCallout />
</DiscoverTourProvider>
</KibanaContextProvider>
);

expect(result.find({ isStepOpen: true })).toHaveLength(0);
findTestSubject(result, 'discoverTakeTourButton').simulate('click');
expect(result.find({ isStepOpen: true })).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
* Side Public License, v 1.
*/

import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useState } from 'react';
import './document_explorer_callout.scss';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import {
EuiButton,
EuiButtonEmpty,
EuiButtonIcon,
EuiCallOut,
EuiFlexGroup,
EuiFlexItem,
EuiLink,
useEuiTheme,
} from '@elastic/eui';
import { css } from '@emotion/react';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { useDiscoverServices } from '../../../../utils/use_discover_services';
import { useDiscoverTourContext } from '../../../../components/discover_tour';

export const CALLOUT_STATE_KEY = 'discover:docExplorerUpdateCalloutClosed';

Expand All @@ -37,22 +36,19 @@ const updateStoredCalloutState = (newState: boolean, storage: Storage) => {
* The callout that's displayed when Document explorer is enabled
*/
export const DocumentExplorerUpdateCallout = () => {
const { euiTheme } = useEuiTheme();
const { storage, capabilities, docLinks } = useDiscoverServices();
const { storage, capabilities } = useDiscoverServices();
const [calloutClosed, setCalloutClosed] = useState(getStoredCalloutState(storage));

const semiBoldStyle = useMemo(
() => css`
font-weight: ${euiTheme.font.weight.semiBold};
`,
[euiTheme.font.weight.semiBold]
);
const onStartTour = useDiscoverTourContext().onStartTour;
kertal marked this conversation as resolved.
Show resolved Hide resolved

const onCloseCallout = useCallback(() => {
updateStoredCalloutState(true, storage);
setCalloutClosed(true);
}, [storage]);

const onTakeTour = useCallback(() => {
onStartTour();
}, [onStartTour]);
kertal marked this conversation as resolved.
Show resolved Hide resolved

if (calloutClosed || !capabilities.advancedSettings.save) {
return null;
}
Expand All @@ -67,44 +63,37 @@ export const DocumentExplorerUpdateCallout = () => {
>
<p>
<FormattedMessage
id="discover.docExplorerUpdateCallout.bodyMessage"
defaultMessage="Perform multi-column sorting, resize columns, set row height, and view data in fullscreen with the {documentExplorer}.
Learn more about the structure of your data with {fieldStatistics}."
values={{
fieldStatistics: (
<EuiLink href={docLinks.links.discover.fieldStatistics} target="_blank">
<span css={semiBoldStyle}>
<FormattedMessage
id="discover.docExplorerUpdateCallout.fieldStatistics"
defaultMessage="field statistics"
/>
</span>
</EuiLink>
),
documentExplorer: (
<EuiLink href={docLinks.links.discover.documentExplorer} target="_blank">
<span css={semiBoldStyle}>
<FormattedMessage
id="discover.docExplorerUpdateCallout.documentExplorer"
defaultMessage="new document table"
/>
</span>
</EuiLink>
),
}}
id="discover.docExplorerUpdateCallout.description"
defaultMessage="Add relevant fields, reorder and sort columns, resize rows, and more in the document table."
/>
</p>
<EuiButton
data-test-subj="document-explorer-update-callout-dismiss-button"
iconType="check"
size="s"
onClick={onCloseCallout}
<EuiFlexGroup
justifyContent="flexStart"
alignItems="center"
responsive={false}
gutterSize="s"
>
<FormattedMessage
id="discover.docExplorerUpdateCallout.dismissButtonLabel"
defaultMessage="Got it"
/>
</EuiButton>
<EuiFlexItem grow={false}>
<EuiButton size="s" onClick={onTakeTour} data-test-subj="discoverTakeTourButton">
<FormattedMessage
id="discover.docExplorerUpdateCallout.takeTourButtonLabel"
defaultMessage="Take the tour"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="xs"
onClick={onCloseCallout}
data-test-subj="document-explorer-update-callout-dismiss-button"
>
<FormattedMessage
id="discover.docExplorerUpdateCallout.dismissButtonLabel"
defaultMessage="Dismiss"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiCallOut>
);
};
Expand All @@ -114,8 +103,8 @@ function CalloutTitle({ onCloseCallout }: { onCloseCallout: () => void }) {
<EuiFlexGroup justifyContent="spaceBetween" gutterSize="none" responsive={false}>
<EuiFlexItem grow={false}>
<FormattedMessage
id="discover.docExplorerUpdateCallout.headerMessage"
defaultMessage="Exploring your data just got better"
id="discover.docExplorerUpdateCallout.title"
defaultMessage="Get the best look at your search results"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { SortPairArr } from '../../../../components/doc_table/lib/get_sort';
import { ElasticSearchHit } from '../../../../types';
import { DocumentExplorerCallout } from '../document_explorer_callout';
import { DocumentExplorerUpdateCallout } from '../document_explorer_callout/document_explorer_update_callout';
import { DiscoverTourProvider } from '../../../../components/discover_tour';

const DocTableInfiniteMemoized = React.memo(DocTableInfinite);
const DataGridMemoized = React.memo(DiscoverGrid);
Expand Down Expand Up @@ -157,7 +158,9 @@ function DiscoverDocumentsComponent({
)}
{!isLegacy && (
<>
<DocumentExplorerUpdateCallout />
<DiscoverTourProvider>
<DocumentExplorerUpdateCallout />
</DiscoverTourProvider>
<div className="dscDiscoverGrid">
<DataGridMemoized
ariaLabelledBy="documentsAriaLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { FieldFilterState, getDefaultFieldFilter, setFieldFilterProp } from './l
import { getIndexPatternFieldList } from './lib/get_index_pattern_field_list';
import { DiscoverSidebarResponsiveProps } from './discover_sidebar_responsive';
import { VIEW_MODE } from '../../../../components/view_mode_toggle';
import { DISCOVER_TOUR_STEP_ANCHOR_IDS } from '../../../../components/discover_tour';
import { ElasticSearchHit } from '../../../../types';

/**
Expand Down Expand Up @@ -412,7 +413,7 @@ export function DiscoverSidebarComponent({
initialIsOpen={true}
buttonContent={
<EuiText size="xs" id="available_fields">
<strong>
<strong id={DISCOVER_TOUR_STEP_ANCHOR_IDS.addFields}>
kertal marked this conversation as resolved.
Show resolved Hide resolved
<FormattedMessage
id="discover.fieldChooser.filter.availableFieldsTitle"
defaultMessage="Available fields"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { AvailableFields$, DataDocuments$ } from '../../utils/use_saved_search';
import { calcFieldCounts } from '../../utils/calc_field_counts';
import { VIEW_MODE } from '../../../../components/view_mode_toggle';
import { FetchStatus } from '../../../types';
import { DISCOVER_TOUR_STEP_ANCHOR_IDS } from '../../../../components/discover_tour';

export interface DiscoverSidebarResponsiveProps {
/**
Expand Down Expand Up @@ -276,7 +277,10 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
<EuiShowFor sizes={['xs', 's']}>
<div className="dscSidebar__mobile">
<EuiButton
contentProps={{ className: 'dscSidebar__mobileButton' }}
contentProps={{
className: 'dscSidebar__mobileButton',
id: DISCOVER_TOUR_STEP_ANCHOR_IDS.addFields,
}}
fullWidth
onClick={() => setIsFlyoutVisible(true)}
>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { euiLightVars as themeLight, euiDarkVars as themeDark } from '@kbn/ui-th
import { i18n } from '@kbn/i18n';
import { DiscoverGridContext } from './discover_grid_context';
import { EsHitRecord } from '../../application/types';
import { DISCOVER_TOUR_STEP_ANCHOR_IDS } from '../discover_tour';

/**
* Button to expand a given row
*/
Expand Down Expand Up @@ -42,6 +44,7 @@ export const ExpandButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
return (
<EuiToolTip content={buttonLabel} delay="long">
<EuiButtonIcon
id={rowIndex === 0 ? DISCOVER_TOUR_STEP_ANCHOR_IDS.expandDocument : undefined}
size="xs"
iconSize="s"
aria-label={buttonLabel}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { EuiTourStep, EuiButton } from '@elastic/eui';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { discoverServiceMock } from '../../__mocks__/services';
import { DiscoverTourProvider } from './discover_tour_provider';
import { useDiscoverTourContext } from './discover_tour_context';
import { DISCOVER_TOUR_STEP_ANCHORS } from './discover_tour_anchors';

describe('Discover tour', () => {
const mountComponent = (innerContent?: JSX.Element) => {
return mountWithIntl(
<KibanaContextProvider services={discoverServiceMock}>
<DiscoverTourProvider>{innerContent}</DiscoverTourProvider>
</KibanaContextProvider>
);
};

it('should start successfully', () => {
const buttonSubjToTestStart = 'discoverTourButtonTestStart';
const InnerComponent = () => {
const tourContext = useDiscoverTourContext();

return (
<EuiButton onClick={tourContext.onStartTour} data-test-subj={buttonSubjToTestStart}>
{'Start the tour'}
</EuiButton>
);
};

const component = mountComponent(<InnerComponent />);
// all steps are hidden by default
expect(component.find(EuiTourStep)).toHaveLength(0);

// one step should become visible after the tour is triggered
component.find(`[data-test-subj="${buttonSubjToTestStart}"]`).at(0).simulate('click');

expect(component.find(EuiTourStep)).toHaveLength(5);
expect(
component.find({ anchor: DISCOVER_TOUR_STEP_ANCHORS.addFields, isStepOpen: true })
).toHaveLength(1);
expect(
component.find({ anchor: DISCOVER_TOUR_STEP_ANCHORS.reorderColumns, isStepOpen: false })
).toHaveLength(1);
expect(
component.find({ anchor: DISCOVER_TOUR_STEP_ANCHORS.sort, isStepOpen: false })
).toHaveLength(1);
expect(
component.find({ anchor: DISCOVER_TOUR_STEP_ANCHORS.changeRowHeight, isStepOpen: false })
).toHaveLength(1);
expect(
component.find({ anchor: DISCOVER_TOUR_STEP_ANCHORS.expandDocument, isStepOpen: false })
).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { htmlIdGenerator } from '@elastic/eui';

export const DISCOVER_TOUR_STEP_ANCHOR_IDS = {
addFields: htmlIdGenerator('dsc-tour-step-add-fields')(),
expandDocument: htmlIdGenerator('dsc-tour-step-expand')(),
};

export const DISCOVER_TOUR_STEP_ANCHORS = {
addFields: `#${DISCOVER_TOUR_STEP_ANCHOR_IDS.addFields}`,
reorderColumns: '[data-test-subj="dataGridColumnSelectorButton"]',
sort: '[data-test-subj="dataGridColumnSortingButton"]',
changeRowHeight: '[data-test-subj="dataGridDisplaySelectorButton"]',
expandDocument: `#${DISCOVER_TOUR_STEP_ANCHOR_IDS.expandDocument}`,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createContext, useContext } from 'react';

export interface DiscoverTourContextProps {
onStartTour: () => void;
onNextTourStep: () => void;
onFinishTour: () => void;
}

export const DiscoverTourContext = createContext<DiscoverTourContextProps>({
onStartTour: () => {},
onNextTourStep: () => {},
onFinishTour: () => {},
});

export const useDiscoverTourContext = () => {
return useContext(DiscoverTourContext);
};
Loading