Skip to content

Commit

Permalink
[uiExports] add replaceInjectedVars() export type
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Nov 14, 2016
1 parent 431e803 commit 7ad237c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { format as formatUrl } from 'url';
import { readFileSync as readFile } from 'fs';
import { defaults } from 'lodash';
import Boom from 'boom';
import { reduce as reduceAsync } from 'bluebird';
import { resolve } from 'path';
import fromRoot from '../utils/from_root';
import UiExports from './ui_exports';
Expand Down Expand Up @@ -74,7 +75,11 @@ export default async (kbnServer, server, config) => {
defaults: await server.uiSettings().getDefaults(),
user: {}
},
vars: defaults(app.getInjectedVars() || {}, uiExports.defaultInjectedVars),
vars: await reduceAsync(
uiExports.injectedVarsReplacers,
(acc, extender) => extender(acc, this.request, server),
defaults(await app.getInjectedVars() || {}, uiExports.defaultInjectedVars)
)
};
}

Expand All @@ -89,15 +94,15 @@ export default async (kbnServer, server, config) => {

async function renderApp(app) {
const isElasticsearchPluginRed = server.plugins.elasticsearch.status.state === 'red';
const payload = await getPayload(app);
const payload = await getPayload.call(this, app);
if (!isElasticsearchPluginRed) {
payload.uiSettings.user = await server.uiSettings().getUserProvided();
}
return viewAppWithPayload.call(this, app, payload);
}

async function renderAppWithDefaultConfig(app) {
const payload = await getPayload(app);
const payload = await getPayload.call(this, app);
return viewAppWithPayload.call(this, app, payload);
}

Expand Down
6 changes: 6 additions & 0 deletions src/ui/ui_exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UiExports {
this.consumers = [];
this.bundleProviders = [];
this.defaultInjectedVars = {};
this.injectedVarsReplacers = [];
}

consumePlugin(plugin) {
Expand Down Expand Up @@ -107,6 +108,11 @@ class UiExports {
_.merge(this.defaultInjectedVars, await injector.call(plugin, server, options));
});
};

case 'replaceInjectedVars':
return (plugin, extender) => {
this.injectedVarsReplacers.push(extender);
};
}
}

Expand Down

0 comments on commit 7ad237c

Please sign in to comment.