-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Dashboard] Add tour to Dashboard #131960
Closed
Closed
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c59f8e1
Add dashboard tour
Heenawter ffcda8c
Force end view mode tour when change to edit mode
Heenawter 7749eca
Add 18n + a few small fixes
Heenawter 2f8177d
Skip last step if controls disabled
Heenawter 50a8a2d
Move tour folder in to application folder
Heenawter 0b0d2ac
Fix functional tests
Heenawter 6bb9395
Clean up code
Heenawter a2c1a10
Make functional tests pass via changes to only presentation-owned files
Heenawter 5d88836
Add tour functional tests
Heenawter 9ed298b
Move functional tests to group 6
Heenawter 736b5c6
Merge branch 'main' of github.com:elastic/kibana into add-dashboard-t…
Heenawter 5006e51
Fix wording of tour steps
Heenawter 35c5e07
Use React context for edit tour
Heenawter 5609d33
Hide tour when add from library flyout open
Heenawter 69a69b6
Hide edit tour when in view mode
Heenawter 0d631d4
Merge branch 'main' of github.com:elastic/kibana into add-dashboard-t…
Heenawter 7e4d19b
Combine both tours + hide tour on add from library
Heenawter 434231c
Clean up code and files
Heenawter c969976
Permanently dismiss edit tour on skip or finish.
Heenawter 3ed778e
Hide tour when control flyout open
Heenawter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/plugins/dashboard/public/application/tour/custom_footer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 { EuiButton, EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiI18n } from '@elastic/eui'; | ||
import React from 'react'; | ||
|
||
export const CustomFooter = ({ onSkip, onNext }: { onSkip: () => void; onNext: () => void }) => { | ||
return ( | ||
<EuiFlexGroup responsive={false} gutterSize="s" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty color="text" size="xs" onClick={onSkip}> | ||
{EuiI18n({ token: 'core.euiTourStep.skipTour', default: 'Skip tour' })} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton size="s" color="success" onClick={onNext}> | ||
{EuiI18n({ token: 'core.euiTourStep.nextStep', default: 'Next' })} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
145 changes: 145 additions & 0 deletions
145
src/plugins/dashboard/public/application/tour/dashboard_edit_tour.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* 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 { | ||
EuiButtonEmpty, | ||
EuiI18n, | ||
EuiStatelessTourStep, | ||
EuiText, | ||
EuiTourState, | ||
EuiTourStep, | ||
useEuiTour, | ||
} from '@elastic/eui'; | ||
import React, { useEffect } from 'react'; | ||
import { CustomFooter } from './custom_footer'; | ||
import { DashboardTourStrings } from './translations'; | ||
|
||
export const DASHBOARD_EDIT_TOUR_STORAGE_KEY = 'dashboard.edit.tourState'; | ||
const TOUR_POPOVER_WIDTH = 360; | ||
|
||
const dashboardEditTourConfig = { | ||
currentTourStep: 1, | ||
isTourActive: true, | ||
tourPopoverWidth: 360, | ||
tourSubtitle: DashboardTourStrings.editModeTour.getTitle(), | ||
}; | ||
|
||
const dashboardEditTourSteps = [ | ||
{ | ||
anchor: '[data-test-subj="dashboardAddNewPanelButton"]', | ||
step: 1, | ||
title: DashboardTourStrings.editModeTour.createVisualization.getTitle(), | ||
content: ( | ||
<EuiText>{DashboardTourStrings.editModeTour.createVisualization.getDescription()}</EuiText> | ||
), | ||
anchorPosition: 'rightCenter', | ||
maxWidth: TOUR_POPOVER_WIDTH, | ||
} as EuiStatelessTourStep, | ||
{ | ||
anchor: '[data-test-subj="embeddablePanelToggleMenuIcon"]', | ||
step: 2, | ||
title: DashboardTourStrings.editModeTour.panelOptions.getTitle(), | ||
content: <EuiText>{DashboardTourStrings.editModeTour.panelOptions.getDescription()}</EuiText>, | ||
anchorPosition: 'upCenter', | ||
maxWidth: TOUR_POPOVER_WIDTH, | ||
} as EuiStatelessTourStep, | ||
{ | ||
anchor: '.kbnQueryBar__datePickerWrapper', | ||
step: 3, | ||
title: DashboardTourStrings.editModeTour.timePicker.getTitle(), | ||
content: <EuiText>{DashboardTourStrings.editModeTour.timePicker.getDescription()}</EuiText>, | ||
anchorPosition: 'downCenter', | ||
maxWidth: TOUR_POPOVER_WIDTH, | ||
} as EuiStatelessTourStep, | ||
{ | ||
anchor: '#addFilterPopover', | ||
step: 4, | ||
title: DashboardTourStrings.editModeTour.filters.getTitle(), | ||
content: <EuiText>{DashboardTourStrings.editModeTour.filters.getDescription()}</EuiText>, | ||
anchorPosition: 'downLeft', | ||
maxWidth: TOUR_POPOVER_WIDTH, | ||
} as EuiStatelessTourStep, | ||
{ | ||
anchor: '[data-test-subj="dashboard-controls-menu-button"]', | ||
step: 5, | ||
title: DashboardTourStrings.editModeTour.controls.getTitle(), | ||
content: <EuiText>{DashboardTourStrings.editModeTour.controls.getDescription()}</EuiText>, | ||
anchorPosition: 'upCenter', | ||
maxWidth: TOUR_POPOVER_WIDTH, | ||
} as EuiStatelessTourStep, | ||
]; | ||
|
||
export const DashboardEditTour = ({ | ||
panelCount, | ||
controlsEnabled, | ||
}: { | ||
panelCount: number; | ||
controlsEnabled: boolean; | ||
}) => { | ||
const initialState = localStorage.getItem(DASHBOARD_EDIT_TOUR_STORAGE_KEY); | ||
let tourState: EuiTourState; | ||
if (initialState) { | ||
tourState = JSON.parse(initialState); | ||
} else { | ||
tourState = dashboardEditTourConfig; | ||
} | ||
|
||
const [ | ||
[euiTourStepOne, euiTourStepTwo, euiTourStepThree, euiTourStepFour, euiTourStepFive], | ||
actions, | ||
reducerState, | ||
] = useEuiTour(dashboardEditTourSteps, tourState); | ||
|
||
useEffect(() => { | ||
localStorage.setItem(DASHBOARD_EDIT_TOUR_STORAGE_KEY, JSON.stringify(reducerState)); | ||
}, [reducerState]); | ||
|
||
const commonFooterProps = { | ||
onSkip: () => actions.finishTour(), | ||
onNext: () => actions.incrementStep(), | ||
}; | ||
|
||
const skipVisualizationStep = () => { | ||
if (panelCount > 0) { | ||
actions.incrementStep(); | ||
} else { | ||
actions.goToStep(3); | ||
} | ||
}; | ||
|
||
const EndTourIfNoControlsFooter = () => { | ||
if (controlsEnabled) return <CustomFooter {...commonFooterProps} />; | ||
return ( | ||
<EuiButtonEmpty color="text" size="xs" onClick={() => actions.finishTour()}> | ||
{EuiI18n({ token: 'core.euiTourStep.endTour', default: 'End tour' })} | ||
</EuiButtonEmpty> | ||
); | ||
}; | ||
|
||
const TourSteps = () => { | ||
return ( | ||
<> | ||
<EuiTourStep | ||
{...euiTourStepOne} | ||
footerAction={ | ||
<CustomFooter | ||
onSkip={() => actions.finishTour()} | ||
onNext={() => skipVisualizationStep()} | ||
/> | ||
} | ||
/> | ||
<EuiTourStep {...euiTourStepTwo} footerAction={<CustomFooter {...commonFooterProps} />} /> | ||
<EuiTourStep {...euiTourStepThree} footerAction={<CustomFooter {...commonFooterProps} />} /> | ||
<EuiTourStep {...euiTourStepFour} footerAction={<EndTourIfNoControlsFooter />} /> | ||
<EuiTourStep {...euiTourStepFive} /> | ||
</> | ||
); | ||
}; | ||
|
||
return <TourSteps />; | ||
}; |
52 changes: 52 additions & 0 deletions
52
src/plugins/dashboard/public/application/tour/dashboard_view_tour.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 { EuiStatelessTourStep, EuiText, EuiTourState, EuiTourStep, useEuiTour } from '@elastic/eui'; | ||
import React, { useEffect } from 'react'; | ||
import { DashboardTourStrings } from './translations'; | ||
|
||
export const DASHBOARD_VIEW_TOUR_STORAGE_KEY = 'dashboard.view.tourState'; | ||
const TOUR_POPOVER_WIDTH = 360; | ||
|
||
export const dashboardViewTourConfig = { | ||
currentTourStep: 1, | ||
isTourActive: true, | ||
tourPopoverWidth: TOUR_POPOVER_WIDTH, | ||
}; | ||
|
||
export const dashboardViewTourSteps = [ | ||
{ | ||
anchor: '[data-test-subj="dashboardEditMode"]', | ||
step: 1, | ||
title: DashboardTourStrings.viewModeTour.getTitle(), | ||
content: <EuiText>{DashboardTourStrings.viewModeTour.getDescription()}</EuiText>, | ||
anchorPosition: 'downCenter', | ||
maxWidth: TOUR_POPOVER_WIDTH, | ||
} as EuiStatelessTourStep, | ||
]; | ||
|
||
export const DashboardViewTour = () => { | ||
const initialState = localStorage.getItem(DASHBOARD_VIEW_TOUR_STORAGE_KEY); | ||
let tourState: Pick<EuiTourState, Exclude<keyof EuiTourState, 'tourSubtitle'>>; | ||
if (initialState) { | ||
tourState = { ...JSON.parse(initialState) }; | ||
} else { | ||
tourState = dashboardViewTourConfig; | ||
} | ||
|
||
const [[euiTourStepOne], _, reducerState] = useEuiTour( | ||
dashboardViewTourSteps, | ||
tourState as EuiTourState | ||
); | ||
|
||
useEffect(() => { | ||
localStorage.setItem(DASHBOARD_VIEW_TOUR_STORAGE_KEY, JSON.stringify(reducerState)); | ||
}, [reducerState]); | ||
|
||
return <EuiTourStep {...euiTourStepOne} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './dashboard_edit_tour'; | ||
export * from './dashboard_view_tour'; |
81 changes: 81 additions & 0 deletions
81
src/plugins/dashboard/public/application/tour/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const DashboardTourStrings = { | ||
viewModeTour: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.viewMode.title', { | ||
defaultMessage: 'Ready to create something brilliant?', | ||
}), | ||
getDescription: () => | ||
i18n.translate('dashboard.tour.viewMode.firstStep.description', { | ||
defaultMessage: 'Start editing here.', | ||
}), | ||
}, | ||
editModeTour: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.editMode.title', { | ||
defaultMessage: 'Dashboard tour', | ||
}), | ||
createVisualization: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.editMode.createVisualization.title', { | ||
defaultMessage: 'Create visualizations', | ||
}), | ||
getDescription: () => | ||
i18n.translate('dashboard.tour.editMode.createVisualization.description', { | ||
defaultMessage: | ||
'Build maps, charts, gauges, and other visualizations that best display your data.', | ||
}), | ||
}, | ||
panelOptions: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.editMode.panelOptions.title', { | ||
defaultMessage: 'Add your style', | ||
}), | ||
getDescription: () => | ||
i18n.translate('dashboard.tour.editMode.panelOptions.description', { | ||
defaultMessage: 'Customize your visualization to give your data its best look.', | ||
}), | ||
}, | ||
timePicker: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.editMode.timePicker.title', { | ||
defaultMessage: 'Expand the time range', | ||
}), | ||
getDescription: () => | ||
i18n.translate('dashboard.tour.editMode.timePicker.description', { | ||
defaultMessage: | ||
'View hits for a particular day, the last year, or whatever gets you the data you want.', | ||
}), | ||
}, | ||
filters: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.editMode.addFilter.title', { | ||
defaultMessage: 'Filter the data', | ||
}), | ||
getDescription: () => | ||
i18n.translate('dashboard.tour.editMode.addFilter.description', { | ||
defaultMessage: | ||
'To reduce the amount of data displayed, filter for data that exists, does not exist, contains a value, and more.', | ||
}), | ||
}, | ||
controls: { | ||
getTitle: () => | ||
i18n.translate('dashboard.tour.editMode.controls.title', { | ||
defaultMessage: 'Make it interactive', | ||
}), | ||
getDescription: () => | ||
i18n.translate('dashboard.tour.editMode.controls.description', { | ||
defaultMessage: 'Add controls for a more engaging, more memorable experience.', | ||
}), | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to put the view mode tour in
dashboard_top_nav.tsx
so that I could have direct access to theonClick
action of switching to edit mode - that way, either by directly dismissing it or by switching from view mode to edit mode, the view mode tour will be dismissed permanently.Since it would have made the code much cleaner, I originally tried to do this by injecting the view mode tour alongside the edit mode tour in the Dashboard viewport and listening for changes to the view mode to trigger the ending of the view mode tour - unfortunately this happened too late and I would get the following error:
which was caused by the
EuiTourStep
being anchored to the edit button, which is dynamically hidden and replaced with theView mode
button when switching from view mode to edit mode.Very much interested in seeing if there is a better way of handling this, since I'm not a huge fan of the view mode tour code being in
dashboard_top_nav.tsx
while the edit mode tour is indashboard_viewport.tsx
(a much more reasonable place) 👍