-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Conversation
8a2f4aa
to
09a262c
Compare
💚 Build Succeeded |
09a262c
to
38204a6
Compare
💚 Build Succeeded |
src/ui/ui_apps/ui_apps_mixin.js
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: arrow function maybe?
src/ui/ui_apps/ui_apps_mixin.js
Outdated
|
||
const injectedVarProviders = []; | ||
server.decorate('server', 'injectUiAppVars', function (id, provider) { | ||
injectedVarProviders.push({ id, provider, }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/ui/ui_apps/ui_apps_mixin.js
Outdated
@@ -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) { |
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 :)
src/ui/ui_apps/ui_apps_mixin.test.js
Outdated
|
||
describe('server.getUiAppById()', () => { | ||
it('returns non-hidden apps when requested, undefined for non-hidden and unknown apps', () => { | ||
expect(server.getUiAppById('foo')).toMatchSnapshot('hidden'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/ui/ui_apps/ui_app.js
Outdated
@@ -22,6 +21,10 @@ export class UiApp { | |||
throw new Error('Every app must specify an id'); | |||
} | |||
|
|||
if (spec.injectVars) { |
There was a problem hiding this comment.
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?
There was a problem hiding this 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
💚 Build Succeeded |
src/ui/ui_apps/ui_apps_mixin.test.js
Outdated
|
||
describe('server.getUiAppById()', () => { | ||
it('returns non-hidden apps when requested, undefined for non-hidden and unknown apps', () => { | ||
expect(server.getUiAppById('foo')).toMatchSnapshot('hidden'); |
There was a problem hiding this comment.
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.
💚 Build Succeeded |
…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
… (#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
6.3/6.x: cd54326 |
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 theui_render
module that provide similar functionality.The new API is:
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.