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

[Guided onboarding] Update header button logic #144634

Merged
merged 32 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5165618
[Guided onboarding] Smashed commits for easier merge/conflict resolution
yuliacech Nov 3, 2022
807c518
[Guided onboarding] Integrate guideState into new pluginState
yuliacech Nov 8, 2022
f18c1b5
Merge branch 'main' into guided_onboarding/8.6_button_logic
yuliacech Nov 9, 2022
ae6f4aa
[Guided onboarding] Update the API
yuliacech Nov 9, 2022
f532cf3
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 9, 2022
7f21014
[Guided onboarding] More updates and test fixes
yuliacech Nov 9, 2022
de23465
[Guided onboarding] More fixes
yuliacech Nov 9, 2022
bbd3358
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 9, 2022
310f0e2
[Guided onboarding] Fix jest tests
yuliacech Nov 9, 2022
f6d091a
[Guided onboarding] Delete console
yuliacech Nov 9, 2022
c4c03aa
[Guided onboarding] Delete disabled status
yuliacech Nov 9, 2022
066b1d3
[Guided onboarding] Fix test description
yuliacech Nov 9, 2022
353fbf9
[Guided onboarding] Put back todo about loading and error state
yuliacech Nov 9, 2022
715bffb
[Guided onboarding] Update the comments
yuliacech Nov 9, 2022
0a93c9d
[Guided onboarding] Fix
yuliacech Nov 9, 2022
d3f9364
[Guided onboarding] Remove console
yuliacech Nov 9, 2022
0589000
Merge branch 'main' into guided_onboarding/8.6_button_logic
yuliacech Nov 10, 2022
88feb35
[Guided onboarding] Update api service mocks
yuliacech Nov 10, 2022
d4b5f25
[Guided onboarding] Update api integration tests
yuliacech Nov 10, 2022
53a37f7
[Guided onboarding] Address CR comments
yuliacech Nov 10, 2022
ce9e63a
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Nov 10, 2022
730cd42
[Guided onboarding] Fix
yuliacech Nov 10, 2022
8608783
[Guided onboarding] Update the limits and copy on the button
yuliacech Nov 10, 2022
3a3cd5d
[Guided onboarding] Fix SO tests
yuliacech Nov 10, 2022
17f9ac4
Merge branch 'main' into guided_onboarding/8.6_button_logic
yuliacech Nov 14, 2022
4ffe756
[Guided onboarding] Update the SO jest test snapshot
yuliacech Nov 14, 2022
85020ed
[Guided onboarding] Fix api unit tests
yuliacech Nov 14, 2022
a2ec2c7
[Guided onboarding] Fix jest tests
yuliacech Nov 14, 2022
112e132
[Guided onboarding] Hide the button when the user quits a guide
yuliacech Nov 14, 2022
c6cc2ce
Merge branch 'main' into guided_onboarding/8.6_button_logic
kibanamachine Nov 14, 2022
08a1cfc
Merge branch 'main' into guided_onboarding/8.6_button_logic
kibanamachine Nov 14, 2022
3d8df84
Merge branch 'main' into guided_onboarding/8.6_button_logic
kibanamachine Nov 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export const Main = (props: MainProps) => {
guideId: selectedGuide!,
};

const response = await guidedOnboardingApi?.updateGuideState(updatedGuideState, true);
const response = await guidedOnboardingApi?.updatePluginState(
{ status: 'in_progress', guide: updatedGuideState },
true
);
if (response) {
notifications.toasts.addSuccess(
i18n.translate('guidedOnboardingExample.updateGuideState.toastLabel', {
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/guided_onboarding/common/types.ts
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';
Copy link
Contributor

@alisonelizabeth alisonelizabeth Nov 10, 2022

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?

Copy link
Contributor Author

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.


/**
* 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
Expand Up @@ -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 => {
Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the isActive flag anymore since the plugin state provides the activeGuide? In other words, would the activeGuide ever not be active? 🤔

Copy link
Contributor Author

@yuliacech yuliacech Nov 10, 2022

Choose a reason for hiding this comment

The 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 isActive because guides are a separate saved object type and we keep all guides with their states in there. The only way to know which is the active guide is by querying the flag. Alternatively, we could keep an ID of the active guide in the plugin state SO, but I think the query works pretty well and is an already "tested" approach.

// 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}
Expand All @@ -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 (
Expand Down
Loading