forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs+] Add timed feedback toast (elastic#167682)
## Summary Closes elastic#166968 Adds a toast message asking for (optional) feedback when navigating from Observability Onboarding > Observability Log Explorer (via the Explore Logs button) after three minutes. The origin is attached to the history location state as part of the Locator. ## State machine A lightweight state machine handles the origin interpreting. We will very likely have more origins in the future. ![Screenshot 2023-10-02 at 17 33 41](https://github.com/elastic/kibana/assets/471693/b0f9ba81-b857-4185-a2dd-8049fae43932) ## Reviewer hints - Start the flow at `/app/observabilityOnboarding/customLogs`, continue to the last step of the wizard, click the "Explore logs" button to navigate to the Observability Log Explorer. - You can alter the `FEEDBACK_DELAY` constant for easier testing. - **Only** the onboarding origin should trigger the feedback toast. - Moves the feedback link to Observability shared to avoid cyclic dependency issues. ## Screenshot ![Screenshot 2023-10-03 at 14 45 21](https://github.com/elastic/kibana/assets/471693/8c5f0ac0-43a5-44f7-a361-4ea2f66e42b8) --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Marco Antonio Ghiani <[email protected]>
- Loading branch information
Showing
22 changed files
with
325 additions
and
20 deletions.
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
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
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
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
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/observability_log_explorer/public/state_machines/index.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,8 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { createOriginInterpreterStateMachine } from './origin_interpreter/src/state_machine'; |
29 changes: 29 additions & 0 deletions
29
...ins/observability_log_explorer/public/state_machines/origin_interpreter/src/component.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,29 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { isDevMode } from '@kbn/xstate-utils'; | ||
import { useInterpret } from '@xstate/react'; | ||
import { | ||
createOriginInterpreterStateMachine, | ||
OriginInterpreterStateMachineDependencies, | ||
} from './state_machine'; | ||
|
||
export const OriginInterpreter: React.FC<OriginInterpreterStateMachineDependencies> = ({ | ||
history, | ||
toasts, | ||
}) => { | ||
useInterpret( | ||
() => | ||
createOriginInterpreterStateMachine({ | ||
history, | ||
toasts, | ||
}), | ||
{ devTools: isDevMode() } | ||
); | ||
|
||
return null; | ||
}; |
9 changes: 9 additions & 0 deletions
9
...gins/observability_log_explorer/public/state_machines/origin_interpreter/src/constants.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,9 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const FEEDBACK_DELAY_MS = 30000; // 30 seconds | ||
export const FEEDBACK_TOAST_LIFETIME_MS = 60000; // 1 minute |
8 changes: 8 additions & 0 deletions
8
...ugins/observability_log_explorer/public/state_machines/origin_interpreter/src/defaults.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,8 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const DEFAULT_CONTEXT = undefined; |
16 changes: 16 additions & 0 deletions
16
...bservability_log_explorer/public/state_machines/origin_interpreter/src/lazy_component.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,16 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { withSuspense } from '@kbn/shared-ux-utility'; | ||
import React from 'react'; | ||
|
||
export const LazyOriginInterpreter = withSuspense( | ||
React.lazy(async () => ({ | ||
default: (await import('./component')).OriginInterpreter, | ||
})), | ||
null | ||
); |
27 changes: 27 additions & 0 deletions
27
...ility_log_explorer/public/state_machines/origin_interpreter/src/location_state_service.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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { InvokeCreator } from 'xstate'; | ||
import { ObservabilityLogExplorerHistory } from '../../../types'; | ||
import { OriginInterpreterContext, OriginInterpreterEvent } from './types'; | ||
|
||
export const initializeFromLocationState = | ||
({ | ||
history, | ||
}: { | ||
history: ObservabilityLogExplorerHistory; | ||
}): InvokeCreator<OriginInterpreterContext, OriginInterpreterEvent> => | ||
(context, event) => | ||
(callback) => { | ||
const origin = history.location?.state?.origin; | ||
|
||
if (!origin) { | ||
return callback('INITIALIZED_WITH_NO_ORIGIN'); | ||
} else if (origin.id === 'application-log-onboarding') { | ||
return callback('INITIALIZED_WITH_ONBOARDING_ORIGIN'); | ||
} | ||
}; |
53 changes: 53 additions & 0 deletions
53
...observability_log_explorer/public/state_machines/origin_interpreter/src/notifications.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,53 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IToasts } from '@kbn/core-notifications-browser'; | ||
import { mountReactNode } from '@kbn/core-mount-utils-browser-internal'; | ||
import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { LOGS_ONBOARDING_FEEDBACK_LINK } from '@kbn/observability-shared-plugin/common'; | ||
import React from 'react'; | ||
import { FEEDBACK_TOAST_LIFETIME_MS } from './constants'; | ||
|
||
export const createRequestFeedbackNotifier = (toasts: IToasts) => () => { | ||
toasts.addInfo( | ||
{ | ||
title: i18n.translate('xpack.observabilityLogExplorer.feedbackToast.title', { | ||
defaultMessage: 'Tell us what you think!', | ||
}), | ||
text: mountReactNode( | ||
<> | ||
<p> | ||
{i18n.translate('xpack.observabilityLogExplorer.feedbackToast.text', { | ||
defaultMessage: 'Share with us your onboarding experience and help us improve it.', | ||
})} | ||
</p> | ||
|
||
<EuiFlexGroup justifyContent="flexEnd" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
data-test-subj="observabilityLogExplorerFeedbackToastButton" | ||
href={LOGS_ONBOARDING_FEEDBACK_LINK} | ||
size="s" | ||
target="_blank" | ||
color="primary" | ||
> | ||
{i18n.translate('xpack.observabilityLogExplorer.feedbackToast.buttonText', { | ||
defaultMessage: 'Take a quick survey', | ||
})} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</> | ||
), | ||
iconType: 'editorComment', | ||
}, | ||
{ | ||
toastLifeTimeMs: FEEDBACK_TOAST_LIFETIME_MS, | ||
} | ||
); | ||
}; |
88 changes: 88 additions & 0 deletions
88
.../observability_log_explorer/public/state_machines/origin_interpreter/src/state_machine.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,88 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IToasts } from '@kbn/core-notifications-browser'; | ||
import { createMachine, InterpreterFrom } from 'xstate'; | ||
import { ObservabilityLogExplorerHistory } from '../../../types'; | ||
import { FEEDBACK_DELAY_MS } from './constants'; | ||
import { DEFAULT_CONTEXT } from './defaults'; | ||
import { initializeFromLocationState } from './location_state_service'; | ||
import { createRequestFeedbackNotifier } from './notifications'; | ||
import { | ||
OriginInterpreterContext, | ||
OriginInterpreterEvent, | ||
OriginInterpreterTypeState, | ||
} from './types'; | ||
|
||
export const createPureOriginInterpreterStateMachine = (initialContext: OriginInterpreterContext) => | ||
/** @xstate-layout N4IgpgJg5mDOIC5QBkD2UCiAPADgG1QCcxCAFQ1AMwEs8wA6AVwDtrWAXagQz2oC9IAYgDaABgC6iUDlSxqnVMykgsiAIwAOAMz0NagEwBWUdoBsWgOxaAnEYA0IAJ7rt9UxesWD+2xf2WAXwCHNExcAmIyCho6ejZ5bl4+NigAMQoAWwBVQjxBCEUGNgA3VABrBlDsfCIScipaIo5E-hT01GzchBLUAGMuBWYxcWHlGTlB5VUEYw1dfQ1RQ30LC0NrbX0HZwQ1CwAWemtDLTV991FTPWWtIJD0aoi66Ma45p5W5jTMnLySCkI9HwA0oRAy9Cq4VqUQasXinA+yS+7U6eG6zFK-UGw1GSBA4wSiimiFm80Wy1W60220QenoxlEjP2J32alEmmsdxAkJqkXqMSaCURKQAIgMuAA1ahgADu+UKb1KFQhDyhfJecPeSVF4qlsvRmIG1EUOIkY1khKUeOmPkM9D8pkMFm0bMpFhpM3Obi0tqdxk0Fi5PKeMIFbyF2q+YvYkulcv+RCBeBBYJVYV5z1hgoRkag0dj+p6WONQwkuOkFsm1sQtvt+kdztOojdHquonoah91h9WkWS1MQdVGdDr3hLSRUAAwop2BQ8KQuMwwHhYPKl4rypUhyH+aOtZ8p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FXQBz6gjDPq8H7KkAkbDpd0DYfs6wTGdiC4ihpJWJFQPzJwiruwRIMf8rxXyzZmSdmPi+VyfFJawfEoYDrzan7WJi2W+xbSymWQG4Y0wnURvNYg0yiZ-ksHn20LxXsIUSMbpQ8AoVVGRXtoG05zTrmdOaDS9oshL5hkUL9D3KKVD8s2ru5Y1tj2g17OvQNtYcwZ2smy+Qp8WggrOnbCHYCLmNX6CW9eiHgb22YoG2cDqrJWR+Dwf6DQaaTG6GluJNy13nR44LUWzZROXWhq7eRAbiXnNabc7pr7zdDV7cQ+1CbthnyBkXUAA */ | ||
createMachine<OriginInterpreterContext, OriginInterpreterEvent, OriginInterpreterTypeState>( | ||
{ | ||
context: initialContext, | ||
predictableActionArguments: true, | ||
id: 'OriginInterpreter', | ||
initial: 'uninitialized', | ||
states: { | ||
uninitialized: { | ||
always: 'initializingFromLocationState', | ||
}, | ||
initializingFromLocationState: { | ||
invoke: { | ||
src: 'initializeFromLocationState', | ||
}, | ||
on: { | ||
INITIALIZED_WITH_NO_ORIGIN: '#done', | ||
INITIALIZED_WITH_ONBOARDING_ORIGIN: '#onboarding', | ||
}, | ||
}, | ||
onboarding: { | ||
id: 'onboarding', | ||
initial: 'waiting', | ||
states: { | ||
waiting: { | ||
after: { | ||
[FEEDBACK_DELAY_MS]: { | ||
target: '#done', | ||
actions: ['requestFeedback'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
done: { | ||
id: 'done', | ||
type: 'final', | ||
}, | ||
}, | ||
}, | ||
{ | ||
actions: {}, | ||
guards: {}, | ||
} | ||
); | ||
|
||
export interface OriginInterpreterStateMachineDependencies { | ||
initialContext?: OriginInterpreterContext; | ||
history: ObservabilityLogExplorerHistory; | ||
toasts: IToasts; | ||
} | ||
|
||
export const createOriginInterpreterStateMachine = ({ | ||
initialContext = DEFAULT_CONTEXT, | ||
history, | ||
toasts, | ||
}: OriginInterpreterStateMachineDependencies) => | ||
createPureOriginInterpreterStateMachine(initialContext).withConfig({ | ||
actions: { | ||
requestFeedback: createRequestFeedbackNotifier(toasts), | ||
}, | ||
services: { | ||
initializeFromLocationState: initializeFromLocationState({ history }), | ||
}, | ||
}); | ||
|
||
export type OriginInterpreterService = InterpreterFrom<typeof createOriginInterpreterStateMachine>; |
Oops, something went wrong.