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

[Graph] Shim plugin #47469

Merged
merged 19 commits into from
Oct 25, 2019
Merged

[Graph] Shim plugin #47469

merged 19 commits into from
Oct 25, 2019

Conversation

flash1293
Copy link
Contributor

This PR shims the Graph app plugin while still using angular under the hood by pulling in angular dependencies from the global angular and initializing some services itself again in the app-local angular.

@flash1293 flash1293 added Feature:Graph Graph application feature v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Oct 7, 2019
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

No review so far, just a note, that I currently can't log in with this PR. In Chrome there's an endless redirect. In Safari if've got the following in my logs:
server log [15:41:02.010] [warning][server][Kibana][cookie-session-storage][http] Found 2 auth sessions when we were only expecting 1.

@flash1293
Copy link
Contributor Author

@kertal My bad, the Graph app was loaded twice due to an experiment I failed to clean up.

@flash1293 flash1293 changed the title [Graph] [skip ci] Shim plugin [Graph] Shim plugin Oct 16, 2019
@kertal
Copy link
Member

kertal commented Oct 16, 2019

@flash1293 works now 👍

@flash1293
Copy link
Contributor Author

Jenkins, test this.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -67,7 +67,7 @@ export function* extractCodeMessages(buffer, reporter) {
try {
ast = parse(buffer.toString(), {
sourceType: 'module',
plugins: ['jsx', 'typescript', 'objectRestSpread', 'classProperties', 'asyncGenerators'],
plugins: ['jsx', 'typescript', 'objectRestSpread', 'classProperties', 'asyncGenerators', 'dynamicImport'],
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 is necessary to support dynamic imports via await import(...

@@ -24,7 +24,7 @@ import { TopNavMenu } from '../../../core_plugins/kibana_react/public';

const module = uiModules.get('kibana');

module.directive('kbnTopNav', () => {
export function createTopNavDirective() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

exporting the directive definition as a module export to be able to put it in a separate angular module with a different name. This is done to use existing code like this one but make sure it's not using any dependencies from the global angular instance

) => {
const urlOverflow = new UrlOverflowService();
const check = () => {
// disable long url checks when storing state in session storage
if (config.get('state:storeInSessionStorage')) {
if (newPlatform.uiSettings.get('state:storeInSessionStorage')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't use config in here to avoid having to initialize it.

// one cache/swaps per Provider
const cache = {};
const swaps = {};
export function PrivateProvider() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as for the top nav directive. Private isn't used in this PR but it will become necessary for shimming discover and others in the same style

@flash1293 flash1293 marked this pull request as ready for review October 18, 2019 12:17
@flash1293 flash1293 requested a review from a team October 18, 2019 12:17
@flash1293 flash1293 requested a review from a team as a code owner October 18, 2019 12:17
@flash1293 flash1293 requested review from joshdover and Bamieh October 18, 2019 12:18
@flash1293 flash1293 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Oct 18, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@joshdover
Copy link
Contributor

ack: will review tomorrow

Copy link
Member

@mistic mistic left a comment

Choose a reason for hiding this comment

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

The changes within respect to the operations team LGTM

@kertal kertal self-requested a review October 22, 2019 08:49
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested locally in Chrome! I salute 🥁 your angular mastership!

core: CoreStart,
{ data, npData, __LEGACY: { angularDependencies } }: GraphPluginStartDependencies
) {
// TODO is this really the right way? I though the app context would give us those
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 know if this is the right way, but I'm sure @joshdover knows

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, the app mount context in the Legacy compatibility layer can't support plugins, only core services at this time. We could solve this by implementing the bindServices proposal I've added in #46483 (comment) is still being debated, but we're making a decision on this by next week).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussion is still ongoing, I would like to go forward with this solution - it will definitely work and when we decide on another convention we can easily adjust it here.

return $injector;
}

function createLocalAngularModule(core: AppMountContext['core']) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: since core is not used, it can be removed, also you could directly return the modules without graphAngularModule

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

This is looking fantastic 👍

core: CoreStart,
{ data, npData, __LEGACY: { angularDependencies } }: GraphPluginStartDependencies
) {
// TODO is this really the right way? I though the app context would give us those
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, the app mount context in the Legacy compatibility layer can't support plugins, only core services at this time. We could solve this by implementing the bindServices proposal I've added in #46483 (comment) is still being debated, but we're making a decision on this by next week).

indexPatterns: DataStart['indexPatterns']['indexPatterns'];
npData: ReturnType<DataPlugin['start']>;
savedObjectsClient: SavedObjectsClientContract;
xpackInfo: { get(path: string): unknown };
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this can be replaced by #44922 once it is complete (just an FYI)

this.dataStart = data;
this.npDataStart = npData;
this.angularDependencies = angularDependencies;
this.savedObjectsClient = core.savedObjects.client;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be able to get this from contextCore in the mount function above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least not in the types - the AppMountContext['core'] seems to be a subset of CoreStart: src/core/public/application/types.ts line 100, and savedObjects is not there.


export const renderApp = ({ appBasePath, element, ...deps }: GraphDependencies) => {
const graphAngularModule = createLocalAngularModule(deps.coreStart);
configureAppAngularModule(graphAngularModule);
Copy link
Contributor

Choose a reason for hiding this comment

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

Really happy this turned out useful...spent a lot of time breaking this out only to wonder if we would use it.

That said, we need to spend some time removing some of the legacy dependencies that this module uses. Doesn't look like there's too much:

import { fatalError } from 'ui/notify';
import { capabilities } from 'ui/capabilities';
import { modifyUrl } from 'ui/url';
import { UrlOverflowService } from '../error_url_overflow';
import { toastNotifications } from '../notify';
import { isSystemApiRequest } from '../system_api';

We should also make this function take CoreStart as an argument rather than importing it via ui/new_platform.

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 have to check but it might be sufficient to just pull in the necessary parts - it looks like Graph only really needs the badges handling and even that could probably be moved to the controller. It's probably not so simple for the Kibana app apps though, so still worth thinking about this.

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 worked on this in the dashboard shim PR - are you fine with leaving this as it is for now and we'll fix it there?

@elasticmachine
Copy link
Contributor

💔 Build Failed

@flash1293
Copy link
Contributor Author

Jenkins, test this. Failure looks unrelated.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@flash1293 flash1293 merged commit 82d5447 into elastic:master Oct 25, 2019
flash1293 added a commit to flash1293/kibana that referenced this pull request Oct 25, 2019
flash1293 added a commit that referenced this pull request Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Graph Graph application feature Feature:NP Migration release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants