Skip to content

Commit

Permalink
Move timelion app hiding to new platform (elastic#58740) (elastic#59539)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Mar 7, 2020
1 parent f7595fd commit 1d7c6af
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 33 deletions.
8 changes: 0 additions & 8 deletions src/legacy/core_plugins/timelion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl
},
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars(server) {
const config = server.config();

return {
timelionUiEnabled: config.get('timelion.ui.enabled'),
kbnIndex: config.get('kibana.index'),
};
},
mappings: require('./mappings.json'),
uiSettingDefaults: {
'timelion:showTutorial': {
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/timelion/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { npSetup } from 'ui/new_platform';
import { plugin } from '.';
import { TimelionPluginSetupDependencies } from './plugin';
import { LegacyDependenciesPlugin } from './shim';
Expand All @@ -32,4 +32,4 @@ const setupPlugins: Readonly<TimelionPluginSetupDependencies> = {
const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, setupPlugins);
export const start = pluginInstance.start(npStart.core);
export const start = pluginInstance.start();
16 changes: 2 additions & 14 deletions src/legacy/core_plugins/timelion/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
IUiSettingsClient,
} from 'kibana/public';
import { CoreSetup, Plugin, PluginInitializerContext, IUiSettingsClient } from 'kibana/public';
import { getTimeChart } from './panels/timechart/timechart';
import { Panel } from './panels/panel';
import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim';
Expand Down Expand Up @@ -65,13 +59,7 @@ export class TimelionPlugin implements Plugin<Promise<void>, void> {
dependencies.timelionPanels.set(timeChartPanel.name, timeChartPanel);
}

public start(core: CoreStart) {
const timelionUiEnabled = core.injectedMetadata.getInjectedVar('timelionUiEnabled');

if (timelionUiEnabled === false) {
core.chrome.navLinks.update('timelion', { hidden: true });
}
}
public start() {}

public stop(): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { schema, TypeOf } from '@kbn/config-schema';

export const ConfigSchema = schema.object(
export const configSchema = schema.object(
{
ui: schema.object({ enabled: schema.boolean({ defaultValue: false }) }),
graphiteUrls: schema.maybe(schema.arrayOf(schema.string())),
},
// This option should be removed as soon as we entirely migrate config from legacy Timelion plugin.
{ allowUnknowns: true }
);

export type ConfigSchema = TypeOf<typeof configSchema>;
2 changes: 1 addition & 1 deletion src/plugins/timelion/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"kibanaVersion": "kibana",
"configPath": ["timelion"],
"server": true,
"ui": false
"ui": true
}
30 changes: 30 additions & 0 deletions src/plugins/timelion/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { CoreStart, PluginInitializerContext } from 'kibana/public';
import { ConfigSchema } from '../config';

export const plugin = (initializerContext: PluginInitializerContext<ConfigSchema>) => ({
setup() {},
start(core: CoreStart) {
if (initializerContext.config.get().ui.enabled === false) {
core.chrome.navLinks.update('timelion', { hidden: true });
}
},
});
11 changes: 9 additions & 2 deletions src/plugins/timelion/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@
*/

import { PluginInitializerContext } from '../../../../src/core/server';
import { ConfigSchema } from './config';
import { configSchema } from '../config';
import { Plugin } from './plugin';

export { PluginSetupContract } from './plugin';

export const config = { schema: ConfigSchema };
export const config = {
schema: configSchema,
exposeToBrowser: {
ui: {
enabled: true,
},
},
};
export const plugin = (initializerContext: PluginInitializerContext) =>
new Plugin(initializerContext);
4 changes: 2 additions & 2 deletions src/plugins/timelion/server/lib/config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import { PluginInitializerContext } from 'kibana/server';
import { TypeOf } from '@kbn/config-schema';
import { ConfigSchema } from '../config';
import { configSchema } from '../../config';

export class ConfigManager {
private esShardTimeout: number = 0;
private graphiteUrls: string[] = [];

constructor(config: PluginInitializerContext['config']) {
config.create<TypeOf<typeof ConfigSchema>>().subscribe(configUpdate => {
config.create<TypeOf<typeof configSchema>>().subscribe(configUpdate => {
this.graphiteUrls = configUpdate.graphiteUrls || [];
});

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/timelion/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
RecursiveReadonly,
} from '../../../../src/core/server';
import { deepFreeze } from '../../../../src/core/utils';
import { ConfigSchema } from './config';
import { configSchema } from '../config';
import loadFunctions from './lib/load_functions';
import { functionsRoute } from './routes/functions';
import { validateEsRoute } from './routes/validate_es';
Expand All @@ -48,7 +48,7 @@ export class Plugin {

public async setup(core: CoreSetup): Promise<RecursiveReadonly<PluginSetupContract>> {
const config = await this.initializerContext.config
.create<TypeOf<typeof ConfigSchema>>()
.create<TypeOf<typeof configSchema>>()
.pipe(first())
.toPromise();

Expand Down

0 comments on commit 1d7c6af

Please sign in to comment.