diff --git a/x-pack/plugins/code/index.ts b/x-pack/plugins/code/index.ts index 7a4e799cf7fc8..1a2344e5620b5 100644 --- a/x-pack/plugins/code/index.ts +++ b/x-pack/plugins/code/index.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { Server } from 'hapi'; import JoiNamespace from 'joi'; import moment from 'moment'; import { resolve } from 'path'; @@ -24,9 +25,19 @@ export const code = (kibana: any) => euiIconType: 'codeApp', }, styleSheetPaths: resolve(__dirname, 'public/index.scss'), + injectDefaultVars(server: Server) { + const config = server.config(); + return { + codeUiEnabled: config.get('xpack.code.ui.enabled'), + }; + }, + hacks: ['plugins/code/hacks/toggle_app_link_in_nav'], }, config(Joi: typeof JoiNamespace) { return Joi.object({ + ui: Joi.object({ + enabled: Joi.boolean().default(true), + }).default(), enabled: Joi.boolean().default(true), queueIndex: Joi.string().default('.code_internal-worker-queue'), // 1 hour by default. diff --git a/x-pack/plugins/code/public/app.tsx b/x-pack/plugins/code/public/app.tsx index 66e7965d4f578..e1c6bdfb74052 100644 --- a/x-pack/plugins/code/public/app.tsx +++ b/x-pack/plugins/code/public/app.tsx @@ -16,45 +16,47 @@ import { App } from './components/app'; import { HelpMenu } from './components/help_menu'; import { store } from './stores'; -const app = uiModules.get('apps/code'); - -app.config(($locationProvider: any) => { - $locationProvider.html5Mode({ - enabled: false, - requireBase: false, - rewriteLinks: false, +if (chrome.getInjected('codeUiEnabled')) { + const app = uiModules.get('apps/code'); + + app.config(($locationProvider: any) => { + $locationProvider.html5Mode({ + enabled: false, + requireBase: false, + rewriteLinks: false, + }); }); -}); -app.config((stateManagementConfigProvider: any) => stateManagementConfigProvider.disable()); - -function RootController($scope: any, $element: any, $http: any) { - const domNode = $element[0]; - - // render react to DOM - render( - - - , - domNode - ); - - // unmount react on controller destroy - $scope.$on('$destroy', () => { - unmountComponentAtNode(domNode); + app.config((stateManagementConfigProvider: any) => stateManagementConfigProvider.disable()); + + function RootController($scope: any, $element: any, $http: any) { + const domNode = $element[0]; + + // render react to DOM + render( + + + , + domNode + ); + + // unmount react on controller destroy + $scope.$on('$destroy', () => { + unmountComponentAtNode(domNode); + }); + } + + chrome.setRootController('code', RootController); + chrome.breadcrumbs.set([ + { + text: 'Code (Beta)', + href: '#/', + }, + ]); + + chrome.helpExtension.set(domNode => { + render(, domNode); + return () => { + unmountComponentAtNode(domNode); + }; }); } - -chrome.setRootController('code', RootController); -chrome.breadcrumbs.set([ - { - text: 'Code (Beta)', - href: '#/', - }, -]); - -chrome.helpExtension.set(domNode => { - render(, domNode); - return () => { - unmountComponentAtNode(domNode); - }; -}); diff --git a/x-pack/plugins/code/public/hacks/toggle_app_link_in_nav.ts b/x-pack/plugins/code/public/hacks/toggle_app_link_in_nav.ts new file mode 100644 index 0000000000000..f2ccc0ef18309 --- /dev/null +++ b/x-pack/plugins/code/public/hacks/toggle_app_link_in_nav.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { onStart } from 'ui/new_platform'; + +onStart(({ core }) => { + const codeUiEnabled = core.injectedMetadata.getInjectedVar('codeUiEnabled'); + if (codeUiEnabled === false) { + core.chrome.navLinks.update('code', { hidden: true }); + } +}); diff --git a/x-pack/plugins/code/server/init.ts b/x-pack/plugins/code/server/init.ts index 62d05da535e48..e02a65a61e354 100644 --- a/x-pack/plugins/code/server/init.ts +++ b/x-pack/plugins/code/server/init.ts @@ -79,7 +79,7 @@ async function getCodeNodeUuid(url: string, log: Logger) { } export function init(server: Server, options: any) { - if (!options.enabled) { + if (!options.ui.enabled) { return; }