Skip to content
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

Merged
merged 14 commits into from
Mar 30, 2021

Conversation

byronhulcher
Copy link
Contributor

@byronhulcher byronhulcher commented Mar 15, 2021

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

image

QA

  1. Spin up Kibana and Enterprise Search
  2. Log in to Enterprise Search, then App Search, and go to the Engines Overview page
  3. Delete any and all existing engines you have, you need to be on the empty state for the Engines Overview page
  • Observe the new CTA as in the screenshot above
  1. Click the button
  • Observe the button goes into a loading/spinner state
  • Observe you are brought to Engine Detail page for the national-parks-demo engine
  • Observe a success message at the top of the page

Checklist

Delete any items that are not applicable to this PR.

@byronhulcher byronhulcher added auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes v7.13.0 labels Mar 15, 2021
@byronhulcher byronhulcher self-assigned this Mar 15, 2021
@byronhulcher byronhulcher force-pushed the demo-engine-cta branch 5 times, most recently from a758024 to e4dc73f Compare March 22, 2021 23:13
@byronhulcher byronhulcher marked this pull request as ready for review March 23, 2021 02:48
@byronhulcher byronhulcher requested review from a team, cee-chen and JasonStoltz and removed request for cee-chen March 23, 2021 02:48

import { i18n } from '@kbn/i18n';

export const SAMPLE_ENGINE_CREATION_CTA_TITLE = i18n.translate(
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member

@JasonStoltz JasonStoltz left a 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 />);
Copy link
Member

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', () => {
Copy link
Member

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">
Copy link
Member

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();
Copy link
Member

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 }),
Copy link
Member

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);
      }

Copy link
Contributor Author

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!

Copy link
Member

@JasonStoltz JasonStoltz Mar 24, 2021

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:

#83353 (comment)

#86822 (review)

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 () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('works if resposne contains no json data', async () => {
it('works if response contains no json data', async () => {

Copy link
Member

@JasonStoltz JasonStoltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@byronhulcher
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
enterpriseSearch 1290 1293 +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 2.0MB 2.0MB +4.6KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @byronhulcher

@byronhulcher byronhulcher merged commit e91d0d4 into elastic:master Mar 30, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Mar 30, 2021
…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 <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

7.x / #95766

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Mar 30, 2021
…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 <[email protected]>

Co-authored-by: Byron Hulcher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants