-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[App Search] Add a Sample Engine CTA panel to the engines table when empty #94647
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
500ac52
Added new onboarding complete route for App Search
byronhulcher 1cd26f1
Allow responses without JSON bodies in Enterprise Search
byronhulcher 0e5d075
New SampleEngineCreationCtaLogic
byronhulcher d0877ef
New SampleEngineCreationCta component
byronhulcher 7924d22
Add SampleEngineCreationCTA to engines EmptyState
byronhulcher 01a6c8d
Improve SampleEngineCreationCta
byronhulcher 0b052db
Fix spelling error in Enterprise Search request handler test
byronhulcher 7aac42c
Improve SampleEngineCreationCtaLogic
byronhulcher c698f9b
Merge remote-tracking branch 'origin/master' into demo-engine-cta
byronhulcher 6ce7cf0
Merge remote-tracking branch 'origin/master' into demo-engine-cta
byronhulcher 13c9801
Fix types
byronhulcher a117565
Fix tests after origin/master merge
byronhulcher 522a82a
Turns out I 'fixed' my tests by removing this test
byronhulcher 3f17722
Merge branch 'master' into demo-engine-cta
kibanamachine 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
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
29 changes: 29 additions & 0 deletions
29
...prise_search/public/applications/app_search/components/sample_engine_creation_cta/i18n.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,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 { i18n } from '@kbn/i18n'; | ||
|
|
||
| export const SAMPLE_ENGINE_CREATION_CTA_TITLE = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.sampleEngineCreationCta.title', | ||
| { | ||
| defaultMessage: 'Just kicking the tires?', | ||
| } | ||
| ); | ||
|
|
||
| export const SAMPLE_ENGINE_CREATION_CTA_DESCRIPTION = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.sampleEngineCreationCta.description', | ||
| { | ||
| defaultMessage: 'Test an engine with sample data.', | ||
| } | ||
| ); | ||
|
|
||
| export const SAMPLE_ENGINE_CREATION_CTA_BUTTON_LABEL = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.sampleEngineCreationCta.buttonLabel', | ||
| { | ||
| defaultMessage: 'Try a sample engine', | ||
| } | ||
| ); | ||
8 changes: 8 additions & 0 deletions
8
...rise_search/public/applications/app_search/components/sample_engine_creation_cta/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,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 { SampleEngineCreationCta } from './sample_engine_creation_cta'; |
57 changes: 57 additions & 0 deletions
57
...ions/app_search/components/sample_engine_creation_cta/sample_engine_creation_cta.test.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,57 @@ | ||
| /* | ||
| * 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 '../../../__mocks__/enterprise_search_url.mock'; | ||
| import { setMockActions, setMockValues } from '../../../__mocks__'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import { shallow } from 'enzyme'; | ||
|
|
||
| import { EuiButton } from '@elastic/eui'; | ||
|
|
||
| import { SampleEngineCreationCta } from './sample_engine_creation_cta'; | ||
|
|
||
| describe('SampleEngineCTA', () => { | ||
| describe('CTA button', () => { | ||
| const MOCK_VALUES = { | ||
| isLoading: false, | ||
| }; | ||
|
|
||
| const MOCK_ACTIONS = { | ||
| createSampleEngine: jest.fn(), | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| setMockActions(MOCK_ACTIONS); | ||
| setMockValues(MOCK_VALUES); | ||
| }); | ||
|
|
||
| it('calls createSampleEngine on click', () => { | ||
| const wrapper = shallow(<SampleEngineCreationCta />); | ||
| const ctaButton = wrapper.find(EuiButton); | ||
|
|
||
| expect(ctaButton.props().onClick).toEqual(MOCK_ACTIONS.createSampleEngine); | ||
| }); | ||
|
|
||
| it('is enabled by default', () => { | ||
| const wrapper = shallow(<SampleEngineCreationCta />); | ||
| const ctaButton = wrapper.find(EuiButton); | ||
|
|
||
| expect(ctaButton.props().isLoading).toEqual(false); | ||
| }); | ||
|
|
||
| it('is disabled while loading', () => { | ||
| setMockValues({ ...MOCK_VALUES, isLoading: true }); | ||
| const wrapper = shallow(<SampleEngineCreationCta />); | ||
| const ctaButton = wrapper.find(EuiButton); | ||
|
|
||
| expect(ctaButton.props().isLoading).toEqual(true); | ||
| }); | ||
| }); | ||
| }); |
44 changes: 44 additions & 0 deletions
44
...lications/app_search/components/sample_engine_creation_cta/sample_engine_creation_cta.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,44 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
|
|
||
| import { useActions, useValues } from 'kea'; | ||
|
|
||
| import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiTitle, EuiText, EuiButton } from '@elastic/eui'; | ||
|
|
||
| import { | ||
| SAMPLE_ENGINE_CREATION_CTA_TITLE, | ||
| SAMPLE_ENGINE_CREATION_CTA_DESCRIPTION, | ||
| SAMPLE_ENGINE_CREATION_CTA_BUTTON_LABEL, | ||
| } from './i18n'; | ||
| import { SampleEngineCreationCtaLogic } from './sample_engine_creation_cta_logic'; | ||
|
|
||
| export const SampleEngineCreationCta: React.FC = () => { | ||
| const { isLoading } = useValues(SampleEngineCreationCtaLogic); | ||
| const { createSampleEngine } = useActions(SampleEngineCreationCtaLogic); | ||
|
|
||
| return ( | ||
| <EuiPanel> | ||
| <EuiFlexGroup alignItems="center"> | ||
| <EuiFlexItem> | ||
| <EuiTitle size="s"> | ||
| <h3>{SAMPLE_ENGINE_CREATION_CTA_TITLE}</h3> | ||
| </EuiTitle> | ||
| <EuiText size="s"> | ||
| <p>{SAMPLE_ENGINE_CREATION_CTA_DESCRIPTION}</p> | ||
| </EuiText> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButton onClick={createSampleEngine} isLoading={isLoading}> | ||
| {SAMPLE_ENGINE_CREATION_CTA_BUTTON_LABEL} | ||
| </EuiButton> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiPanel> | ||
| ); | ||
| }; |
92 changes: 92 additions & 0 deletions
92
...app_search/components/sample_engine_creation_cta/sample_engine_creation_cta_logic.test.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,92 @@ | ||
| /* | ||
| * 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 { | ||
| LogicMounter, | ||
| mockHttpValues, | ||
| mockKibanaValues, | ||
| mockFlashMessageHelpers, | ||
| } from '../../../__mocks__'; | ||
|
|
||
| import { nextTick } from '@kbn/test/jest'; | ||
|
|
||
| import { SampleEngineCreationCtaLogic } from './sample_engine_creation_cta_logic'; | ||
|
|
||
| describe('SampleEngineCreationCtaLogic', () => { | ||
| const { mount } = new LogicMounter(SampleEngineCreationCtaLogic); | ||
| const { http } = mockHttpValues; | ||
| const { navigateToUrl } = mockKibanaValues; | ||
| const { setQueuedSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers; | ||
|
|
||
| const DEFAULT_VALUES = { | ||
| isLoading: false, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mount(); | ||
| }); | ||
|
|
||
| it('has expected default values', () => { | ||
| expect(SampleEngineCreationCtaLogic.values).toEqual(DEFAULT_VALUES); | ||
| }); | ||
|
|
||
| describe('actions', () => { | ||
| it('onSampleEngineCreationFailure sets isLoading to false', () => { | ||
| mount({ isLoading: true }); | ||
|
|
||
| SampleEngineCreationCtaLogic.actions.onSampleEngineCreationFailure(); | ||
|
|
||
| expect(SampleEngineCreationCtaLogic.values.isLoading).toEqual(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('listeners', () => { | ||
| describe('createSampleEngine', () => { | ||
| it('POSTS to /api/app_search/engines', () => { | ||
| const body = JSON.stringify({ | ||
| seed_sample_engine: true, | ||
| }); | ||
| SampleEngineCreationCtaLogic.actions.createSampleEngine(); | ||
|
|
||
| expect(http.post).toHaveBeenCalledWith('/api/app_search/onboarding_complete', { body }); | ||
| }); | ||
|
|
||
| it('calls onSampleEngineCreationSuccess on valid submission', async () => { | ||
| jest.spyOn(SampleEngineCreationCtaLogic.actions, 'onSampleEngineCreationSuccess'); | ||
| http.post.mockReturnValueOnce(Promise.resolve({})); | ||
|
|
||
| SampleEngineCreationCtaLogic.actions.createSampleEngine(); | ||
| await nextTick(); | ||
|
|
||
| expect( | ||
| SampleEngineCreationCtaLogic.actions.onSampleEngineCreationSuccess | ||
| ).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('calls onSampleEngineCreationFailure and flashAPIErrors on API Error', async () => { | ||
| jest.spyOn(SampleEngineCreationCtaLogic.actions, 'onSampleEngineCreationFailure'); | ||
| http.post.mockReturnValueOnce(Promise.reject()); | ||
|
|
||
| SampleEngineCreationCtaLogic.actions.createSampleEngine(); | ||
| await nextTick(); | ||
|
|
||
| expect(flashAPIErrors).toHaveBeenCalledTimes(1); | ||
| expect( | ||
| SampleEngineCreationCtaLogic.actions.onSampleEngineCreationFailure | ||
| ).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
|
|
||
| it('onSampleEngineCreationSuccess should set a success message and navigate the user to the engine page', () => { | ||
| SampleEngineCreationCtaLogic.actions.onSampleEngineCreationSuccess(); | ||
|
|
||
| expect(setQueuedSuccessMessage).toHaveBeenCalledWith('Successfully created engine.'); | ||
| expect(navigateToUrl).toHaveBeenCalledWith('/engines/national-parks-demo'); | ||
| }); | ||
| }); | ||
| }); |
72 changes: 72 additions & 0 deletions
72
...ions/app_search/components/sample_engine_creation_cta/sample_engine_creation_cta_logic.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,72 @@ | ||
| /* | ||
| * 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 { generatePath } from 'react-router-dom'; | ||
|
|
||
| import { kea, MakeLogicType } from 'kea'; | ||
|
|
||
| import { flashAPIErrors, setQueuedSuccessMessage } from '../../../shared/flash_messages'; | ||
| import { HttpLogic } from '../../../shared/http'; | ||
| import { KibanaLogic } from '../../../shared/kibana'; | ||
| import { ENGINE_PATH } from '../../routes'; | ||
| import { ENGINE_CREATION_SUCCESS_MESSAGE } from '../engine_creation/constants'; | ||
|
|
||
| interface SampleEngineCreationCtaActions { | ||
| createSampleEngine(): void; | ||
| onSampleEngineCreationSuccess(): void; | ||
| onSampleEngineCreationFailure(): void; | ||
| setIsLoading(isLoading: boolean): { isLoading: boolean }; | ||
| } | ||
|
|
||
| interface SampleEngineCreationCtaValues { | ||
| isLoading: boolean; | ||
| } | ||
|
|
||
| export const SampleEngineCreationCtaLogic = kea< | ||
| MakeLogicType<SampleEngineCreationCtaValues, SampleEngineCreationCtaActions> | ||
| >({ | ||
| path: ['enterprise_search', 'app_search', 'sample_engine_cta_logic'], | ||
| actions: { | ||
| createSampleEngine: true, | ||
| onSampleEngineCreationSuccess: true, | ||
| onSampleEngineCreationFailure: true, | ||
| }, | ||
| reducers: { | ||
| isLoading: [ | ||
| false, | ||
| { | ||
| createSampleEngine: () => true, | ||
| onSampleEngineCreationSuccess: () => false, | ||
| onSampleEngineCreationFailure: () => false, | ||
| }, | ||
| ], | ||
| }, | ||
| listeners: ({ actions }) => ({ | ||
| createSampleEngine: async () => { | ||
| const { http } = HttpLogic.values; | ||
|
|
||
| const body = JSON.stringify({ seed_sample_engine: true }); | ||
|
|
||
| try { | ||
| await http.post('/api/app_search/onboarding_complete', { | ||
| body, | ||
| }); | ||
| actions.onSampleEngineCreationSuccess(); | ||
| } catch (e) { | ||
| actions.onSampleEngineCreationFailure(); | ||
| flashAPIErrors(e); | ||
| } | ||
| }, | ||
| onSampleEngineCreationSuccess: () => { | ||
| const { navigateToUrl } = KibanaLogic.values; | ||
| const enginePath = generatePath(ENGINE_PATH, { engineName: 'national-parks-demo' }); | ||
|
|
||
| setQueuedSuccessMessage(ENGINE_CREATION_SUCCESS_MESSAGE); | ||
| navigateToUrl(enginePath); | ||
| }, | ||
| }), | ||
| }); |
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.
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.
Looks like this is a pattern used elsewhere in Kibana, so I'm good with it.
Ping for awareness of this pattern, @constancecchen.
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.
This pattern being "a seperate i18n.ts file", right?
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.
Yes.