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

[uiExports] add uiExport type "injectDefaultVars" #6546

Merged
merged 13 commits into from
Mar 18, 2016

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Mar 15, 2016

In order for plugins to inject default injected vars, they should define an "injectVars" uiExport that will be called once in order to build the default injected vars. This function should return an object with the injectedVars it wishes to add. Plugins are run in a non-deterministic order, so they should not be written to override each other. injectedVars should all have unique names. The injectedVars for the app will override any values provided by "default" injectedVars functions.

In order for plugins to inject default injected vars, they should define an "injectVars" uiExport that will be called once in order to build the default injected vars. This function should return an object with the injectedVars it wishes to add. Plugins are run in a non-deterministic order, so they should not be written to override each other. injectedVars should all have unique names. The injectedVars for the app will override any values provided by "default" injectedVars functions.
@spalger spalger self-assigned this Mar 15, 2016
@w33ble
Copy link
Contributor

w33ble commented Mar 15, 2016

Looks like the expectation is that injectedVars is synchronous, and just returns an object of vars to inject. I actually need this to be an async thing, so I'd love to be able to return a Promise that resolves to said object...

EDIT: Or, I could set it after the fact, since init() is async. The question then becomes, can I change the value of the thing I'm injecting?

@trevan
Copy link
Contributor

trevan commented Mar 15, 2016

Are the injectVars from all plugins going to be used? Or is there a way to indicate which "apps" the injectVars should go to? Say I have a plugin that only messes with the kibana app and not the sense/console app. Can I just injectVars for kibana and not for sense/console?

@spalger
Copy link
Contributor Author

spalger commented Mar 16, 2016

@trevan that isn't the plan right now, the plan is for the injectedVars to be the defaults for every app. That said, I'm not opposed to this idea I'm just not sure of a good api for it. For now, you should be able to monkey-patch kibana's UiApp like so (untested code):

import { wrap } from 'lodash'

export default kibana => new kibana.Plugin({
  requires: ['kibana'],
  init(server, options) {
    const uiApp = kibana.uiExports.apps.byName.kibana
    const original = uiApp.getInjectedVars
    uiApp.getInjectedVars = (server, opts) => {
      const injectedVars = original.call(uiApp, server, opts)
      // make modifications
      return injectedVars
    })
  }
})

@spalger spalger force-pushed the implement/uiExportsInjectVars branch from 732fcdb to e120e44 Compare March 16, 2016 23:51
@spalger spalger changed the title [uiExports] add uiExport type "injectVars" [uiExports] add uiExport type "injectDefaultVars" Mar 16, 2016
@spalger spalger added the v5.0.0 label Mar 16, 2016
@spalger spalger assigned w33ble and unassigned spalger Mar 16, 2016
@w33ble
Copy link
Contributor

w33ble commented Mar 17, 2016

Functionally, this looks good, Promises and all! 👯

@spalger spalger assigned spalger and unassigned w33ble Mar 18, 2016
@spalger spalger force-pushed the implement/uiExportsInjectVars branch from ea8194e to f267ab1 Compare March 18, 2016 01:42
@spalger spalger assigned w33ble and unassigned spalger Mar 18, 2016
@w33ble
Copy link
Contributor

w33ble commented Mar 18, 2016

LGTM, waiting for the build to pass

@w33ble
Copy link
Contributor

w33ble commented Mar 18, 2016

All signs point to awesome, time for a mergin'

w33ble added a commit that referenced this pull request Mar 18, 2016
[uiExports] add uiExport type "injectDefaultVars"
@w33ble w33ble merged commit 6c9c9b9 into elastic:master Mar 18, 2016
epixa added a commit that referenced this pull request Jun 6, 2016
@epixa epixa added the v4.6.0 label Aug 26, 2016
@spalger spalger deleted the implement/uiExportsInjectVars branch October 18, 2019 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants