-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[engagement] Create Engagement plugin PoC #123339
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3aa3697
[engagement] Create engagement plugin PoC
clintandrewhall 2ccdd63
fixes
clintandrewhall f1bba3b
Fixed type and mock issue
clintandrewhall 1b475df
Made chat divide more clear by removing references to 'drift'
clintandrewhall 9bdf552
Fixing mocks
clintandrewhall 71574ff
Merge branch 'main' into cloud/engagement
clintandrewhall fbbe312
Addressing feedback
clintandrewhall 76f1cbe
Separate config and service provided data
SergeyPoluektov 30e8ca9
Add JWT token endpoint
SergeyPoluektov 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
Next
Next commit
[engagement] Create engagement plugin PoC
- Loading branch information
commit 3aa3697a2538e35bcb96a3c334bff27a3f51858d
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| { | ||
| "prefix": "engagement", | ||
| "paths": { | ||
| "engagement": "." | ||
| }, | ||
| "translations": ["translations/ja-JP.json"] | ||
| } |
This file contains hidden or 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 React from 'react'; | ||
| import { DecoratorFn } from '@storybook/react'; | ||
| import { servicesDecorator as sharedUXServicesDecorator } from '../../shared_ux/.storybook/decorators'; | ||
| import { ServicesProvider } from '../public/services'; | ||
|
|
||
| const config = { | ||
| drift: { | ||
| enabled: true, | ||
| chatURL: 'https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html', | ||
| pocID: '53877975', | ||
| pocEmail: 'sergei.poluektov+drift-chat@elasticsearch.com', | ||
| pocJWT: | ||
| 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Mzg3Nzk3NSIsImV4cCI6MTY0MjUxNDc0Mn0.CcAZbD8R865UmoHGi27wKn0aH1bzkZXhX449yyDH2Vk', | ||
| }, | ||
| }; | ||
|
|
||
| export const servicesDecorator: DecoratorFn = (storyFn, context) => ( | ||
| <ServicesProvider {...config}>{sharedUXServicesDecorator(storyFn, context)}</ServicesProvider> | ||
| ); |
This file contains hidden or 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,11 @@ | ||
| /* | ||
| * 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 { defaultConfig } from '@kbn/storybook'; | ||
|
|
||
| module.exports = defaultConfig; |
This file contains hidden or 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,21 @@ | ||
| /* | ||
| * 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 { addons } from '@storybook/addons'; | ||
| import { create } from '@storybook/theming'; | ||
| import { PANEL_ID } from '@storybook/addon-actions'; | ||
|
|
||
| addons.setConfig({ | ||
| theme: create({ | ||
| base: 'light', | ||
| brandTitle: 'Engagement Storybook', | ||
| brandUrl: 'https://github.com/elastic/kibana/tree/main/src/plugins/engagement', | ||
| }), | ||
| showPanel: true.valueOf, | ||
| selectedPanel: PANEL_ID, | ||
| }); |
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 { addDecorator } from '@storybook/react'; | ||
| import { servicesDecorator } from './decorators'; | ||
|
|
||
| addDecorator(servicesDecorator); |
This file contains hidden or 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,5 @@ | ||
| # engagement | ||
|
|
||
| A Kibana plugin | ||
|
|
||
| --- |
This file contains hidden or 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 const PLUGIN_ID = 'engagement'; | ||
| export const PLUGIN_NAME = 'engagement'; | ||
This file contains hidden or 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 @@ | ||
| { | ||
| "id": "engagement", | ||
| "version": "1.0.0", | ||
| "kibanaVersion": "kibana", | ||
| "owner": { | ||
| "name": "Shared UX", | ||
| "githubTeam": "shared-ux" | ||
| }, | ||
| "description": "A plugin for engaging with the active user.", | ||
| "server": true, | ||
| "ui": true, | ||
| "requiredPlugins": [ | ||
| "sharedUX" | ||
| ], | ||
| "optionalPlugins": [] | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/plugins/engagement/public/components/drift_chat/drift_chat.stories.tsx
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
|
|
||
| import { DriftChat } from './drift_chat'; | ||
|
|
||
| export default { | ||
| title: 'Drift Chat', | ||
| description: '', | ||
| parameters: {}, | ||
| }; | ||
|
|
||
| export const Component = () => { | ||
| return ( | ||
| <div> | ||
| <DriftChat /> | ||
| </div> | ||
| ); | ||
| }; |
136 changes: 136 additions & 0 deletions
136
src/plugins/engagement/public/components/drift_chat/drift_chat.tsx
This file contains hidden or 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,136 @@ | ||
| /* | ||
| * 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 React, { useEffect, useRef, useState, CSSProperties } from 'react'; | ||
| import { css } from '@emotion/react'; | ||
| import { useDrift } from '../../services'; | ||
|
|
||
| type UseDriftType = | ||
| | [false] | ||
| | [true, string, React.MutableRefObject<HTMLIFrameElement | null>, CSSProperties]; | ||
|
|
||
| const MESSAGE_READY = 'driftIframeReady'; | ||
| const MESSAGE_RESIZE = 'driftIframeResize'; | ||
|
|
||
| const iframeStyle = css` | ||
| position: fixed; | ||
| botton: 30px; | ||
| right: 30px; | ||
| display: block; | ||
| `; | ||
|
|
||
| const getContext = () => { | ||
| const { location, navigator, innerHeight, innerWidth } = window; | ||
| const { hash, host, hostname, href, origin, pathname, port, protocol, search } = location; | ||
| const { language, userAgent } = navigator; | ||
| const { title, referrer } = document; | ||
|
|
||
| return { | ||
| window: { | ||
| location: { | ||
| hash, | ||
| host, | ||
| hostname, | ||
| href, | ||
| origin, | ||
| pathname, | ||
| port, | ||
| protocol, | ||
| search, | ||
| }, | ||
| navigator: { language, userAgent }, | ||
| innerHeight, | ||
| innerWidth, | ||
| }, | ||
| document: { | ||
| title, | ||
| referrer, | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| const useDriftFrame = (): UseDriftType => { | ||
| const chatRef = useRef<HTMLIFrameElement>(null); | ||
| const drift = useDrift(); | ||
| const [style, setStyle] = useState<CSSProperties>({}); | ||
|
|
||
| useEffect(() => { | ||
| const handleMessage = (event: MessageEvent): void => { | ||
| const { current: chatIframe } = chatRef; | ||
|
|
||
| if ( | ||
| !drift.enabled || | ||
| !chatIframe?.contentWindow || | ||
| event.source !== chatIframe?.contentWindow | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const { data: message } = event; | ||
| const context = getContext(); | ||
|
|
||
| switch (message.type) { | ||
| case MESSAGE_READY: { | ||
| const user = { | ||
| id: drift.pocID, | ||
| attributes: { | ||
| email: drift.pocEmail, | ||
| }, | ||
| jwt: drift.pocJWT, | ||
| }; | ||
|
|
||
| chatIframe.contentWindow.postMessage( | ||
| { | ||
| type: 'driftSetContext', | ||
| data: { context, user }, | ||
| }, | ||
| '*' | ||
| ); | ||
| break; | ||
| } | ||
|
|
||
| case MESSAGE_RESIZE: { | ||
| const styles = message.data.styles || ({} as CSSProperties); | ||
| setStyle({ ...style, ...styles }); | ||
| break; | ||
| } | ||
|
|
||
| default: | ||
| break; | ||
| } | ||
| }; | ||
|
|
||
| window.addEventListener('message', handleMessage); | ||
| return () => window.removeEventListener('message', handleMessage); | ||
| }, [drift, style]); | ||
|
|
||
| if (drift.enabled) { | ||
| return [true, drift.chatURL, chatRef, style]; | ||
| } | ||
|
|
||
| return [false]; | ||
| }; | ||
|
|
||
| export const DriftChat = () => { | ||
| const [enabled, chatUrl, chatRef, style] = useDriftFrame(); | ||
|
|
||
| if (!enabled) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <iframe | ||
| css={iframeStyle} | ||
| style={style} | ||
| data-test-id="drift-chat" | ||
| ref={chatRef} | ||
| src={chatUrl} | ||
| title="Engagment" | ||
| /> | ||
| ); | ||
| }; |
17 changes: 17 additions & 0 deletions
17
src/plugins/engagement/public/components/drift_chat/index.ts
This file contains hidden or 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,17 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| /* eslint-disable import/no-default-export */ | ||
|
|
||
| import { DriftChat } from './drift_chat'; | ||
| export { DriftChat } from './drift_chat'; | ||
|
|
||
| /** | ||
| * Exporting the DriftChat component as a default export so it can be | ||
| * loaded by React.lazy. | ||
| */ | ||
| export default DriftChat; |
This file contains hidden or 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,14 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
| import { withSuspense } from '../../../shared_ux/public'; | ||
|
|
||
| // This could be abstracted away, but defaulting to DriftChat for now. | ||
| export const LazyEngagementChat = React.lazy(() => import('./drift_chat')); | ||
| export const EngagementChat = withSuspense(LazyEngagementChat); |
This file contains hidden or 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,20 @@ | ||
| /* | ||
| * 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 { PluginInitializerContext } from '../../../core/public'; | ||
|
|
||
| import { EngagementPlugin } from './plugin'; | ||
|
|
||
| // This exports static code and TypeScript types, | ||
| // as well as, Kibana Platform `plugin()` initializer. | ||
| export function plugin(initializerContext: PluginInitializerContext) { | ||
| return new EngagementPlugin(initializerContext); | ||
| } | ||
|
|
||
| export { EngagementPluginSetup, EngagementPluginStart } from './types'; | ||
| export { EngagementChat, LazyEngagementChat } from './components'; |
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.
Uh oh!
There was an error while loading. Please reload this page.