Skip to content

Commit

Permalink
[Guided onboarding] Update header button logic (#144634)
Browse files Browse the repository at this point in the history
## Summary
Fixes #141129
Fixes #144515

This PR introduces a new state to the guided onboarding plugin. The
state keeps track of the `creationDate` and of the overall `status` of
the plugin. The creation date allows us to detect an "active" period
during which the header button will be displayed more prominently in the
header. Currently, the active period is set to 30 days. During this
time, if the user has not started any guide, has quit a guide before
completion or skipped the guide on the landing page, the header button
will be displayed and when clicked, redirect the user to the landing
page to start/continue a guide.
Also this PR adds a check for Cloud deployments and prevents the code
from sending any API requests when not on Cloud, because guided
onboarding is disabled on prem.

#### Screenshot 
<img width="298" alt="Screenshot 2022-11-10 at 18 42 18"
src="https://user-images.githubusercontent.com/6585477/201168414-391a7cd4-0709-492b-9001-1432b5bed3c8.png">



### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
yuliacech and kibanamachine authored Nov 14, 2022
1 parent e2d3bb9 commit 879b101
Show file tree
Hide file tree
Showing 37 changed files with 1,539 additions and 932 deletions.
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
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pageLoadAssetSize:
globalSearchProviders: 25554
graph: 31504
grokdebugger: 26779
guidedOnboarding: 26875
guidedOnboarding: 42965
home: 30182
indexLifecycleManagement: 107090
indexManagement: 140608
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"fleet-preconfiguration-deletion-record": "7b28f200513c28ae774f1b7d7d7906954e3c6e16",
"graph-workspace": "3342f2cd561afdde8f42f5fb284bf550dee8ebb5",
"guided-onboarding-guide-state": "561db8d481b131a2bbf46b1e534d6ce960255135",
"guided-onboarding-plugin-state": "a802ed58e9d0076b9632c59d7943861ba476f99c",
"index-pattern": "48e77ca393c254e93256f11a7cdc0232dd754c08",
"infrastructure-monitoring-log-view": "e2c78c1076bd35e57d7c5fa1b410e5c126d12327",
"infrastructure-ui-source": "7c8dbbc0a608911f1b683a944f4a65383f6153ed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const previouslyRegisteredTypes = [
'graph-workspace',
'guided-setup-state',
'guided-onboarding-guide-state',
'guided-onboarding-plugin-state',
'index-pattern',
'infrastructure-monitoring-log-view',
'infrastructure-ui-source',
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';

/**
* 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;
}
45 changes: 40 additions & 5 deletions src/plugins/guided_onboarding/public/components/guide_button.tsx
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) {
// if still active period and the user has not started a guide or skipped the guide,
// display the button that redirects to the landing page
if (
!(
pluginState?.isActivePeriod &&
(pluginState?.status === 'not_started' || pluginState?.status === 'skipped')
)
) {
return null;
} else {
return (
<EuiButton
onClick={navigateToLandingPage}
color="success"
fill
size="s"
data-test-subj="guideButtonRedirect"
>
{i18n.translate('guidedOnboarding.guidedSetupRedirectButtonLabel', {
defaultMessage: 'Setup guide',
})}
</EuiButton>
);
}
}
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

0 comments on commit 879b101

Please sign in to comment.