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

[Enterprise Search] Convert our public_url route to config_data and collect initialAppData #75616

Merged
merged 10 commits into from
Aug 21, 2020

Conversation

cee-chen
Copy link
Member

Summary

TL;DR of changes (or, follow along by commit):

  • Removes public_url API route in favor of new config_data route
  • Updates callEnterpriseSearchConfigAPI to account for new (expected) data
  • Passes down this fetched initial data as props to the WS & AS apps
  • Moves Kea <Provider> to a top-level wrapper and correctly resets state between AS<->WS navigation
  • Adds a very basic/initial AppLogic store in AS, mostly to confirm that Kea works as expected

QA

  • Go to http://localhost:5601/api/enterprise_search/config_data and confirm the new expected data loads (w/ falsey fallbacks, since that data doesn't exist yet)
  • Add a console.log('hasInitialized', hasInitialized); to public/applications/app_search/index.tsx (line 55 or so) and confirm that it updates to true and stays true when navigating within App Search pages

Checklist

@cee-chen cee-chen added Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Aug 20, 2020
Comment on lines +7 to +19
export interface IAccount {
id: string;
groups: string[];
isAdmin: boolean;
isCurated: boolean;
canCreatePersonalSources: boolean;
viewedOnboardingPage: boolean;
}

export interface IOrganization {
name: string;
defaultOrgName: string;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@scottybollinger FYI that I moved Workplace Search's IAccount/IOrganization types here (since both public/ and server/ files use it).

Also note that I deleted IUser, since we're no longer showing current user data (Kibana does that for us)

@@ -24,7 +24,6 @@ const account = {
isAdmin: true,
canCreatePersonalSources: true,
groups: [],
supportEligible: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

@scottybollinger Another heads up that I also deleted this, it doesn't seem to be in the initial AppLogic API spec and I don't see it used anywhere in ent-search either

Comment on lines -9 to -15
import { Provider } from 'react-redux';
import { Store } from 'redux';
import { getContext, resetContext } from 'kea';

resetContext({ createStore: true });

const store = getContext().store as Store;
Copy link
Member Author

Choose a reason for hiding this comment

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

Another heads up to WS that this was moved to the top-level public/applications/index.tsx

- DRYs out repeated code
- This will be used by an upcoming server/ endpoint change, hence why it's in common
- In preparation for upcoming server logic that will need to reuse these types
+ DRY out and clean up workplace_search types
  - remove unused supportEligible
  - remove currentUser - unneeded in Kibana
… API from public/plugin

+ set returned initialData in this.data
- resetContext at the top level only gets called once total on first plugin load and never after, causing navigating between WS and AS to crash when both have Kea - this fixes the issue

- moves redux Provider to top level app as well
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
enterpriseSearch 197 +1 196

async chunks size

id value diff baseline
enterpriseSearch 342.5KB -16.9KB 359.4KB

page load bundle size

id value diff baseline
enterpriseSearch 21.8KB +561.0B 21.2KB

History

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

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.

This all seems reasonable to me. I have no concerns.

* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('kea', () => ({
Copy link
Member

Choose a reason for hiding this comment

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

Good call making this a common mock

@@ -14,6 +14,7 @@ import { mockLicenseContext } from './license_context.mock';
jest.mock('react', () => ({
...(jest.requireActual('react') as object),
useContext: jest.fn(() => ({ ...mockKibanaContext, ...mockLicenseContext })),
useEffect: jest.fn((fn) => fn()), // Calls on mount/every update - use mount for more complex behavior
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why you are mocking useEffect for shallow rendering?

Copy link
Member Author

Choose a reason for hiding this comment

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

So that these lines in app_search/index.tsx run in the test:

useEffect(() => {
if (!hasInitialized) initializeAppData(props);
}, [hasInitialized]);

Unfortunately Enzyme doesn't yet call useEffect() in shallow() so we have to kind of stub it ourselves. It's not perfect however since it ignores the [changeOnThisVar] array that you can pass into useEffect - if you want to really granularly test that, you'll have to use mount().

It's OK however in this case because I just want to check that initializeAppData was called on mount.

@cee-chen
Copy link
Member Author

@scottybollinger - I know you're out today so apologies if I'm merging anything too quickly with changes that WS didn't want - feel free to let me know next week and I can revert or make changes as needed!

@cee-chen cee-chen merged commit 172c464 into elastic:master Aug 21, 2020
@cee-chen cee-chen deleted the public-url-to-config-data branch August 21, 2020 16:02
cee-chen pushed a commit that referenced this pull request Aug 21, 2020
…nd collect initialAppData (#75616) (#75667)

* [Setup] DRY out stripTrailingSlash helper

- DRYs out repeated code
- This will be used by an upcoming server/ endpoint change, hence why it's in common

* [Setup] DRY out initial app data types to common/types

- In preparation for upcoming server logic that will need to reuse these types
+ DRY out and clean up workplace_search types
  - remove unused supportEligible
  - remove currentUser - unneeded in Kibana

* Update callEnterpriseSearchConfigAPI to parse and fetch new expected data

* Remove /public_url API for /config_data

* Remove getPublicUrl in favor of directly calling the new /config_data API from public/plugin

+ set returned initialData in this.data

* Set up product apps to be passed initial data as props

* Fix for Kea/redux state not resetting between AS<->WS nav

- resetContext at the top level only gets called once total on first plugin load and never after, causing navigating between WS and AS to crash when both have Kea - this fixes the issue

- moves redux Provider to top level app as well

* Add very basic Kea logic file to App Search

* Finish AppSearchConfigured tests & set up kea+useEffect mocks

* [Cleanup] DRY out repeated mock initialAppData to a reusable defaults constant
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 21, 2020
* master: (71 commits)
  [Lens] Show 'No data for this field' for empty field in accordion (elastic#73772)
  Skip failing lens test
  Configure ScopedHistory consistenty regardless of URL used to mount app (elastic#75074)
  Fix returned payload by "search" usage collector (elastic#75340)
  [Security Solution] Fix missing key error (elastic#75576)
  Upgrade EUI to v27.4.1 (elastic#75240)
  Update datasets UI copy to data streams (elastic#75618)
  [Lens] Register saved object references (elastic#74523)
  [DOCS] Update links to Beats documentation (elastic#70380)
  [Enterprise Search] Convert our `public_url` route to `config_data` and collect initialAppData (elastic#75616)
  [Usage Collection Schemas] Remove Legacy entries (elastic#75652)
  [Dashboard First] Lens Originating App Breadcrumb (elastic#75470)
  Improve login UI error message. (elastic#75642)
  [Security Solution] modify circular deps checker to output images of circular deps graphs (elastic#75579)
  [Data Telemetry] Add index pattern to identify "meow" attacks (elastic#75163)
  Migrate CSP usage collector to `kibana_usage_collection` plugin (elastic#75536)
  [Console] Get ES Config from core (elastic#75406)
  [Uptime] Add delay in telemetry test (elastic#75162)
  [Lens] Use index pattern service instead saved object client (elastic#74654)
  Embeddable input (elastic#73033)
  ...
export interface IInitialAppData {
readOnlyMode?: boolean;
ilmEnabled?: boolean;
configuredLimits?: IConfiguredLimits;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this top-level and not nested under appSearch?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe Oleksiy mentioned that Workplace Search either uses configurable limits as well (possibly in the back-end) or may, in the future, add more configurable limits to the front-end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants