-
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
Separate config and service provided data
- Loading branch information
commit 76f1cbe73cd6bafa6d84d99bb2a1ce27efadd4e5
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,16 @@ import React from 'react'; | |
| import { DecoratorFn } from '@storybook/react'; | ||
| import { getSharedUXContextProvider } from '../../shared_ux/.storybook/decorators'; | ||
| import { ServicesProvider } from '../public/services'; | ||
| import type { EngagementServices } from '../public/services'; | ||
|
|
||
| // TODO: move to a storybook implementation of the service using parameters. | ||
| const config = { | ||
| const services: EngagementServices = { | ||
| chat: { | ||
| enabled: true, | ||
| chatURL: 'https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html', | ||
| pocID: '53877975', | ||
| pocEmail: '[email protected]', | ||
| pocJWT: | ||
| userID: '53877975', | ||
| userEmail: '[email protected]', | ||
| identityJWT: | ||
| 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Mzg3Nzk3NSIsImV4cCI6MTY0MjUxNDc0Mn0.CcAZbD8R865UmoHGi27wKn0aH1bzkZXhX449yyDH2Vk', | ||
| }, | ||
| }; | ||
|
|
@@ -36,4 +37,4 @@ export const getEngagementContextDecorator: DecoratorFn = (storyFn, context) => | |
| export const getEngagementContextProvider: () => React.FC = | ||
| () => | ||
| ({ children }) => | ||
| <ServicesProvider {...config}>{children}</ServicesProvider>; | ||
| <ServicesProvider {...services}>{children}</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
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 |
|---|---|---|
|
|
@@ -7,25 +7,25 @@ | |
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { ServicesProvider } from '../public/services'; | ||
| import { ServicesProvider, EngagementServices } from '../public/services'; | ||
| import { EngagementPluginSetup, EngagementPluginStart } from './types'; | ||
|
|
||
| // TODO: move to a storybook implementation of the service using parameters. | ||
| const config = { | ||
| const services: EngagementServices = { | ||
| chat: { | ||
| enabled: true, | ||
| chatURL: 'https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html', | ||
| pocID: '53877975', | ||
| pocEmail: '[email protected]', | ||
| pocJWT: | ||
| userID: '53877975', | ||
| userEmail: '[email protected]', | ||
| identityJWT: | ||
| 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Mzg3Nzk3NSIsImV4cCI6MTY0MjUxNDc0Mn0.CcAZbD8R865UmoHGi27wKn0aH1bzkZXhX449yyDH2Vk', | ||
| }, | ||
| }; | ||
|
|
||
| const getEngagementContextProvider: () => React.FC = | ||
| () => | ||
| ({ children }) => | ||
| <ServicesProvider {...config}>{children}</ServicesProvider>; | ||
| <ServicesProvider {...services}>{children}</ServicesProvider>; | ||
|
|
||
| const createEngagementPluginSetup = (): jest.Mocked<EngagementPluginSetup> => { | ||
| const mock: jest.Mocked<EngagementPluginSetup> = {}; | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -14,26 +14,26 @@ import type { | |
| EngagementPluginSetupDeps, | ||
| EngagementPluginStartDeps, | ||
| } from './types'; | ||
| import type { EngagementServices } from './services'; | ||
| import { ServicesProvider } from './services'; | ||
|
|
||
| export interface EngagementConfigType { | ||
| chat: { | ||
| enabled: boolean; | ||
| chatURL: string; | ||
|
|
||
| // These are here for PoC purposes *only*. They should be replaced with actual implementations | ||
| // as the PoC matures. | ||
| pocJWT: string; | ||
| pocID: string; | ||
| pocEmail: string; | ||
| }; | ||
| } | ||
|
|
||
| interface ChatUser { | ||
| id: string; | ||
| email: string; | ||
| } | ||
|
|
||
| export class EngagementPlugin | ||
| implements | ||
| Plugin< | ||
| EngagementPluginSetup, | ||
| EngagementPluginStart, | ||
| Promise<EngagementPluginStart>, | ||
| EngagementPluginSetupDeps, | ||
| EngagementPluginStartDeps | ||
| > | ||
|
|
@@ -44,11 +44,37 @@ export class EngagementPlugin | |
| return {}; | ||
| } | ||
|
|
||
| public start(_core: CoreStart, plugins: EngagementPluginStartDeps): EngagementPluginStart { | ||
| private async getChatUser(): Promise<ChatUser | null> { | ||
| // TODO: obtain kibana and/or cloud user information | ||
| return { | ||
| id: 'user-id', | ||
| email: '[email protected]', | ||
| } | ||
| } | ||
|
|
||
| private async getChatIdentityToken(): Promise<string | null> { | ||
| // TODO: fetch identity token from plugin internal endpoint | ||
| return 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Mzg3Nzk3NSIsImV4cCI6MTY0MjUxNDc0Mn0.CcAZbD8R865UmoHGi27wKn0aH1bzkZXhX449yyDH2Vk'; | ||
| } | ||
|
|
||
| public async start(_core: CoreStart, plugins: EngagementPluginStartDeps): Promise<EngagementPluginStart> { | ||
| const { sharedUX } = plugins; | ||
|
|
||
| const user = await this.getChatUser(); | ||
|
|
||
| const chatIdentityToken = await this.getChatIdentityToken(); | ||
|
|
||
| const config = this.initializerContext.config.get<EngagementConfigType>(); | ||
| const chat = config?.chat || { enabled: false }; | ||
|
|
||
| let chat: EngagementServices['chat'] = { enabled: false }; | ||
| if (config.chat.enabled && user && chatIdentityToken) { | ||
| chat = { | ||
| ...config.chat, | ||
| userID: user.id, | ||
| userEmail: user.email, | ||
| identityJWT: chatIdentityToken, | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| ContextProvider: ({ children }) => ( | ||
|
|
||
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
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.
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 need to find a way to obtain a Kibana or Cloud user data here. Particularly we need to get user ID (might be Kibana user's
username) and user email (this should be the same as in Cloud for Cloud users)@pgayvallet maybe you know how to do this?