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

[uiApp] replace uiApp.injectVars with server.injectUiAppVars() #17485

Merged
merged 8 commits into from
Apr 6, 2018

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Mar 30, 2018

Fixes #17483

With #17474 we will be moving the configuration for uiApp specs to the browser which means they can no longer include functions like injectVars() which expect to be run on the server. Instead we need to expose hooks into the ui_render module that provide similar functionality.

The new API is:

server.injectUiAppVars('kibana', () => ({
  someConfigVar: server.config().get('kibana.someConfigVar')
}))

Long term we will probably want to get rid of this API entirely, perhaps replacing most existing uses with a static map of configuration values from kibana.yml that should be injected into a uiPlugin, but that requires more planning and thought than I want to put into this at this time.

@spalger spalger added WIP Work in progress Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.0.0 v6.3.0 labels Mar 30, 2018
@spalger spalger force-pushed the remove/uiApp/injectedVars branch 3 times, most recently from 8a2f4aa to 09a262c Compare March 30, 2018 23:28
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@spalger spalger added review and removed WIP Work in progress labels Apr 4, 2018
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -29,4 +29,18 @@ export function uiAppsMixin(kbnServer, server) {
server.decorate('server', 'getAllUiApps', () => kbnServer.uiApps.slice(0));
server.decorate('server', 'getUiAppById', id => appsById.get(id));
server.decorate('server', 'getHiddenUiAppById', id => hiddenAppsById.get(id));

const injectedVarProviders = [];
server.decorate('server', 'injectUiAppVars', function (id, provider) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: arrow function maybe?


const injectedVarProviders = [];
server.decorate('server', 'injectUiAppVars', function (id, provider) {
injectedVarProviders.push({ id, provider, });
Copy link
Member

Choose a reason for hiding this comment

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

question: we use trailing commas even if all properties are on the same line?

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 gone in to remove that like four times :P

@@ -29,4 +29,18 @@ export function uiAppsMixin(kbnServer, server) {
server.decorate('server', 'getAllUiApps', () => kbnServer.uiApps.slice(0));
server.decorate('server', 'getUiAppById', id => appsById.get(id));
server.decorate('server', 'getHiddenUiAppById', id => hiddenAppsById.get(id));

const injectedVarProviders = [];
server.decorate('server', 'injectUiAppVars', function (id, provider) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe we can use more descriptive name for id here and in the function below? Like appId/pluginId or something.

@@ -29,4 +29,18 @@ export function uiAppsMixin(kbnServer, server) {
server.decorate('server', 'getAllUiApps', () => kbnServer.uiApps.slice(0));
server.decorate('server', 'getUiAppById', id => appsById.get(id));
server.decorate('server', 'getHiddenUiAppById', id => hiddenAppsById.get(id));

const injectedVarProviders = [];
Copy link
Member

Choose a reason for hiding this comment

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

question/issue: why is this an array and not a map, do you have a use case in mind when we want to register several different provider's for the same id? If no, I'd use map and even throw if someone tries to register provider with the same name twice. If yes, then we need tests for this use case.

Copy link
Contributor Author

@spalger spalger Apr 5, 2018

Choose a reason for hiding this comment

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

Yeah, definitely intended to support multiple providers for the same appId so that plugins can inject vars into other applications. Down the road I intend to add support for a * appId that will allow us to remove most if not all instances of uiExports.injectDefaultVars and uiExports.replaceInjectedVars, but didn't want to muddy up this pr.

import { uiAppsMixin } from './ui_apps_mixin';

jest.mock('./ui_app', () => ({
UiApp: class StubUiApp {
Copy link
Member

Choose a reason for hiding this comment

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

note: Heh, I'm surprised that having a class declaration within a property declaration is a valid syntax. There is no need to change anything here, I'm just old fashioned and grumbling a bit :)


describe('server.getUiAppById()', () => {
it('returns non-hidden apps when requested, undefined for non-hidden and unknown apps', () => {
expect(server.getUiAppById('foo')).toMatchSnapshot('hidden');
Copy link
Member

Choose a reason for hiding this comment

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

optional nit: I don't have a strong opinion on that so up to you, but using snapshot just for undefined (here and in test below) sounds like an overkill to me.

Copy link
Contributor Author

@spalger spalger Apr 5, 2018

Choose a reason for hiding this comment

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

🤷‍♀️ I like consistency, but I'm not married to it

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think this should just be inlined as undefined. Same with the {} ones. I think we should optimize for readability, not consistency.

@@ -22,6 +21,10 @@ export class UiApp {
throw new Error('Every app must specify an id');
}

if (spec.injectVars) {
Copy link
Member

Choose a reason for hiding this comment

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

issue: it seems this if will never trigger since injectVars is always "trimmed" in ui_export_types/ui_apps.js now. If I'm not mistaken, we should do this check there instead?

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple of minor things

@elasticmachine
Copy link
Contributor

💚 Build Succeeded


describe('server.getUiAppById()', () => {
it('returns non-hidden apps when requested, undefined for non-hidden and unknown apps', () => {
expect(server.getUiAppById('foo')).toMatchSnapshot('hidden');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think this should just be inlined as undefined. Same with the {} ones. I think we should optimize for readability, not consistency.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@spalger spalger merged commit 1ecddb4 into elastic:master Apr 6, 2018
spalger added a commit to spalger/kibana that referenced this pull request Apr 6, 2018
…ic#17485)

* [uiApp] replace uiApp.injectVars with server.injectUiAppVars()

* [server/injectUiAppVars] cleanup styling

* [server/injectUiAppVars] add test to verify injectUiAppVars merging

* [server/injectUiAppVars] describe what type of id we expect

* [uiExportTypes/uiApp] add removal error to proper location

* [uiApps/tests] avoid snapshots for undefined/{} values
spalger added a commit that referenced this pull request Apr 7, 2018
… (#17601)

* [uiApp] replace uiApp.injectVars with server.injectUiAppVars()

* [server/injectUiAppVars] cleanup styling

* [server/injectUiAppVars] add test to verify injectUiAppVars merging

* [server/injectUiAppVars] describe what type of id we expect

* [uiExportTypes/uiApp] add removal error to proper location

* [uiApps/tests] avoid snapshots for undefined/{} values
@spalger
Copy link
Contributor Author

spalger commented Apr 7, 2018

6.3/6.x: cd54326

@spalger spalger deleted the remove/uiApp/injectedVars branch April 7, 2018 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v6.3.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants