Skip to content

Commit

Permalink
Adds Canvas and ensures loading order
Browse files Browse the repository at this point in the history
Stylesheets are loaded in the following order:

* Vendor
* Commons
* Current Application
* Those defined in uiExports.styleSheetPaths

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
Tyler Smalley committed Sep 17, 2018
1 parent f231a14 commit d511971
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/core_plugins/status_page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
export default function (kibana) {
return new kibana.Plugin({
uiExports: {
styleSheetPaths: `${__dirname}/public/index.scss`,
app: {
title: 'Server Status',
main: 'plugins/status_page/status_page',
hidden: true,
url: '/status',
}
},
styleSheetPaths: `${__dirname}/public/index.scss`,
}
});
}
71 changes: 39 additions & 32 deletions src/ui/ui_render/bootstrap/template.js.hbs
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
window.onload = function () {
var files = [
'{{bundlePath}}/vendors.style.css',
'{{bundlePath}}/commons.style.css',
'{{bundlePath}}/{{appId}}.style.css',

'{{bundlePath}}/vendors.bundle.js',
'{{bundlePath}}/commons.bundle.js',
'{{bundlePath}}/{{appId}}.bundle.js'
];

var failure = function () {
// make subsequent calls to failure() noop
failure = function () {};

var err = document.createElement('h1');
err.style['color'] = 'white';
err.style['font-family'] = 'monospace';
err.style['text-align'] = 'center';
err.style['background'] = '#F44336';
err.style['padding'] = '25px';
err.innerText = '{{i18n 'common.ui.welcomeError' '{"defaultMessage": "Kibana did not load properly. Check the server output for more information."}'}}';

document.body.innerHTML = err.outerHTML;
}

function loadStyleSheet(path) {
var dom = document.createElement('link');

dom.addEventListener('error', failure);
dom.setAttribute('rel', 'stylesheet');
dom.setAttribute('href', path);
document.head.appendChild(dom);
}

function createJavascriptElement(path) {
var dom = document.createElement('script');

dom.setAttribute('async', '');
dom.addEventListener('error', failure);
dom.setAttribute('src', file);
dom.addEventListener('load', next);
document.head.appendChild(dom);
}

{{#each styleSheetPaths}}
files.unshift('{{this}}');
loadStyleSheet('{{this}}');
{{/each}}

(function next() {
var file = files.shift();
if (!file) return;

var failure = function () {
// make subsequent calls to failure() noop
failure = function () {};
var dom = document.createElement('script');

var err = document.createElement('h1');
err.style['color'] = 'white';
err.style['font-family'] = 'monospace';
err.style['text-align'] = 'center';
err.style['background'] = '#F44336';
err.style['padding'] = '25px';
err.innerText = '{{i18n 'common.ui.welcomeError' '{"defaultMessage": "Kibana did not load properly. Check the server output for more information."}'}}';

document.body.innerHTML = err.outerHTML;
}

var type = /\.js(\?.+)?$/.test(file) ? 'script' : 'link';
var dom = document.createElement(type);
dom.setAttribute('async', '');
dom.addEventListener('error', failure);

if (type === 'script') {
dom.setAttribute('src', file);
dom.addEventListener('load', next);
document.head.appendChild(dom);
} else {
dom.setAttribute('rel', 'stylesheet');
dom.setAttribute('href', file);
document.head.appendChild(dom);
next();
}
dom.setAttribute('src', file);
dom.addEventListener('load', next);
document.head.appendChild(dom);
}());
};
11 changes: 9 additions & 2 deletions src/ui/ui_render/ui_render_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ export function uiRenderMixin(kbnServer, server, config) {
}

const basePath = config.get('server.basePath');
const bundlePath = `${basePath}/bundles`;
const styleSheetPaths = [
`${bundlePath}/vendors.style.css`,
`${bundlePath}/commons.style.css`,
`${bundlePath}/${app.getId()}.style.css`,
].concat(kbnServer.uiExports.styleSheetPaths.map(path => `${basePath}/${path.publicPath}`));

const bootstrap = new AppBootstrap({
templateData: {
appId: app.getId(),
bundlePath: `${basePath}/bundles`,
styleSheetPaths: kbnServer.uiExports.styleSheetPaths.map(path => `${basePath}/${path.publicPath}`),
bundlePath,
styleSheetPaths,
},
translations: await server.getUiTranslations()
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export function canvas(kibana) {
description: 'Data driven workpads',
icon: 'plugins/canvas/icon.svg',
main: 'plugins/canvas/app',
styleSheetPath: `${__dirname}/public/style/index.scss`,
},
styleSheetPaths: `${__dirname}/public/style/index.scss`,
hacks: [
// window.onerror override
'plugins/canvas/lib/window_error_handler.js',
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/dashboard_mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function dashboardMode(kibana) {
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],
uiExports: {
styleSheetPaths: `${__dirname}/public/index.scss`,
uiSettingDefaults: {
[CONFIG_DASHBOARD_ONLY_MODE_ROLES]: {
name: 'Dashboards only roles',
Expand All @@ -52,7 +51,8 @@ export function dashboardMode(kibana) {
icon: 'plugins/kibana/assets/dashboard.svg',
}
],
}
},
styleSheetPaths: `${__dirname}/public/index.scss`,
},

config(Joi) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const ml = (kibana) => {
description: 'Machine Learning for the Elastic Stack',
icon: 'plugins/ml/ml.svg',
main: 'plugins/ml/app',
styleSheetPath: `${__dirname}/public/index.scss`,
},
styleSheetPaths: `${__dirname}/public/index.scss`,
hacks: ['plugins/ml/hacks/toggle_app_link_in_nav'],
home: ['plugins/ml/register_feature']
},
Expand Down

0 comments on commit d511971

Please sign in to comment.