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

Discussion. Example: registry to NP #37310

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

import { FunctionsRegistry } from '../../common/functions_registry';
import { getNewPlatform } from '../../../../ui/public/new_platform';

export const functionsRegistry = new FunctionsRegistry();
export const functionsRegistry = getNewPlatform().setup.plugins.interpreter.functionsRegistry;
2 changes: 1 addition & 1 deletion src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function __newPlatformStart__(
}

export function getNewPlatform() {
if (runtimeContext.setup.core === null || runtimeContext.start.core === null) {
if (runtimeContext.setup.core === null /* || runtimeContext.start.core === null */) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding was that platform loading follows

NP setup -> NP start -> legacy platform

but for some reason when legacy runs runtimeContext.start.core is still null.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be resolved before merging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to merge this PR, I should have made it as a Draft. I guess, this is just an example of moving one Interpreter registry, but I am looking into moving way bigger chunk of Interpreter, as it does not have many dependencies.

But in general this runtimeContext.start.core must be addressed somehow. For moving registries we don't need runtimeContext.start.core, but kibana-react will probably need runtimeContext.start.core in legacy world.

throw new Error('runtimeContext is not initialized yet');
}

Expand Down
8 changes: 8 additions & 0 deletions src/plugins/interpreter/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "interpreter",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["core", "interpreter"],
"server": false,
"ui": true
}
30 changes: 30 additions & 0 deletions src/plugins/interpreter/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { FunctionsRegistry } from './registries';

export const plugin = () => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to know!
And then things can be imported statically from the top level of the plugin.

setup: () => {
const functionsRegistry = new FunctionsRegistry();
return {
functionsRegistry,
};
},
start: () => {},
});
27 changes: 27 additions & 0 deletions src/plugins/interpreter/public/registries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Registry } from '@kbn/interpreter/common';
const { Fn } = require('@kbn/interpreter/common'); // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this line use require instead of an import statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because Fn does not appear in TypeScript .d.ts, I believe, in @kbn/interpreter/common, so it complains.


export class FunctionsRegistry extends Registry<any, any> {
wrapper(obj: any) {
return new Fn(obj);
}
}