[App Search] Add a Sample Engine CTA panel to the engines table when empty#94647
[App Search] Add a Sample Engine CTA panel to the engines table when empty#94647byronhulcher merged 14 commits intoelastic:masterfrom
Conversation
a758024 to
e4dc73f
Compare
e4dc73f to
e9e44ca
Compare
e9e44ca to
7924d22
Compare
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| export const SAMPLE_ENGINE_CREATION_CTA_TITLE = i18n.translate( |
There was a problem hiding this comment.
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.
This pattern being "a seperate i18n.ts file", right?
JasonStoltz
left a comment
There was a problem hiding this comment.
A couple of suggestions to consider
| }); | ||
|
|
||
| it('calls createSampleEngine on click', () => { | ||
| const wrapper = mountWithIntl(<SampleEngineCreationCta />); |
There was a problem hiding this comment.
You only need to use mountWithIntl if you are using FormattedMessage. I believe you could shallow in this file.
| expect(ctaButton.props().onClick).toEqual(MOCK_ACTIONS.createSampleEngine); | ||
| }); | ||
|
|
||
| it('by default enabled', () => { |
There was a problem hiding this comment.
[optional] I don't always get this right either, but it's nice to make tests read like sentences.
"CTA button is enabled by default" as opposed to "CTA button by default enabled"
| const { createSampleEngine } = useActions(SampleEngineCreationCtaLogic); | ||
|
|
||
| return ( | ||
| <EuiPanel data-test-subj="SampleEngineCreationCta"> |
There was a problem hiding this comment.
I don't think this data-test-subj, or the one further down in this file are used anywhere. I suggest removing them.
| }); | ||
|
|
||
| afterAll(() => { | ||
| jest.clearAllMocks(); |
There was a problem hiding this comment.
I suggest moving this to a beforeEach so that your tests are isolated from each other. As it is now you could be asserting expect(flashAPIErrors).toHaveBeenCalledTimes(1) in one test and have it pass, even if it was called in a previous test.
| actions: { | ||
| createSampleEngine: true, | ||
| onSampleEngineCreationSuccess: true, | ||
| setIsLoading: (isLoading) => ({ isLoading }), |
There was a problem hiding this comment.
Actions like this are generally an anti-pattern in Kea.
It is so pervasive in our code that I generally ignore it in reviews. However, since this logic is small (and new?) I want to point it out. When we design logic files we should keep this mind.
The preferable way to do this is:
actions: {
createSampleEngine: true,
onSampleEngineCreationSuccess: true,
onSampleEngineCreationFailure: true,
},
reducers: {
isLoading: [
false,
{
createSampleEngine: () => true,
onSampleEngineCreationSuccess: () => false,
onSampleEngineCreationFailure: () => false,
},
],
},
....
try {
await http.post('/api/app_search/onboarding_complete', {
body,
});
actions.onSampleEngineCreationSuccess();
} catch (e) {
actions.onSampleEngineCreationFailure();
flashAPIErrors(e);
}
There was a problem hiding this comment.
I actually like this a lot more!
There was a problem hiding this comment.
Sweet. And just FYI, after re-reading this I don't know if I was totally clear about what the anti-pattern is. From that link:
If you read the reducers section above, you'll remember that it's an anti-pattern to only have setThis and setThat actions that only update this or that.
A helpful mental model to understand actions is the one of events in computer programming.
This is something I've mentioned on a couple of PRs previously, but would be new to you:
Some lengthy discussion in that second link! I lay out what I perceive as the benefits there.
| }); | ||
| }); | ||
|
|
||
| it('works if resposne contains no json data', async () => { |
There was a problem hiding this comment.
| it('works if resposne contains no json data', async () => { | |
| it('works if response contains no json data', async () => { |
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
…empty (elastic#94647) * Added new onboarding complete route for App Search * Allow responses without JSON bodies in Enterprise Search * New SampleEngineCreationCtaLogic * New SampleEngineCreationCta component * Add SampleEngineCreationCTA to engines EmptyState * Improve SampleEngineCreationCta * Fix spelling error in Enterprise Search request handler test * Improve SampleEngineCreationCtaLogic * Fix types * Fix tests after origin/master merge * Turns out I 'fixed' my tests by removing this test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…empty (#94647) (#95766) * Added new onboarding complete route for App Search * Allow responses without JSON bodies in Enterprise Search * New SampleEngineCreationCtaLogic * New SampleEngineCreationCta component * Add SampleEngineCreationCTA to engines EmptyState * Improve SampleEngineCreationCta * Fix spelling error in Enterprise Search request handler test * Improve SampleEngineCreationCtaLogic * Fix types * Fix tests after origin/master merge * Turns out I 'fixed' my tests by removing this test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Summary
Migrates over the Sample Engine CTA from the old repository. This encourages users to get up and running quickly in App Search by using our national parks demo dataset.
Screenshots
QA
national-parks-demoengineChecklist
Delete any items that are not applicable to this PR.