Skip to content

Commit

Permalink
Allows disabling CSS for a plugin
Browse files Browse the repository at this point in the history
If a plugin does not require styles, a css file will not be produced by the optimizer. Previously this wasn't an issue as all plugins were including duplicated styles (kibana/15816).

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
Tyler Smalley committed Jan 8, 2018
1 parent 4634aa6 commit 149f1f0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core_plugins/state_session_storage_redirect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function (kibana) {
id: 'stateSessionStorageRedirect',
main: 'plugins/state_session_storage_redirect',
hidden: true,
hasCSS: false,
}
}
});
Expand Down
9 changes: 9 additions & 0 deletions src/ui/ui_apps/__tests__/ui_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function createStubUiAppSpec(extraParams) {
linkToLastSubUrl: true,
hidden: false,
listed: false,
hasCSS: false,
templateName: 'ui_app_test',
uses: [
'visTypes',
Expand Down Expand Up @@ -86,6 +87,10 @@ describe('UiApp', () => {
expect(app.getNavLink()).to.be.a(UiNavLink);
});

it('has CSS', () => {
expect(app.getHasCSS()).to.be(true);
});

it('has no injected vars', () => {
expect(app.getInjectedVars()).to.be(undefined);
});
Expand Down Expand Up @@ -139,6 +144,10 @@ describe('UiApp', () => {
expect(app.getNavLink()).to.be(undefined);
});

it('has no CSS', () => {
expect(app.getHasCSS()).to.be(false);
});

it('has injected vars', () => {
expect(app.getInjectedVars()).to.eql({ foo: 'bar' });
});
Expand Down
6 changes: 6 additions & 0 deletions src/ui/ui_apps/ui_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class UiApp {
listed,
templateName = 'ui_app',
injectVars,
hasCSS = true,
url = `/app/${id}`,
uses = []
} = spec;
Expand All @@ -35,6 +36,7 @@ export class UiApp {
this._templateName = templateName;
this._url = url;
this._injectedVarsProvider = injectVars;
this._hasCSS = hasCSS;
this._pluginId = pluginId;
this._kbnServer = kbnServer;

Expand Down Expand Up @@ -98,6 +100,10 @@ export class UiApp {
}
}

getHasCSS() {
return this._hasCSS;
}

getInjectedVars() {
const provider = this._injectedVarsProvider;
const plugin = this._getPlugin();
Expand Down
2 changes: 2 additions & 0 deletions src/ui/ui_exports/ui_export_types/ui_apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function applySpecDefaults(spec, type, pluginSpec) {
listed = !hidden,
templateName = 'ui_app',
injectVars = noop,
hasCSS = true,
url = `/app/${id}`,
uses = [],
} = spec;
Expand All @@ -34,6 +35,7 @@ function applySpecDefaults(spec, type, pluginSpec) {
listed,
templateName,
injectVars,
hasCSS,
url,
uses: uniq([
...uses,
Expand Down
5 changes: 4 additions & 1 deletion src/ui/ui_render/views/ui_app.jade
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ block content
}
var files = [
bundleFile('commons.style.css'),
bundleFile('#{app.getId()}.style.css'),
bundleFile('commons.bundle.js'),
bundleFile('#{app.getId()}.bundle.js')
];

if ('#{app.getHasCSS()}' == 'true') {
files.push(bundleFile('#{app.getId()}.style.css'));
}

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

0 comments on commit 149f1f0

Please sign in to comment.