-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[App Search] Add a Sample Engine CTA panel to the engines table when empty #94647
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.
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.
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.
A couple of suggestions to consider
}); | ||
|
||
it('calls createSampleEngine on click', () => { | ||
const wrapper = mountWithIntl(<SampleEngineCreationCta />); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like this a lot more!
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.
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.
@@ -198,6 +198,18 @@ describe('EnterpriseSearchRequestHandler', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
it('works if resposne contains no json data', async () => { |
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.
it('works if resposne contains no json data', async () => { | |
it('works if response contains no json data', async () => { |
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.
Nice work!
@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-demo
engineChecklist
Delete any items that are not applicable to this PR.