-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[Guided onboarding] Update header button logic #144634
Changes from 16 commits
5165618
807c518
f18c1b5
ae6f4aa
f532cf3
7f21014
de23465
bbd3358
310f0e2
f6d091a
c4c03aa
066b1d3
353fbf9
715bffb
0a93c9d
d3f9364
0589000
88feb35
d4b5f25
53a37f7
ce9e63a
730cd42
8608783
3a3cd5d
17f9ac4
4ffe756
85020ed
a2ec2c7
112e132
c6cc2ce
08a1cfc
3d8df84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 { GuideState } from '@kbn/guided-onboarding'; | ||
|
||
/** | ||
* Guided onboarding overall status: | ||
* not_started: no guides have been started yet | ||
* in_progress: a guide is currently active | ||
* complete: at least one guide has been completed | ||
* quit: the user quit a guide before completion | ||
* skipped: the user skipped on the landing page | ||
*/ | ||
export type PluginStatus = 'not_started' | 'in_progress' | 'complete' | 'quit' | 'skipped'; | ||
|
||
export interface PluginState { | ||
status: PluginStatus; | ||
// a specific period after deployment creation when guided onboarding UI is highlighted | ||
isActivePeriod: boolean; | ||
activeGuide?: GuideState; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,15 @@ import { EuiButton } from '@elastic/eui'; | |
import { i18n } from '@kbn/i18n'; | ||
import type { GuideState } from '@kbn/guided-onboarding'; | ||
|
||
import type { PluginState } from '../../common/types'; | ||
import { getStepConfig } from '../services/helpers'; | ||
import { GuideButtonPopover } from './guide_button_popover'; | ||
|
||
interface GuideButtonProps { | ||
guideState: GuideState; | ||
pluginState: PluginState | undefined; | ||
toggleGuidePanel: () => void; | ||
isGuidePanelOpen: boolean; | ||
navigateToLandingPage: () => void; | ||
} | ||
|
||
const getStepNumber = (state: GuideState): number | undefined => { | ||
|
@@ -39,12 +41,45 @@ const getStepNumber = (state: GuideState): number | undefined => { | |
}; | ||
|
||
export const GuideButton = ({ | ||
guideState, | ||
pluginState, | ||
toggleGuidePanel, | ||
isGuidePanelOpen, | ||
navigateToLandingPage, | ||
}: GuideButtonProps) => { | ||
const stepNumber = getStepNumber(guideState); | ||
const stepReadyToComplete = guideState.steps.find((step) => step.status === 'ready_to_complete'); | ||
// TODO handle loading, error state | ||
// https://github.com/elastic/kibana/issues/139799, https://github.com/elastic/kibana/issues/139798 | ||
|
||
// if there is no active guide | ||
if (!pluginState || !pluginState.activeGuide || !pluginState.activeGuide.isActive) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that too, but I think we still need the flag |
||
// if still active period and the user has not started a guide, quit or skipped the guide, | ||
// display the button that redirects to the landing page | ||
if ( | ||
pluginState?.isActivePeriod && | ||
(pluginState?.status === 'not_started' || | ||
pluginState?.status === 'quit' || | ||
pluginState?.status === 'skipped') | ||
) { | ||
return ( | ||
<EuiButton | ||
onClick={navigateToLandingPage} | ||
color="success" | ||
fill | ||
size="s" | ||
data-test-subj="guideButtonRedirect" | ||
> | ||
{i18n.translate('guidedOnboarding.guidedSetupRedirectButtonLabel', { | ||
defaultMessage: 'Launch setup guide', | ||
})} | ||
</EuiButton> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
const stepNumber = getStepNumber(pluginState.activeGuide); | ||
const stepReadyToComplete = pluginState.activeGuide.steps.find( | ||
(step) => step.status === 'ready_to_complete' | ||
); | ||
const button = ( | ||
<EuiButton | ||
onClick={toggleGuidePanel} | ||
|
@@ -66,7 +101,7 @@ export const GuideButton = ({ | |
</EuiButton> | ||
); | ||
if (stepReadyToComplete) { | ||
const stepConfig = getStepConfig(guideState.guideId, stepReadyToComplete.id); | ||
const stepConfig = getStepConfig(pluginState.activeGuide.guideId, stepReadyToComplete.id); | ||
// check if the stepConfig has manualCompletion info | ||
if (stepConfig && stepConfig.manualCompletion) { | ||
return ( | ||
|
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.
Can you remind me again why
GuideState
lives in a package and not in the plugin?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.
We needed
GuideState
in the Home plugin and then moved some of the code from the Home plugin into a package, so the types have to be in the package too.