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

Add ApplicationService Mounting #41007

Merged
merged 20 commits into from
Sep 3, 2019
Merged

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented Jul 12, 2019

Summary

Implements RFC-0004
Related to #18843
Depends on #41251

This adds support for UI applications in the New Platform. With this change, CoreSystem on the frontend now has a "legacy mode" and normal mode.

  • In legacy mode, the ApplicationService does not mount its router on the page and instead gives control to the LegacyService.
  • In normal mode, the ApplicationService mounts its router on the page and controls mounting individual UI apps. The LegacyService does import any legacy code, though it does still provide some data and features to mirror Legacy behaviors.

This mode is toggled by the legacy renderApp function, which serves the bootstrapping page and bundles. When rendering a UI app that is unknown to the legacy platform, this function will instead serve the "core-only" bundle which does not include any legacy code or applications.

New Platform applications currently have some caveats:

Testing

To test the NP application service yourself, unzip these plugins into your plugins directory, run yarn kbn bootstrap, and start Kibana.

Alternatively, you can also start the functional test server with the config that loads some test applications:

node scripts/functional_tests_server.js --config test/plugin_functional/config.js

Dev Docs

Kibana Platform plugins may now register UI applications to display in the global navigation and be mounted inside Kibana as a single-page application. Example:

class MyPlugin {
  public setup(core) {
    core.application.register({
      id: 'myApp',
      async mount(context, params) {
        const { renderApp } = await import('./application');
        return renderApp(context, params);
      }
    });
  }
}

For more details, see the Application Mounting RFC.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@joshdover joshdover added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.4.0 labels Jul 12, 2019
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@joshdover joshdover force-pushed the app-service/mount branch 2 times, most recently from 2b9d376 to e081514 Compare July 12, 2019 20:43
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@joshdover

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@joshdover joshdover force-pushed the app-service/mount branch 2 times, most recently from aed2a1c to 0908cfc Compare August 2, 2019 19:14
@joshdover
Copy link
Contributor Author

@elastic/kibana-platform With the EUI update in, I've updated this to support "open in new tab" correctly. This should be 100% ready now, just looking for approvals.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

core.application.register({
id: 'bar',
title: 'Bar',
async mount(context, params) {
Copy link
Contributor

@mshustov mshustov Aug 28, 2019

Choose a reason for hiding this comment

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

we need to create recommendation how to declare additional properties on context. if we delete this import https://github.com/elastic/kibana/pull/41007/files#diff-73111fdf9de323e24d3cf6695ad53aafR21 context doesn't contain methods provided by dependency. because dependency declaration is not imported

declare module 'kibana/public' {
  interface AppMountContext {...}
}

probably we should recommend declaring context type manually, as we do for deps. in this case plugin will always import a type from dependency and read module declaration.

package.json Outdated Show resolved Hide resolved
src/core/public/application/application_service.test.tsx Outdated Show resolved Hide resolved
src/core/public/application/application_service.tsx Outdated Show resolved Hide resolved
src/core/public/http/http_service.mock.ts Outdated Show resolved Hide resolved
src/core/public/plugins/plugin_context.ts Outdated Show resolved Hide resolved
application: {
capabilities: mockStartDeps.application.capabilities,
},
application: expect.any(Object),
Copy link
Contributor

Choose a reason for hiding this comment

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

what we want to test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm starting to find these tests useless. We're basically just testing that the interface is right...which TS already does. What do you think about removing these assertions completely?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I'm not sure assertion works outside of expect. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jest/index.d.ts#L547-L563 this test uses it when creates a new object
  2. In other places when we test interfaces it's excessive, because TS performs the same check

test/functional/page_objects/common_page.js Outdated Show resolved Hide resolved
src/core/public/application/ui/app_container.tsx Outdated Show resolved Hide resolved
};
}

function isModifiedEvent(event: MouseEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

no tests. I'm not sure that our testing framework supports keyDown + click tho

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 entire UI has no tests when I copied it from legacy. I plan to refactor and cleanup all of this header UI code after this is done.

@joshdover joshdover added v7.5.0 and removed v7.4.0 labels Aug 29, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@joshdover joshdover merged commit b352f67 into elastic:master Sep 3, 2019
@joshdover joshdover deleted the app-service/mount branch September 3, 2019 18:03
joshdover added a commit to joshdover/kibana that referenced this pull request Sep 3, 2019
* Add core-only bundle

* Add ApplicationService mounting

* Add LegacyCore{Setup,Start}

* Fix PR comments

* Add functional tests

* Fix PR comments

* Fix PR comments

* Remove other usages of rootRoute

* Use state field notation

* Add support for open in new tab

* Fix PR comments

* Fix pesky await from the dead

* Update docs

* Bump @types/history
@rayafratkina
Copy link
Contributor

@joshdover can you please add a DevDocs section?

@joshdover
Copy link
Contributor Author

@rayafratkina Done.

@elasticmachine
Copy link
Contributor

💔 Build Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants