From 6a249bf567bfc347d3ecdd614dc1a89d8cd2596b Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 26 Aug 2019 23:57:56 +0300 Subject: [PATCH 01/42] Move index.js to index.ts --- .../timelion/{index.js => index.ts} | 47 ++++++++++--------- src/legacy/plugin_discovery/types.ts | 4 +- 2 files changed, 29 insertions(+), 22 deletions(-) rename src/legacy/core_plugins/timelion/{index.js => index.ts} (82%) diff --git a/src/legacy/core_plugins/timelion/index.js b/src/legacy/core_plugins/timelion/index.ts similarity index 82% rename from src/legacy/core_plugins/timelion/index.js rename to src/legacy/core_plugins/timelion/index.ts index 29f538dc9fcd6..78471aff59c28 100644 --- a/src/legacy/core_plugins/timelion/index.js +++ b/src/legacy/core_plugins/timelion/index.ts @@ -19,25 +19,29 @@ import { resolve } from 'path'; import { i18n } from '@kbn/i18n'; +import { Legacy } from 'kibana'; +import { LegacyPluginApi, LegacyPluginInitializer } from 'src/legacy/plugin_discovery/types'; +import { CoreSetup, PluginInitializerContext } from 'src/core/server'; import { plugin } from './server'; +import { CustomCoreSetup } from './server/plugin'; const experimentalLabel = i18n.translate('timelion.uiSettings.experimentalLabel', { defaultMessage: 'experimental', }); -export default function (kibana) { - return new kibana.Plugin({ +const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) => + new Plugin({ require: ['kibana', 'elasticsearch'], - config(Joi) { + config(Joi: any) { return Joi.object({ enabled: Joi.boolean().default(true), ui: Joi.object({ enabled: Joi.boolean().default(false), }).default(), - graphiteUrls: Joi.array().items( - Joi.string().uri({ scheme: ['http', 'https'] }), - ).default([]), + graphiteUrls: Joi.array() + .items(Joi.string().uri({ scheme: ['http', 'https'] })) + .default([]), }).default(); }, @@ -71,13 +75,9 @@ export default function (kibana) { kbnIndex: config.get('kibana.index'), }; }, - visTypes: [ - 'plugins/timelion/vis', - ], + visTypes: ['plugins/timelion/vis'], interpreter: ['plugins/timelion/timelion_vis_fn'], - home: [ - 'plugins/timelion/register_feature', - ], + home: ['plugins/timelion/register_feature'], mappings: require('./mappings.json'), uiSettingDefaults: { 'timelion:showTutorial': { @@ -159,16 +159,18 @@ export default function (kibana) { value: '1ms', description: i18n.translate('timelion.uiSettings.minimumIntervalDescription', { defaultMessage: 'The smallest interval that will be calculated when using "auto"', - description: '"auto" is a technical value in that context, that should not be translated.', + description: + '"auto" is a technical value in that context, that should not be translated.', }), category: ['timelion'], }, 'timelion:graphite.url': { name: i18n.translate('timelion.uiSettings.graphiteURLLabel', { defaultMessage: 'Graphite URL', - description: 'The URL should be in the form of https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite', + description: + 'The URL should be in the form of https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite', }), - value: (server) => { + value: (server: any) => { const urls = server.config().get('timelion.graphiteUrls'); if (urls.length === 0) { return null; @@ -177,11 +179,12 @@ export default function (kibana) { } }, description: i18n.translate('timelion.uiSettings.graphiteURLDescription', { - defaultMessage: '{experimentalLabel} The URL of your graphite host', + defaultMessage: + '{experimentalLabel} The URL of your graphite host', values: { experimentalLabel: `[${experimentalLabel}]` }, }), type: 'select', - options: (server) => (server.config().get('timelion.graphiteUrls')), + options: (server: any) => server.config().get('timelion.graphiteUrls'), category: ['timelion'], }, 'timelion:quandl.key': { @@ -197,11 +200,13 @@ export default function (kibana) { }, }, }, - init: (server) => { - const initializerContext = {}; - const core = { http: { server } }; + init: (server: Legacy.Server) => { + const initializerContext = {} as PluginInitializerContext; + const core = { http: { server } } as CoreSetup & CustomCoreSetup; plugin(initializerContext).setup(core); }, }); -} + +// eslint-disable-next-line import/no-default-export +export default timelionPluginInitializer; diff --git a/src/legacy/plugin_discovery/types.ts b/src/legacy/plugin_discovery/types.ts index 76b62b7eb693c..b53cfa7240042 100644 --- a/src/legacy/plugin_discovery/types.ts +++ b/src/legacy/plugin_discovery/types.ts @@ -72,8 +72,10 @@ export interface LegacyPluginOptions { visTypes: string[]; embeddableActions?: string[]; embeddableFactories?: string[]; + interpreter?: string[]; + uiSettingDefaults?: Record; }>; - uiCapabilities?: Capabilities; + uiCapabilities?: Capabilities | (() => Record); publicDir: any; configPrefix: any; config: any; From a8bde3eacf9c6ed533479930c142c2a8e8cd5f0e Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 28 Aug 2019 12:56:00 +0300 Subject: [PATCH 02/42] Migrate Vis, interpreter, home and 2 hacks to setup() and start() --- src/legacy/core_plugins/timelion/index.ts | 13 +--- .../toggle_app_link_in_nav.ts => index.ts} | 8 +-- .../core_plugins/timelion/public/legacy.ts | 42 +++++++++++ .../core_plugins/timelion/public/plugin.ts | 70 +++++++++++++++++++ .../timelion/public/register_feature.js | 10 +-- .../timelion/public/timelion_vis_fn.js | 5 -- .../core_plugins/timelion/public/vis/index.js | 8 +-- 7 files changed, 122 insertions(+), 34 deletions(-) rename src/legacy/core_plugins/timelion/public/{hacks/toggle_app_link_in_nav.ts => index.ts} (76%) create mode 100644 src/legacy/core_plugins/timelion/public/legacy.ts create mode 100644 src/legacy/core_plugins/timelion/public/plugin.ts diff --git a/src/legacy/core_plugins/timelion/index.ts b/src/legacy/core_plugins/timelion/index.ts index 78471aff59c28..9775201ed134e 100644 --- a/src/legacy/core_plugins/timelion/index.ts +++ b/src/legacy/core_plugins/timelion/index.ts @@ -32,7 +32,6 @@ const experimentalLabel = i18n.translate('timelion.uiSettings.experimentalLabel' const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) => new Plugin({ require: ['kibana', 'elasticsearch'], - config(Joi: any) { return Joi.object({ enabled: Joi.boolean().default(true), @@ -44,7 +43,6 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl .default([]), }).default(); }, - uiCapabilities() { return { timelion: { @@ -52,7 +50,7 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl }, }; }, - + publicDir: resolve(__dirname, 'public'), uiExports: { app: { title: 'Timelion', @@ -62,11 +60,7 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl main: 'plugins/timelion/app', }, styleSheetPaths: resolve(__dirname, 'public/index.scss'), - hacks: [ - 'plugins/timelion/hacks/toggle_app_link_in_nav', - 'plugins/timelion/lib/panel_registry', - 'plugins/timelion/panels/timechart/timechart', - ], + hacks: [resolve(__dirname, 'public/legacy')], injectDefaultVars(server) { const config = server.config(); @@ -75,9 +69,6 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl kbnIndex: config.get('kibana.index'), }; }, - visTypes: ['plugins/timelion/vis'], - interpreter: ['plugins/timelion/timelion_vis_fn'], - home: ['plugins/timelion/register_feature'], mappings: require('./mappings.json'), uiSettingDefaults: { 'timelion:showTutorial': { diff --git a/src/legacy/core_plugins/timelion/public/hacks/toggle_app_link_in_nav.ts b/src/legacy/core_plugins/timelion/public/index.ts similarity index 76% rename from src/legacy/core_plugins/timelion/public/hacks/toggle_app_link_in_nav.ts rename to src/legacy/core_plugins/timelion/public/index.ts index 6480ea0a69e43..6b42135884655 100644 --- a/src/legacy/core_plugins/timelion/public/hacks/toggle_app_link_in_nav.ts +++ b/src/legacy/core_plugins/timelion/public/index.ts @@ -17,9 +17,9 @@ * under the License. */ -import { npStart } from 'ui/new_platform'; +import { PluginInitializerContext } from 'kibana/public'; +import { TimelionPlugin as Plugin } from './plugin'; -const timelionUiEnabled = npStart.core.injectedMetadata.getInjectedVar('timelionUiEnabled'); -if (timelionUiEnabled === false) { - npStart.core.chrome.navLinks.update('timelion', { hidden: true }); +export function plugin(initializerContext: PluginInitializerContext) { + return new Plugin(initializerContext); } diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts new file mode 100644 index 0000000000000..c53913f6aed50 --- /dev/null +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -0,0 +1,42 @@ +/* + * 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 { PluginInitializerContext } from 'kibana/public'; +import { npSetup, npStart } from 'ui/new_platform'; +import { FeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; +import { plugin } from '.'; +import { visualizations } from '../../visualizations/public'; +import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; +// @ts-ignore +import { panelRegistry } from './lib/panel_registry'; + +const setupPlugins: Readonly = { + visualizations, + data: npSetup.plugins.data, + featureCatalogue: FeatureCatalogueRegistryProvider, +}; + +const startPlugins: Readonly = { + panelRegistry, +}; + +const pluginInstance = plugin({} as PluginInitializerContext); + +export const setup = pluginInstance.setup(npSetup.core, setupPlugins); +export const start = pluginInstance.start(npStart.core, startPlugins); diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts new file mode 100644 index 0000000000000..2ffbefa6c83ae --- /dev/null +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -0,0 +1,70 @@ +/* + * 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 { + CoreSetup, + CoreStart, + InternalCoreStart, + Plugin, + PluginInitializerContext, +} from 'kibana/public'; +import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/public'; +import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; +// @ts-ignore +import { timelionVis } from './timelion_vis_fn'; +// @ts-ignore +import { TimelionVisProvider } from './vis'; +// @ts-ignore +import { registerFeature } from './register_feature'; + +/** @internal */ +export interface TimelionPluginSetupDependencies { + data: ReturnType; + visualizations: VisualizationsSetup; + featureCatalogue: any; +} + +/** @internal */ +export interface TimelionPluginStartDependencies { + panelRegistry: any; +} + +/** @internal */ +export class TimelionPlugin implements Plugin, void> { + initializerContext: PluginInitializerContext; + + constructor(initializerContext: PluginInitializerContext) { + this.initializerContext = initializerContext; + } + + public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { + plugins.featureCatalogue.register(registerFeature); + plugins.data.expressions.registerFunction(timelionVis); + plugins.visualizations.types.VisTypesRegistryProvider.register(TimelionVisProvider); + } + + public start(core: CoreStart & InternalCoreStart, plugins: TimelionPluginStartDependencies) { + const timelionUiEnabled = core.injectedMetadata.getInjectedVar('timelionUiEnabled'); + + if (timelionUiEnabled === false) { + core.chrome.navLinks.update('timelion', { hidden: true }); + } + } + + public stop(): void {} +} diff --git a/src/legacy/core_plugins/timelion/public/register_feature.js b/src/legacy/core_plugins/timelion/public/register_feature.js index 415ed532f6a34..7dd44b58bd1d7 100644 --- a/src/legacy/core_plugins/timelion/public/register_feature.js +++ b/src/legacy/core_plugins/timelion/public/register_feature.js @@ -17,14 +17,10 @@ * under the License. */ -import { - FeatureCatalogueRegistryProvider, - FeatureCatalogueCategory, -} from 'ui/registry/feature_catalogue'; - +import { FeatureCatalogueCategory } from 'ui/registry/feature_catalogue'; import { i18n } from '@kbn/i18n'; -FeatureCatalogueRegistryProvider.register(() => { +export const registerFeature = () => { return { id: 'timelion', title: 'Timelion', @@ -37,4 +33,4 @@ FeatureCatalogueRegistryProvider.register(() => { showOnHomePage: false, category: FeatureCatalogueCategory.DATA, }; -}); +}; diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.js b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.js index 9161715d28022..d1ac183594b56 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.js +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.js @@ -17,12 +17,9 @@ * under the License. */ -import { functionsRegistry } from 'plugins/interpreter/registries'; import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { TimelionRequestHandlerProvider } from './vis/timelion_request_handler'; - - import chrome from 'ui/chrome'; export const timelionVis = () => ({ @@ -76,5 +73,3 @@ export const timelionVis = () => ({ }; }, }); - -functionsRegistry.register(timelionVis); diff --git a/src/legacy/core_plugins/timelion/public/vis/index.js b/src/legacy/core_plugins/timelion/public/vis/index.js index 4257d4334b602..d5be65c295472 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.js +++ b/src/legacy/core_plugins/timelion/public/vis/index.js @@ -19,21 +19,15 @@ import { VisFactoryProvider } from 'ui/vis/vis_factory'; import { i18n } from '@kbn/i18n'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import { TimelionRequestHandlerProvider } from './timelion_request_handler'; import { DefaultEditorSize } from 'ui/vis/editor_size'; - // we also need to load the controller and directive used by the template import './timelion_vis_controller'; import '../directives/timelion_expression_input'; - import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; -// register the provider with the visTypes registry so that other know it exists -VisTypesRegistryProvider.register(TimelionVisProvider); - -export default function TimelionVisProvider(Private) { +export function TimelionVisProvider(Private) { const VisFactory = Private(VisFactoryProvider); const timelionRequestHandler = Private(TimelionRequestHandlerProvider); From 69887c700f08e25a45465e69faded67dfa3ab32a Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 28 Aug 2019 13:11:51 +0300 Subject: [PATCH 03/42] Move Timechart hack to start() --- src/legacy/core_plugins/timelion/public/legacy.ts | 2 +- .../timelion/public/panels/timechart/timechart.js | 5 ++--- src/legacy/core_plugins/timelion/public/plugin.ts | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index c53913f6aed50..cb565cdc0562e 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -24,7 +24,7 @@ import { plugin } from '.'; import { visualizations } from '../../visualizations/public'; import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; // @ts-ignore -import { panelRegistry } from './lib/panel_registry'; +import panelRegistry from './lib/panel_registry'; const setupPlugins: Readonly = { visualizations, diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js index a3bee66f9d4ef..47afc6b049988 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js @@ -19,10 +19,9 @@ import Panel from '../panel'; import { i18n } from '@kbn/i18n'; -import panelRegistry from '../../lib/panel_registry'; -panelRegistry.register(function timeChartProvider(Private) { +export function timeChartProvider(Private) { // Schema is broken out so that it may be extended for use in other plugins // Its also easier to test. return new Panel('timechart', Private(require('./schema'))(), i18n); -}); +} diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 2ffbefa6c83ae..93b00f47e1624 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -31,6 +31,8 @@ import { timelionVis } from './timelion_vis_fn'; import { TimelionVisProvider } from './vis'; // @ts-ignore import { registerFeature } from './register_feature'; +// @ts-ignore +import { timeChartProvider } from './panels/timechart/timechart'; /** @internal */ export interface TimelionPluginSetupDependencies { @@ -64,6 +66,8 @@ export class TimelionPlugin implements Plugin, void> { if (timelionUiEnabled === false) { core.chrome.navLinks.update('timelion', { hidden: true }); } + + plugins.panelRegistry.register(timeChartProvider); } public stop(): void {} From ca5bcc9c8cc7c32234f0352e354d9e0355c23c86 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 28 Aug 2019 15:07:39 +0300 Subject: [PATCH 04/42] Add featureCatalogueRegistryProvider to an interface --- src/legacy/core_plugins/timelion/public/legacy.ts | 4 ++-- src/legacy/core_plugins/timelion/public/plugin.ts | 5 +++-- src/legacy/ui/public/registry/feature_catalogue.d.ts | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index cb565cdc0562e..007666f3253b9 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -19,7 +19,7 @@ import { PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; -import { FeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; +import { FeatureCatalogueRegistryProvider as featureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; import { plugin } from '.'; import { visualizations } from '../../visualizations/public'; import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; @@ -29,7 +29,7 @@ import panelRegistry from './lib/panel_registry'; const setupPlugins: Readonly = { visualizations, data: npSetup.plugins.data, - featureCatalogue: FeatureCatalogueRegistryProvider, + featureCatalogueRegistryProvider, }; const startPlugins: Readonly = { diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 93b00f47e1624..66e98be991467 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -25,6 +25,7 @@ import { } from 'kibana/public'; import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/public'; import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; +import { IFeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; // @ts-ignore import { timelionVis } from './timelion_vis_fn'; // @ts-ignore @@ -38,7 +39,7 @@ import { timeChartProvider } from './panels/timechart/timechart'; export interface TimelionPluginSetupDependencies { data: ReturnType; visualizations: VisualizationsSetup; - featureCatalogue: any; + featureCatalogueRegistryProvider: IFeatureCatalogueRegistryProvider; } /** @internal */ @@ -55,7 +56,7 @@ export class TimelionPlugin implements Plugin, void> { } public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { - plugins.featureCatalogue.register(registerFeature); + plugins.featureCatalogueRegistryProvider.register(registerFeature); plugins.data.expressions.registerFunction(timelionVis); plugins.visualizations.types.VisTypesRegistryProvider.register(TimelionVisProvider); } diff --git a/src/legacy/ui/public/registry/feature_catalogue.d.ts b/src/legacy/ui/public/registry/feature_catalogue.d.ts index 031c3efa6c5ad..b45fd8d6fb47c 100644 --- a/src/legacy/ui/public/registry/feature_catalogue.d.ts +++ b/src/legacy/ui/public/registry/feature_catalogue.d.ts @@ -37,6 +37,8 @@ interface FeatureCatalogueObject { type FeatureCatalogueRegistryFunction = (i18n: I18nServiceType) => FeatureCatalogueObject; -export const FeatureCatalogueRegistryProvider: { +export interface IFeatureCatalogueRegistryProvider { register: (fn: FeatureCatalogueRegistryFunction) => void; -}; +} + +export const FeatureCatalogueRegistryProvider: IFeatureCatalogueRegistryProvider; From 446b96ceefc7a1da25623148274fac5b741648ca Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 28 Aug 2019 18:41:09 +0300 Subject: [PATCH 05/42] Add types to a server param --- src/legacy/core_plugins/timelion/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/timelion/index.ts b/src/legacy/core_plugins/timelion/index.ts index 9775201ed134e..c111e25d78f15 100644 --- a/src/legacy/core_plugins/timelion/index.ts +++ b/src/legacy/core_plugins/timelion/index.ts @@ -161,8 +161,8 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl description: 'The URL should be in the form of https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite', }), - value: (server: any) => { - const urls = server.config().get('timelion.graphiteUrls'); + value: (server: Legacy.Server) => { + const urls = server.config().get('timelion.graphiteUrls') as string[]; if (urls.length === 0) { return null; } else { @@ -175,7 +175,7 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl values: { experimentalLabel: `[${experimentalLabel}]` }, }), type: 'select', - options: (server: any) => server.config().get('timelion.graphiteUrls'), + options: (server: Legacy.Server) => server.config().get('timelion.graphiteUrls'), category: ['timelion'], }, 'timelion:quandl.key': { From 4cb9c0609dfcc98391156dfb1096f3d357af6da4 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Thu, 29 Aug 2019 13:56:06 +0300 Subject: [PATCH 06/42] Move some .js to .ts --- .../public/panels/{panel.js => panel.ts} | 28 +++++----- .../timechart/{timechart.js => timechart.ts} | 7 ++- .../core_plugins/timelion/public/plugin.ts | 4 -- ...egister_feature.js => register_feature.ts} | 0 ...{timelion_vis_fn.js => timelion_vis_fn.ts} | 17 +++--- .../public/vis/{index.js => index.ts} | 8 +-- ...handler.js => timelion_request_handler.ts} | 54 ++++++++++++------- 7 files changed, 64 insertions(+), 54 deletions(-) rename src/legacy/core_plugins/timelion/public/panels/{panel.js => panel.ts} (67%) rename src/legacy/core_plugins/timelion/public/panels/timechart/{timechart.js => timechart.ts} (83%) rename src/legacy/core_plugins/timelion/public/{register_feature.js => register_feature.ts} (100%) rename src/legacy/core_plugins/timelion/public/{timelion_vis_fn.js => timelion_vis_fn.ts} (90%) rename src/legacy/core_plugins/timelion/public/vis/{index.js => index.ts} (95%) rename src/legacy/core_plugins/timelion/public/vis/{timelion_request_handler.js => timelion_request_handler.ts} (66%) diff --git a/src/legacy/core_plugins/timelion/public/panels/panel.js b/src/legacy/core_plugins/timelion/public/panels/panel.ts similarity index 67% rename from src/legacy/core_plugins/timelion/public/panels/panel.js rename to src/legacy/core_plugins/timelion/public/panels/panel.ts index f45aeb08e31fe..ea4a6c4376b1e 100644 --- a/src/legacy/core_plugins/timelion/public/panels/panel.js +++ b/src/legacy/core_plugins/timelion/public/panels/panel.ts @@ -19,20 +19,22 @@ import { i18n } from '@kbn/i18n'; -export default function Panel(name, config) { +export class Panel { + name: any; + help: any; + render: any; - this.name = name; + constructor(name: any, config: any) { + this.name = name; + this.help = config.help || ''; + this.render = config.render; - this.help = config.help || ''; - - this.render = config.render; - - if (!config.render) { - throw new Error ( - i18n.translate('timelion.panels.noRenderFunctionErrorMessage', { - defaultMessage: 'Panel must have a rendering function' - }) - ); + if (!config.render) { + throw new Error( + i18n.translate('timelion.panels.noRenderFunctionErrorMessage', { + defaultMessage: 'Panel must have a rendering function', + }) + ); + } } - } diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts similarity index 83% rename from src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js rename to src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts index 47afc6b049988..d1ceaa9f389ee 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.js +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts @@ -17,11 +17,10 @@ * under the License. */ -import Panel from '../panel'; -import { i18n } from '@kbn/i18n'; +import { Panel } from '../panel'; -export function timeChartProvider(Private) { +export function timeChartProvider(Private: any) { // Schema is broken out so that it may be extended for use in other plugins // Its also easier to test. - return new Panel('timechart', Private(require('./schema'))(), i18n); + return new Panel('timechart', Private(require('./schema'))()); } diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 66e98be991467..03c178ae0ad95 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -26,13 +26,9 @@ import { import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/public'; import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; import { IFeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; -// @ts-ignore import { timelionVis } from './timelion_vis_fn'; -// @ts-ignore import { TimelionVisProvider } from './vis'; -// @ts-ignore import { registerFeature } from './register_feature'; -// @ts-ignore import { timeChartProvider } from './panels/timechart/timechart'; /** @internal */ diff --git a/src/legacy/core_plugins/timelion/public/register_feature.js b/src/legacy/core_plugins/timelion/public/register_feature.ts similarity index 100% rename from src/legacy/core_plugins/timelion/public/register_feature.js rename to src/legacy/core_plugins/timelion/public/register_feature.ts diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.js b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts similarity index 90% rename from src/legacy/core_plugins/timelion/public/timelion_vis_fn.js rename to src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index d1ac183594b56..093a2e069ac3c 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.js +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -19,20 +19,17 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { TimelionRequestHandlerProvider } from './vis/timelion_request_handler'; import chrome from 'ui/chrome'; +import { TimelionRequestHandlerProvider } from './vis/timelion_request_handler'; export const timelionVis = () => ({ name: 'timelion_vis', type: 'render', context: { - types: [ - 'kibana_context', - 'null', - ], + types: ['kibana_context', 'null'], }, help: i18n.translate('timelion.function.help', { - defaultMessage: 'Timelion visualization' + defaultMessage: 'Timelion visualization', }), args: { expression: { @@ -43,11 +40,11 @@ export const timelionVis = () => ({ interval: { types: ['string', 'null'], default: 'auto', - } + }, }, - async fn(context, args) { + async fn(context: any, args: any) { const $injector = await chrome.dangerouslyGetActiveInjector(); - const Private = $injector.get('Private'); + const Private = $injector.get('Private') as any; const timelionRequestHandler = Private(TimelionRequestHandlerProvider).handler; const visParams = { expression: args.expression, interval: args.interval }; @@ -57,7 +54,7 @@ export const timelionVis = () => ({ query: get(context, 'query', null), filters: get(context, 'filters', null), forceFetch: true, - visParams: visParams, + visParams, }); response.visType = 'timelion'; diff --git a/src/legacy/core_plugins/timelion/public/vis/index.js b/src/legacy/core_plugins/timelion/public/vis/index.ts similarity index 95% rename from src/legacy/core_plugins/timelion/public/vis/index.js rename to src/legacy/core_plugins/timelion/public/vis/index.ts index d5be65c295472..7ea4f94bbc51b 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.js +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -17,17 +17,19 @@ * under the License. */ +// @ts-ignore import { VisFactoryProvider } from 'ui/vis/vis_factory'; import { i18n } from '@kbn/i18n'; -import { TimelionRequestHandlerProvider } from './timelion_request_handler'; +// @ts-ignore import { DefaultEditorSize } from 'ui/vis/editor_size'; // we also need to load the controller and directive used by the template import './timelion_vis_controller'; import '../directives/timelion_expression_input'; +import { TimelionRequestHandlerProvider } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; -export function TimelionVisProvider(Private) { +export function TimelionVisProvider(Private: any) { const VisFactory = Private(VisFactoryProvider); const timelionRequestHandler = Private(TimelionRequestHandlerProvider); @@ -43,7 +45,7 @@ export function TimelionVisProvider(Private) { visConfig: { defaults: { expression: '.es(*)', - interval: 'auto' + interval: 'auto', }, template: visConfigTemplate, }, diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.js b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts similarity index 66% rename from src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.js rename to src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index 21b6a243e77d9..fe826c2f6fcc3 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.js +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -18,42 +18,56 @@ */ import _ from 'lodash'; +// @ts-ignore import { buildEsQuery, getEsQueryConfig } from '@kbn/es-query'; +// @ts-ignore import { timezoneProvider } from 'ui/vis/lib/timezone'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; -const TimelionRequestHandlerProvider = function (Private, $http, config) { +const TimelionRequestHandlerProvider = function(Private: any, $http: any, config: any) { const timezone = Private(timezoneProvider)(); return { name: 'timelion', - handler: function ({ timeRange, filters, query, visParams }) { - + handler({ + timeRange, + filters, + query, + visParams, + }: { + timeRange: any; + filters: any; + query: any; + visParams: any; + }) { return new Promise((resolve, reject) => { const expression = visParams.expression; if (!expression) return; const esQueryConfigs = getEsQueryConfig(config); - const httpResult = $http.post('../api/timelion/run', { - sheet: [expression], - extended: { - es: { - filter: buildEsQuery(undefined, query, filters, esQueryConfigs) - } - }, - time: _.extend(timeRange, { - interval: visParams.interval, - timezone: timezone - }), - }) - .then(resp => resp.data) - .catch(resp => { throw resp.data; }); + const httpResult = $http + .post('../api/timelion/run', { + sheet: [expression], + extended: { + es: { + filter: buildEsQuery(undefined, query, filters, esQueryConfigs), + }, + }, + time: _.extend(timeRange, { + interval: visParams.interval, + timezone, + }), + }) + .then((resp: any) => resp.data) + .catch((resp: any) => { + throw resp.data; + }); httpResult - .then(function (resp) { + .then(function(resp: any) { resolve(resp); }) - .catch(function (resp) { + .catch(function(resp: any) { const err = new Error(resp.message); err.stack = resp.stack; toastNotifications.addError(err, { @@ -64,7 +78,7 @@ const TimelionRequestHandlerProvider = function (Private, $http, config) { reject(err); }); }); - } + }, }; }; From ffd604cc38ef9027bf0b194433c2472a0ff4323b Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 30 Aug 2019 16:27:45 +0300 Subject: [PATCH 07/42] Add ExpressionFunction<> to interpreter --- .../timelion/public/timelion_vis_fn.ts | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index 093a2e069ac3c..47f7c199a8a79 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -20,10 +20,34 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import chrome from 'ui/chrome'; +import { + ExpressionFunction, + KibanaContext, + Render, +} from 'src/plugins/data/common/expressions/types'; import { TimelionRequestHandlerProvider } from './vis/timelion_request_handler'; -export const timelionVis = () => ({ - name: 'timelion_vis', +const name = 'timelion_vis'; + +type Context = KibanaContext | null; + +interface Arguments { + expression: string; + interval: any; +} + +export type VisParams = Required; + +interface RenderValue { + visData: Context; + visType: typeof name; + visParams: VisParams; +} + +type Return = Promise>; + +export const timelionVis = (): ExpressionFunction => ({ + name, type: 'render', context: { types: ['kibana_context', 'null'], @@ -36,13 +60,15 @@ export const timelionVis = () => ({ types: ['string'], aliases: ['_'], default: '".es(*)"', + help: '', }, interval: { types: ['string', 'null'], default: 'auto', + help: '', }, }, - async fn(context: any, args: any) { + async fn(context, args) { const $injector = await chrome.dangerouslyGetActiveInjector(); const Private = $injector.get('Private') as any; const timelionRequestHandler = Private(TimelionRequestHandlerProvider).handler; @@ -64,7 +90,7 @@ export const timelionVis = () => ({ as: 'visualization', value: { visParams, - visType: 'timelion', + visType: name, visData: response, }, }; From 1369f6dcee60bab07292a0672483929b838a726b Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 30 Aug 2019 16:53:23 +0300 Subject: [PATCH 08/42] Remove Feature Provider --- src/legacy/core_plugins/timelion/public/legacy.ts | 2 -- src/legacy/core_plugins/timelion/public/plugin.ts | 4 ---- src/legacy/ui/public/registry/feature_catalogue.d.ts | 6 ++---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index 007666f3253b9..767c256ff084c 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -19,7 +19,6 @@ import { PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; -import { FeatureCatalogueRegistryProvider as featureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; import { plugin } from '.'; import { visualizations } from '../../visualizations/public'; import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; @@ -29,7 +28,6 @@ import panelRegistry from './lib/panel_registry'; const setupPlugins: Readonly = { visualizations, data: npSetup.plugins.data, - featureCatalogueRegistryProvider, }; const startPlugins: Readonly = { diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 03c178ae0ad95..fb6c6085f6e64 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -25,17 +25,14 @@ import { } from 'kibana/public'; import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/public'; import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; -import { IFeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue'; import { timelionVis } from './timelion_vis_fn'; import { TimelionVisProvider } from './vis'; -import { registerFeature } from './register_feature'; import { timeChartProvider } from './panels/timechart/timechart'; /** @internal */ export interface TimelionPluginSetupDependencies { data: ReturnType; visualizations: VisualizationsSetup; - featureCatalogueRegistryProvider: IFeatureCatalogueRegistryProvider; } /** @internal */ @@ -52,7 +49,6 @@ export class TimelionPlugin implements Plugin, void> { } public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { - plugins.featureCatalogueRegistryProvider.register(registerFeature); plugins.data.expressions.registerFunction(timelionVis); plugins.visualizations.types.VisTypesRegistryProvider.register(TimelionVisProvider); } diff --git a/src/legacy/ui/public/registry/feature_catalogue.d.ts b/src/legacy/ui/public/registry/feature_catalogue.d.ts index b45fd8d6fb47c..031c3efa6c5ad 100644 --- a/src/legacy/ui/public/registry/feature_catalogue.d.ts +++ b/src/legacy/ui/public/registry/feature_catalogue.d.ts @@ -37,8 +37,6 @@ interface FeatureCatalogueObject { type FeatureCatalogueRegistryFunction = (i18n: I18nServiceType) => FeatureCatalogueObject; -export interface IFeatureCatalogueRegistryProvider { +export const FeatureCatalogueRegistryProvider: { register: (fn: FeatureCatalogueRegistryFunction) => void; -} - -export const FeatureCatalogueRegistryProvider: IFeatureCatalogueRegistryProvider; +}; From 8c178f25efe3d1e954c47fc7a47162e6eb31dead Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 2 Sep 2019 11:49:39 +0300 Subject: [PATCH 09/42] Remove extra export --- src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index 47f7c199a8a79..774fbd58f3dcc 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -29,21 +29,19 @@ import { TimelionRequestHandlerProvider } from './vis/timelion_request_handler'; const name = 'timelion_vis'; -type Context = KibanaContext | null; - interface Arguments { expression: string; interval: any; } -export type VisParams = Required; - interface RenderValue { visData: Context; visType: typeof name; visParams: VisParams; } +type Context = KibanaContext | null; +type VisParams = Arguments; type Return = Promise>; export const timelionVis = (): ExpressionFunction => ({ From 630e0b0da31d913f6ce7b4a7cb48443ffe2c9803 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 2 Sep 2019 16:13:42 +0300 Subject: [PATCH 10/42] Add an interface to a timelion response --- .../timelion/public/timelion_vis_fn.ts | 20 ++++++---- .../public/vis/timelion_request_handler.ts | 38 ++++++++++++++++--- .../expression_types/kibana_context.ts | 1 + 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index 774fbd58f3dcc..10d9ea4b3fc61 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -20,12 +20,16 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import chrome from 'ui/chrome'; +import { IPrivate } from 'ui/private'; import { ExpressionFunction, KibanaContext, Render, } from 'src/plugins/data/common/expressions/types'; -import { TimelionRequestHandlerProvider } from './vis/timelion_request_handler'; +import { + TimelionRequestHandlerProvider, + TimelionSuccessResponse, +} from './vis/timelion_request_handler'; const name = 'timelion_vis'; @@ -68,18 +72,18 @@ export const timelionVis = (): ExpressionFunction>; + render: Record; + type: string; +} + +export interface TimelionSuccessResponse { + sheet: Sheet[]; + stats: Stats; + visType: string; + type: KIBANA_CONTEXT_NAME; +} + const TimelionRequestHandlerProvider = function(Private: any, $http: any, config: any) { const timezone = Private(timezoneProvider)(); @@ -36,10 +61,11 @@ const TimelionRequestHandlerProvider = function(Private: any, $http: any, config query, visParams, }: { - timeRange: any; - filters: any; - query: any; - visParams: any; + timeRange: TimeRange; + filters: Filter[]; + query: Query; + visParams: VisParams; + forceFetch?: boolean; }) { return new Promise((resolve, reject) => { const expression = visParams.expression; @@ -64,7 +90,7 @@ const TimelionRequestHandlerProvider = function(Private: any, $http: any, config }); httpResult - .then(function(resp: any) { + .then(function(resp: TimelionSuccessResponse) { resolve(resp); }) .catch(function(resp: any) { diff --git a/src/plugins/data/common/expressions/expression_types/kibana_context.ts b/src/plugins/data/common/expressions/expression_types/kibana_context.ts index 5ee3f7abbbdb0..d15b80f27882d 100644 --- a/src/plugins/data/common/expressions/expression_types/kibana_context.ts +++ b/src/plugins/data/common/expressions/expression_types/kibana_context.ts @@ -22,6 +22,7 @@ import { Query } from '../../query/types'; import { TimeRange } from '../../timefilter/types'; const name = 'kibana_context'; +export type KIBANA_CONTEXT_NAME = 'kibana_context'; export interface KibanaContext { type: typeof name; From e40b39918080100ed874d45b189720412ebb06e5 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 2 Sep 2019 16:39:03 +0300 Subject: [PATCH 11/42] Add an inteface to the panel --- .../core_plugins/timelion/public/panels/panel.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/panels/panel.ts b/src/legacy/core_plugins/timelion/public/panels/panel.ts index ea4a6c4376b1e..3512cd96a9596 100644 --- a/src/legacy/core_plugins/timelion/public/panels/panel.ts +++ b/src/legacy/core_plugins/timelion/public/panels/panel.ts @@ -19,12 +19,17 @@ import { i18n } from '@kbn/i18n'; +interface PanelConfig { + help?: string; + render?: Function; +} + export class Panel { - name: any; - help: any; - render: any; + name: string; + help: string; + render: Function | undefined; - constructor(name: any, config: any) { + constructor(name: string, config: PanelConfig) { this.name = name; this.help = config.help || ''; this.render = config.render; From a6212577c9b86b554556dfba5bee6e83d3d7389f Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 2 Sep 2019 17:32:28 +0300 Subject: [PATCH 12/42] Add IPrivate interface --- .../timelion/public/panels/timechart/timechart.ts | 5 +++-- src/legacy/core_plugins/timelion/public/vis/index.ts | 10 ++++++++-- .../timelion/public/vis/timelion_request_handler.ts | 5 +++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts index d1ceaa9f389ee..3ef1db6fd4236 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts @@ -17,10 +17,11 @@ * under the License. */ +import { IPrivate } from 'ui/private'; import { Panel } from '../panel'; -export function timeChartProvider(Private: any) { +export function timeChartProvider(Private: IPrivate) { // Schema is broken out so that it may be extended for use in other plugins // Its also easier to test. - return new Panel('timechart', Private(require('./schema'))()); + return new Panel('timechart', (Private(require('./schema')) as Function)()); } diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index 7ea4f94bbc51b..8374e8cd457f3 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -22,6 +22,7 @@ import { VisFactoryProvider } from 'ui/vis/vis_factory'; import { i18n } from '@kbn/i18n'; // @ts-ignore import { DefaultEditorSize } from 'ui/vis/editor_size'; +import { IPrivate } from 'ui/private'; // we also need to load the controller and directive used by the template import './timelion_vis_controller'; import '../directives/timelion_expression_input'; @@ -29,8 +30,13 @@ import { TimelionRequestHandlerProvider } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; -export function TimelionVisProvider(Private: any) { - const VisFactory = Private(VisFactoryProvider); +interface VisFactory { + createAngularVisualization: Function; + createVislibVisualization: Function; +} + +export function TimelionVisProvider(Private: IPrivate) { + const VisFactory = Private(VisFactoryProvider) as VisFactory; const timelionRequestHandler = Private(TimelionRequestHandlerProvider); // return the visType object, which kibana will use to display and configure new diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index fbefd8fa2966e..9965196657f7b 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -22,6 +22,7 @@ import _ from 'lodash'; import { buildEsQuery, getEsQueryConfig, Filter } from '@kbn/es-query'; // @ts-ignore import { timezoneProvider } from 'ui/vis/lib/timezone'; +import { IPrivate } from 'ui/private'; import { KIBANA_CONTEXT_NAME } from 'src/plugins/data/common/expressions/types'; import { Query } from 'src/legacy/core_plugins/data/public'; import { TimeRange } from 'src/plugins/data/public'; @@ -50,8 +51,8 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } -const TimelionRequestHandlerProvider = function(Private: any, $http: any, config: any) { - const timezone = Private(timezoneProvider)(); +const TimelionRequestHandlerProvider = function(Private: IPrivate, $http: any, config: any) { + const timezone = (Private(timezoneProvider) as Function)(); return { name: 'timelion', From 0abd64de32fdd4de6f8ad4b75a9b5aae44f731f8 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 2 Sep 2019 17:45:42 +0300 Subject: [PATCH 13/42] Make nit notes --- src/legacy/core_plugins/timelion/public/plugin.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index fb6c6085f6e64..e62763ed4f786 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -41,7 +41,9 @@ export interface TimelionPluginStartDependencies { } /** @internal */ -export class TimelionPlugin implements Plugin, void> { +export class TimelionPlugin + implements + Plugin, void, TimelionPluginSetupDependencies, TimelionPluginStartDependencies> { initializerContext: PluginInitializerContext; constructor(initializerContext: PluginInitializerContext) { From fc89dd0db4c5eb17eabbbd9e8da71ddaebd3ca97 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Tue, 3 Sep 2019 10:38:50 +0300 Subject: [PATCH 14/42] Edit uiCapabilities() type --- src/legacy/plugin_discovery/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/plugin_discovery/types.ts b/src/legacy/plugin_discovery/types.ts index b53cfa7240042..62a1b2d2f6046 100644 --- a/src/legacy/plugin_discovery/types.ts +++ b/src/legacy/plugin_discovery/types.ts @@ -75,7 +75,7 @@ export interface LegacyPluginOptions { interpreter?: string[]; uiSettingDefaults?: Record; }>; - uiCapabilities?: Capabilities | (() => Record); + uiCapabilities?: Capabilities | (() => Partial); publicDir: any; configPrefix: any; config: any; From 173816162a8a06876486a2c88c41580f33a2ef9b Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Tue, 3 Sep 2019 15:04:14 +0300 Subject: [PATCH 15/42] Shim Timelion plugin --- .../core_plugins/timelion/public/legacy.ts | 5 ++ .../core_plugins/timelion/public/plugin.ts | 16 ++++-- .../timelion/public/shim/index.ts | 20 ++++++++ .../public/shim/legacy_dependencies_plugin.ts | 49 +++++++++++++++++++ .../timelion/public/timelion_vis_fn.ts | 13 +++-- .../core_plugins/timelion/public/vis/index.ts | 19 +++---- .../public/vis/timelion_request_handler.ts | 11 ++--- 7 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 src/legacy/core_plugins/timelion/public/shim/index.ts create mode 100644 src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index 767c256ff084c..a986be62b2a94 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -24,10 +24,15 @@ import { visualizations } from '../../visualizations/public'; import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; // @ts-ignore import panelRegistry from './lib/panel_registry'; +import { LegacyDependenciesPlugin } from './shim'; const setupPlugins: Readonly = { visualizations, data: npSetup.plugins.data, + + // Temporary solution + // It will be removed when all dependent services are migrated to the new platform. + __LEGACY: new LegacyDependenciesPlugin(), }; const startPlugins: Readonly = { diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index e62763ed4f786..0112e55aff03d 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -25,14 +25,18 @@ import { } from 'kibana/public'; import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/public'; import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; -import { timelionVis } from './timelion_vis_fn'; -import { TimelionVisProvider } from './vis'; +import { getTimelionVisualizationConfig } from './timelion_vis_fn'; +import { getTimelionVisualization } from './vis'; import { timeChartProvider } from './panels/timechart/timechart'; +import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'; /** @internal */ export interface TimelionPluginSetupDependencies { data: ReturnType; visualizations: VisualizationsSetup; + + // Temporary solution + __LEGACY: LegacyDependenciesPlugin; } /** @internal */ @@ -51,8 +55,12 @@ export class TimelionPlugin } public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { - plugins.data.expressions.registerFunction(timelionVis); - plugins.visualizations.types.VisTypesRegistryProvider.register(TimelionVisProvider); + const dependencies: LegacyDependenciesPluginSetup = await plugins.__LEGACY.setup(); + + plugins.data.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); + plugins.visualizations.types.VisTypesRegistryProvider.register(() => + getTimelionVisualization(dependencies) + ); } public start(core: CoreStart & InternalCoreStart, plugins: TimelionPluginStartDependencies) { diff --git a/src/legacy/core_plugins/timelion/public/shim/index.ts b/src/legacy/core_plugins/timelion/public/shim/index.ts new file mode 100644 index 0000000000000..cfc7b62ff4f86 --- /dev/null +++ b/src/legacy/core_plugins/timelion/public/shim/index.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export * from './legacy_dependencies_plugin'; diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts new file mode 100644 index 0000000000000..b75899efa60ff --- /dev/null +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -0,0 +1,49 @@ +/* + * 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 chrome from 'ui/chrome'; +import 'ui/es'; // required for $injector.get('es') below +import { CoreStart, Plugin } from 'kibana/public'; +// @ts-ignore +import { VisFactoryProvider } from 'ui/vis/vis_factory'; + +/** @internal */ +export interface LegacyDependenciesPluginSetup { + $http: any; + config: any; + createAngularVisualization: Function; +} + +export class LegacyDependenciesPlugin + implements Plugin, void> { + public async setup() { + const $injector = await chrome.dangerouslyGetActiveInjector(); + const Private = $injector.get('Private'); + + return { + $http: $injector.get('$http'), + config: chrome.getUiSettingsClient(), + createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, + } as LegacyDependenciesPluginSetup; + } + + public start(core: CoreStart) { + // nothing to do here yet + } +} diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index 10d9ea4b3fc61..b52de09ab0bba 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -19,17 +19,16 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import chrome from 'ui/chrome'; -import { IPrivate } from 'ui/private'; import { ExpressionFunction, KibanaContext, Render, } from 'src/plugins/data/common/expressions/types'; import { - TimelionRequestHandlerProvider, + getTimelionRequestProvider, TimelionSuccessResponse, } from './vis/timelion_request_handler'; +import { LegacyDependenciesPluginSetup } from './shim'; const name = 'timelion_vis'; @@ -48,7 +47,9 @@ type Context = KibanaContext | null; type VisParams = Arguments; type Return = Promise>; -export const timelionVis = (): ExpressionFunction => ({ +export const getTimelionVisualizationConfig = ( + dependencies: LegacyDependenciesPluginSetup +): ExpressionFunction => ({ name, type: 'render', context: { @@ -71,9 +72,7 @@ export const timelionVis = (): ExpressionFunction Date: Tue, 3 Sep 2019 15:44:07 +0300 Subject: [PATCH 16/42] Shim start() plugin method --- .../core_plugins/timelion/public/legacy.ts | 4 ++++ .../public/panels/timechart/schema.js | 7 +++--- .../public/panels/timechart/timechart.ts | 8 ++++--- .../core_plugins/timelion/public/plugin.ts | 19 ++++++++++++---- .../public/shim/legacy_dependencies_plugin.ts | 22 +++++++++++++++---- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index a986be62b2a94..9a33f21014263 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -37,6 +37,10 @@ const setupPlugins: Readonly = { const startPlugins: Readonly = { panelRegistry, + + // Temporary solution + // It will be removed when all dependent services are migrated to the new platform. + __LEGACY: new LegacyDependenciesPlugin(), }; const pluginInstance = plugin({} as PluginInitializerContext); diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.js b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.js index 20e3338ea74fd..f6b18adc413d9 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.js +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.js @@ -27,15 +27,16 @@ import { timefilter } from 'ui/timefilter'; const DEBOUNCE_DELAY = 50; -export default function timechartFn(Private, config, $rootScope, $compile) { +export function timechartFn(dependencies) { + const { config, $rootScope, $compile } = dependencies; return function () { return { help: 'Draw a timeseries chart', render: function ($scope, $elem) { const template = '
'; const tickFormatters = require('plugins/timelion/services/tick_formatters')(); - const getxAxisFormatter = Private(require('plugins/timelion/panels/timechart/xaxis_formatter')); - const generateTicks = Private(require('plugins/timelion/panels/timechart/tick_generator')); + const getxAxisFormatter = require('plugins/timelion/panels/timechart/xaxis_formatter')(config); + const generateTicks = require('plugins/timelion/panels/timechart/tick_generator')(); // TODO: I wonder if we should supply our own moment that sets this every time? // could just use angular's injection to provide a moment service? diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts index 3ef1db6fd4236..866314d32a955 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts @@ -17,11 +17,13 @@ * under the License. */ -import { IPrivate } from 'ui/private'; +// @ts-ignore +import { timechartFn } from './schema'; import { Panel } from '../panel'; +import { LegacyDependenciesPluginStart } from '../../shim'; -export function timeChartProvider(Private: IPrivate) { +export function getTimeChart(dependencies: LegacyDependenciesPluginStart) { // Schema is broken out so that it may be extended for use in other plugins // Its also easier to test. - return new Panel('timechart', (Private(require('./schema')) as Function)()); + return new Panel('timechart', timechartFn(dependencies)()); } diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 0112e55aff03d..f723a8efd2739 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -27,8 +27,12 @@ import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/publ import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; import { getTimelionVisualizationConfig } from './timelion_vis_fn'; import { getTimelionVisualization } from './vis'; -import { timeChartProvider } from './panels/timechart/timechart'; -import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'; +import { getTimeChart } from './panels/timechart/timechart'; +import { + LegacyDependenciesPlugin, + LegacyDependenciesPluginSetup, + LegacyDependenciesPluginStart, +} from './shim'; /** @internal */ export interface TimelionPluginSetupDependencies { @@ -42,6 +46,9 @@ export interface TimelionPluginSetupDependencies { /** @internal */ export interface TimelionPluginStartDependencies { panelRegistry: any; + + // Temporary solution + __LEGACY: LegacyDependenciesPlugin; } /** @internal */ @@ -63,14 +70,18 @@ export class TimelionPlugin ); } - public start(core: CoreStart & InternalCoreStart, plugins: TimelionPluginStartDependencies) { + public async start( + core: CoreStart & InternalCoreStart, + plugins: TimelionPluginStartDependencies + ) { + const dependencies: LegacyDependenciesPluginStart = await plugins.__LEGACY.start(); const timelionUiEnabled = core.injectedMetadata.getInjectedVar('timelionUiEnabled'); if (timelionUiEnabled === false) { core.chrome.navLinks.update('timelion', { hidden: true }); } - plugins.panelRegistry.register(timeChartProvider); + plugins.panelRegistry.register(() => getTimeChart(dependencies)); } public stop(): void {} diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index b75899efa60ff..22476f313c6dc 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -19,7 +19,7 @@ import chrome from 'ui/chrome'; import 'ui/es'; // required for $injector.get('es') below -import { CoreStart, Plugin } from 'kibana/public'; +import { Plugin } from 'kibana/public'; // @ts-ignore import { VisFactoryProvider } from 'ui/vis/vis_factory'; @@ -30,8 +30,16 @@ export interface LegacyDependenciesPluginSetup { createAngularVisualization: Function; } +/** @internal */ +export interface LegacyDependenciesPluginStart { + $rootScope: any; + $compile: any; + config: any; +} + export class LegacyDependenciesPlugin - implements Plugin, void> { + implements + Plugin, Promise> { public async setup() { const $injector = await chrome.dangerouslyGetActiveInjector(); const Private = $injector.get('Private'); @@ -43,7 +51,13 @@ export class LegacyDependenciesPlugin } as LegacyDependenciesPluginSetup; } - public start(core: CoreStart) { - // nothing to do here yet + public async start() { + const $injector = await chrome.dangerouslyGetActiveInjector(); + + return { + $rootScope: $injector.get('$rootScope'), + $compile: $injector.get('$compile'), + config: chrome.getUiSettingsClient(), + } as LegacyDependenciesPluginStart; } } From 5308ca7ca927c923d4600f14642e57b93287311a Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 4 Sep 2019 12:12:01 +0300 Subject: [PATCH 17/42] Change InternalCoreStart to LegacyCoreStart --- src/legacy/core_plugins/timelion/public/plugin.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index f723a8efd2739..c15378c04a059 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -19,7 +19,7 @@ import { CoreSetup, CoreStart, - InternalCoreStart, + LegacyCoreStart, Plugin, PluginInitializerContext, } from 'kibana/public'; @@ -70,10 +70,7 @@ export class TimelionPlugin ); } - public async start( - core: CoreStart & InternalCoreStart, - plugins: TimelionPluginStartDependencies - ) { + public async start(core: CoreStart & LegacyCoreStart, plugins: TimelionPluginStartDependencies) { const dependencies: LegacyDependenciesPluginStart = await plugins.__LEGACY.start(); const timelionUiEnabled = core.injectedMetadata.getInjectedVar('timelionUiEnabled'); From 29eea85987c433af4ac5c5bab4387f05db471337 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 4 Sep 2019 15:51:14 +0300 Subject: [PATCH 18/42] Move Angular dependencies to a separate module --- .../timelion/public/directives/chart/chart.js | 79 +++++++++---------- .../directives/timelion_expression_input.js | 7 +- .../timelion_expression_suggestions.js | 6 +- .../timelion_interval/timelion_interval.js | 7 +- .../public/shim/legacy_dependencies_plugin.ts | 4 + .../public/shim/timelion_legacy_module.ts | 54 +++++++++++++ .../core_plugins/timelion/public/vis/index.ts | 3 - .../public/vis/timelion_vis_controller.js | 34 -------- 8 files changed, 103 insertions(+), 91 deletions(-) create mode 100644 src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts delete mode 100644 src/legacy/core_plugins/timelion/public/vis/timelion_vis_controller.js diff --git a/src/legacy/core_plugins/timelion/public/directives/chart/chart.js b/src/legacy/core_plugins/timelion/public/directives/chart/chart.js index 7a898d7b3e161..2869f7fd992c8 100644 --- a/src/legacy/core_plugins/timelion/public/directives/chart/chart.js +++ b/src/legacy/core_plugins/timelion/public/directives/chart/chart.js @@ -17,55 +17,52 @@ * under the License. */ import panelRegistryProvider from '../../lib/panel_registry'; - import { i18n } from '@kbn/i18n'; -require('ui/modules') - .get('apps/timelion', []) - .directive('chart', function (Private) { - return { - restrict: 'A', - scope: { - seriesList: '=chart', // The flot object, data, config and all - search: '=', // The function to execute to kick off a search - interval: '=', // Required for formatting x-axis ticks - rerenderTrigger: '=', - }, - link: function ($scope, $elem) { - - const panelRegistry = Private(panelRegistryProvider); - let panelScope = $scope.$new(true); - - function render() { - panelScope.$destroy(); +export function makeChart(Private) { + return { + restrict: 'A', + scope: { + seriesList: '=chart', // The flot object, data, config and all + search: '=', // The function to execute to kick off a search + interval: '=', // Required for formatting x-axis ticks + rerenderTrigger: '=', + }, + link: function ($scope, $elem) { - if (!$scope.seriesList) return; + const panelRegistry = Private(panelRegistryProvider); + let panelScope = $scope.$new(true); - $scope.seriesList.render = $scope.seriesList.render || { - type: 'timechart' - }; + function render() { + panelScope.$destroy(); - const panelSchema = panelRegistry.byName[$scope.seriesList.render.type]; + if (!$scope.seriesList) return; - if (!panelSchema) { - $elem.text( - i18n.translate('timelion.chart.seriesList.noSchemaWarning', { - defaultMessage: 'No such panel type: {renderType}', - values: { renderType: $scope.seriesList.render.type }, - }) - ); - return; - } + $scope.seriesList.render = $scope.seriesList.render || { + type: 'timechart' + }; - panelScope = $scope.$new(true); - panelScope.seriesList = $scope.seriesList; - panelScope.interval = $scope.interval; - panelScope.search = $scope.search; + const panelSchema = panelRegistry.byName[$scope.seriesList.render.type]; - panelSchema.render(panelScope, $elem); + if (!panelSchema) { + $elem.text( + i18n.translate('timelion.chart.seriesList.noSchemaWarning', { + defaultMessage: 'No such panel type: {renderType}', + values: { renderType: $scope.seriesList.render.type }, + }) + ); + return; } - $scope.$watchGroup(['seriesList', 'rerenderTrigger'], render); + panelScope = $scope.$new(true); + panelScope.seriesList = $scope.seriesList; + panelScope.interval = $scope.interval; + panelScope.search = $scope.search; + + panelSchema.render(panelScope, $elem); } - }; - }); + + $scope.$watchGroup(['seriesList', 'rerenderTrigger'], render); + } + }; +} diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js index 498636df9250b..407671f2431f7 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js @@ -43,9 +43,7 @@ import _ from 'lodash'; import $ from 'jquery'; import PEG from 'pegjs'; - import grammar from 'raw-loader!../chain.peg'; -import './timelion_expression_suggestions/timelion_expression_suggestions'; import timelionExpressionInputTemplate from './timelion_expression_input.html'; import { SUGGESTION_TYPE, @@ -57,9 +55,8 @@ import { comboBoxKeyCodes } from '@elastic/eui'; import { ArgValueSuggestionsProvider } from './timelion_expression_suggestions/arg_value_suggestions'; const Parser = PEG.generate(grammar); -const app = require('ui/modules').get('apps/timelion', []); -app.directive('timelionExpressionInput', function ($http, $timeout, Private) { +export function makeTimelionExpInput($http, $timeout, Private) { return { restrict: 'E', scope: { @@ -276,4 +273,4 @@ app.directive('timelionExpressionInput', function ($http, $timeout, Private) { init(); } }; -}); +} diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js index fc2bd094989ff..e721a609f0d69 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js @@ -19,9 +19,7 @@ import template from './timelion_expression_suggestions.html'; -const app = require('ui/modules').get('apps/timelion', []); - -app.directive('timelionExpressionSuggestions', () => { +export function makeTimelionExpressionSuggestions() { return { restrict: 'E', scope: { @@ -38,4 +36,4 @@ app.directive('timelionExpressionSuggestions', () => { scope.onMouseDown = e => e.preventDefault(); } }; -}); +} diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js b/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js index 7323874e62f95..fce1320a77471 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js @@ -19,11 +19,9 @@ import _ from 'lodash'; import $ from 'jquery'; - -const app = require('ui/modules').get('apps/timelion', []); import template from './timelion_interval.html'; -app.directive('timelionInterval', function ($timeout) { +export function makeTimelionInterval($timeout) { return { restrict: 'E', scope: { @@ -81,4 +79,5 @@ app.directive('timelionInterval', function ($timeout) { }); } }; -}); +} + diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index 22476f313c6dc..4ccf6e8a79151 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -22,6 +22,7 @@ import 'ui/es'; // required for $injector.get('es') below import { Plugin } from 'kibana/public'; // @ts-ignore import { VisFactoryProvider } from 'ui/vis/vis_factory'; +import { initTimelionLegacyModule } from './timelion_legacy_module'; /** @internal */ export interface LegacyDependenciesPluginSetup { @@ -41,6 +42,9 @@ export class LegacyDependenciesPlugin implements Plugin, Promise> { public async setup() { + // Init kibana/timelion_vis AngularJS module. + initTimelionLegacyModule(); + const $injector = await chrome.dangerouslyGetActiveInjector(); const Private = $injector.get('Private'); diff --git a/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts b/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts new file mode 100644 index 0000000000000..ea783f899e088 --- /dev/null +++ b/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts @@ -0,0 +1,54 @@ +/* + * 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 'ngreact'; +import 'brace/mode/hjson'; +import 'brace/ext/searchbox'; +import 'ui/accessibility/kbn_ui_ace_keyboard_mode'; +import 'ui/vis/map/service_settings'; + +import { once } from 'lodash'; +// @ts-ignore +import { uiModules } from 'ui/modules'; +// @ts-ignore +import { makeChart } from '../directives/chart/chart'; +// @ts-ignore +import { makeTimelionInterval } from '../directives/timelion_interval/timelion_interval'; +// @ts-ignore +import { makeTimelionExpInput } from '../directives/timelion_expression_input'; +// @ts-ignore +import { makeTimelionExpressionSuggestions } from '../directives/timelion_expression_suggestions/timelion_expression_suggestions'; + +/** @internal */ +export const initTimelionLegacyModule = once((): void => { + require('ui/state_management/app_state'); + + uiModules + .get('kibana/timelion_vis', ['kibana']) + .controller('TimelionVisController', function($scope: any) { + $scope.$on('timelionChartRendered', (event: any) => { + event.stopPropagation(); + $scope.renderComplete(); + }); + }) + .directive('chart', makeChart) + .directive('timelionInterval', makeTimelionInterval) + .directive('timelionExpressionSuggestions', makeTimelionExpressionSuggestions) + .directive('timelionExpressionInput', makeTimelionExpInput); +}); diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index 8d9f7b137ba7a..d8ff5ec799e31 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -21,9 +21,6 @@ import { i18n } from '@kbn/i18n'; // @ts-ignore import { DefaultEditorSize } from 'ui/vis/editor_size'; -// we also need to load the controller and directive used by the template -import './timelion_vis_controller'; -import '../directives/timelion_expression_input'; import { getTimelionRequestProvider } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_vis_controller.js b/src/legacy/core_plugins/timelion/public/vis/timelion_vis_controller.js deleted file mode 100644 index d621dd4b9cd8f..0000000000000 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_vis_controller.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 '../directives/chart/chart'; -import '../directives/timelion_interval/timelion_interval'; -import 'ui/state_management/app_state'; - -import { uiModules } from 'ui/modules'; - -uiModules - .get('kibana/timelion_vis', ['kibana']) - .controller('TimelionVisController', function ($scope) { - $scope.$on('timelionChartRendered', event => { - event.stopPropagation(); - $scope.renderComplete(); - }); - }); From eae077a64cce809d2689a42ee23f2cd4b6d27d36 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Thu, 5 Sep 2019 15:21:46 +0300 Subject: [PATCH 19/42] Change visualizations import path due to recent changes --- src/legacy/core_plugins/timelion/public/legacy.ts | 2 +- src/legacy/core_plugins/timelion/public/plugin.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index 9a33f21014263..542823c8e21c7 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -20,7 +20,7 @@ import { PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; import { plugin } from '.'; -import { visualizations } from '../../visualizations/public'; +import { setup as visualizations } from '../../visualizations/public/np_ready/public/legacy'; import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; // @ts-ignore import panelRegistry from './lib/panel_registry'; diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index c15378c04a059..147a777f11955 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -23,8 +23,8 @@ import { Plugin, PluginInitializerContext, } from 'kibana/public'; -import { VisualizationsSetup } from 'src/legacy/core_plugins/visualizations/public'; import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; +import { VisualizationsSetup } from '../../visualizations/public/np_ready/public'; import { getTimelionVisualizationConfig } from './timelion_vis_fn'; import { getTimelionVisualization } from './vis'; import { getTimeChart } from './panels/timechart/timechart'; @@ -65,7 +65,7 @@ export class TimelionPlugin const dependencies: LegacyDependenciesPluginSetup = await plugins.__LEGACY.setup(); plugins.data.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); - plugins.visualizations.types.VisTypesRegistryProvider.register(() => + plugins.visualizations.types.registerVisualization(() => getTimelionVisualization(dependencies) ); } From b8bd9eade913c73af2e170f00097be078eb35e71 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 6 Sep 2019 12:36:14 +0300 Subject: [PATCH 20/42] Rename directives --- .../timelion/public/directives/chart/chart.js | 2 +- .../directives/timelion_expression_input.js | 2 +- .../timelion_expression_suggestions.js | 2 +- .../timelion_interval/timelion_interval.js | 2 +- .../public/shim/timelion_legacy_module.ts | 18 +++++++++--------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/directives/chart/chart.js b/src/legacy/core_plugins/timelion/public/directives/chart/chart.js index 2869f7fd992c8..0a95b489aa2e1 100644 --- a/src/legacy/core_plugins/timelion/public/directives/chart/chart.js +++ b/src/legacy/core_plugins/timelion/public/directives/chart/chart.js @@ -19,7 +19,7 @@ import panelRegistryProvider from '../../lib/panel_registry'; import { i18n } from '@kbn/i18n'; -export function makeChart(Private) { +export function Chart(Private) { return { restrict: 'A', scope: { diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js index 407671f2431f7..f7676d9267a52 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js @@ -56,7 +56,7 @@ import { ArgValueSuggestionsProvider } from './timelion_expression_suggestions/a const Parser = PEG.generate(grammar); -export function makeTimelionExpInput($http, $timeout, Private) { +export function TimelionExpInput($http, $timeout, Private) { return { restrict: 'E', scope: { diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js index e721a609f0d69..4ea6d19ff308b 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_suggestions/timelion_expression_suggestions.js @@ -19,7 +19,7 @@ import template from './timelion_expression_suggestions.html'; -export function makeTimelionExpressionSuggestions() { +export function TimelionExpressionSuggestions() { return { restrict: 'E', scope: { diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js b/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js index fce1320a77471..24247fd86a2ce 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_interval/timelion_interval.js @@ -21,7 +21,7 @@ import _ from 'lodash'; import $ from 'jquery'; import template from './timelion_interval.html'; -export function makeTimelionInterval($timeout) { +export function TimelionInterval($timeout) { return { restrict: 'E', scope: { diff --git a/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts b/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts index ea783f899e088..c461973172865 100644 --- a/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts +++ b/src/legacy/core_plugins/timelion/public/shim/timelion_legacy_module.ts @@ -27,28 +27,28 @@ import { once } from 'lodash'; // @ts-ignore import { uiModules } from 'ui/modules'; // @ts-ignore -import { makeChart } from '../directives/chart/chart'; +import { Chart } from '../directives/chart/chart'; // @ts-ignore -import { makeTimelionInterval } from '../directives/timelion_interval/timelion_interval'; +import { TimelionInterval } from '../directives/timelion_interval/timelion_interval'; // @ts-ignore -import { makeTimelionExpInput } from '../directives/timelion_expression_input'; +import { TimelionExpInput } from '../directives/timelion_expression_input'; // @ts-ignore -import { makeTimelionExpressionSuggestions } from '../directives/timelion_expression_suggestions/timelion_expression_suggestions'; +import { TimelionExpressionSuggestions } from '../directives/timelion_expression_suggestions/timelion_expression_suggestions'; /** @internal */ export const initTimelionLegacyModule = once((): void => { require('ui/state_management/app_state'); uiModules - .get('kibana/timelion_vis', ['kibana']) + .get('apps/timelion', []) .controller('TimelionVisController', function($scope: any) { $scope.$on('timelionChartRendered', (event: any) => { event.stopPropagation(); $scope.renderComplete(); }); }) - .directive('chart', makeChart) - .directive('timelionInterval', makeTimelionInterval) - .directive('timelionExpressionSuggestions', makeTimelionExpressionSuggestions) - .directive('timelionExpressionInput', makeTimelionExpInput); + .directive('chart', Chart) + .directive('timelionInterval', TimelionInterval) + .directive('timelionExpressionSuggestions', TimelionExpressionSuggestions) + .directive('timelionExpressionInput', TimelionExpInput); }); From 60f2a5d4c6281aa1a73a2ced7ea13601ed16d33f Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 6 Sep 2019 13:03:35 +0300 Subject: [PATCH 21/42] Take a common property out --- src/legacy/core_plugins/timelion/public/legacy.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index 542823c8e21c7..ce14194d4c2ce 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -26,21 +26,19 @@ import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from import panelRegistry from './lib/panel_registry'; import { LegacyDependenciesPlugin } from './shim'; +// Temporary solution +// It will be removed when all dependent services are migrated to the new platform. +const __LEGACY = new LegacyDependenciesPlugin(); + const setupPlugins: Readonly = { visualizations, data: npSetup.plugins.data, - - // Temporary solution - // It will be removed when all dependent services are migrated to the new platform. - __LEGACY: new LegacyDependenciesPlugin(), + __LEGACY, }; const startPlugins: Readonly = { panelRegistry, - - // Temporary solution - // It will be removed when all dependent services are migrated to the new platform. - __LEGACY: new LegacyDependenciesPlugin(), + __LEGACY, }; const pluginInstance = plugin({} as PluginInitializerContext); From afe69c4030b93e0fd67a8f5c6d4eb8ac775bd239 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 6 Sep 2019 14:00:55 +0300 Subject: [PATCH 22/42] Get rid of require in schema --- .../panels/timechart/{schema.js => schema.ts} | 163 ++++++++++-------- .../{tick_generator.js => tick_generator.ts} | 17 +- .../public/panels/timechart/timechart.ts | 1 - ...{xaxis_formatter.js => xaxis_formatter.ts} | 9 +- ...{tick_formatters.js => tick_formatters.ts} | 37 ++-- 5 files changed, 129 insertions(+), 98 deletions(-) rename src/legacy/core_plugins/timelion/public/panels/timechart/{schema.js => schema.ts} (72%) rename src/legacy/core_plugins/timelion/public/panels/timechart/{tick_generator.js => tick_generator.ts} (81%) rename src/legacy/core_plugins/timelion/public/panels/timechart/{xaxis_formatter.js => xaxis_formatter.ts} (91%) rename src/legacy/core_plugins/timelion/public/services/{tick_formatters.js => tick_formatters.ts} (70%) diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.js b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts similarity index 72% rename from src/legacy/core_plugins/timelion/public/panels/timechart/schema.js rename to src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts index f6b18adc413d9..042addb9aa139 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.js +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts @@ -17,26 +17,32 @@ * under the License. */ -require('./flot'); +import './flot'; import _ from 'lodash'; import $ from 'jquery'; import moment from 'moment-timezone'; +import { timefilter } from 'ui/timefilter'; +// @ts-ignore import observeResize from '../../lib/observe_resize'; +// @ts-ignore import { calculateInterval, DEFAULT_TIME_FORMAT } from '../../../common/lib'; -import { timefilter } from 'ui/timefilter'; +import { LegacyDependenciesPluginStart } from '../../shim'; +import { tickFormatters } from '../../services/tick_formatters'; +import { xaxisFormatterProvider } from './xaxis_formatter'; +import { generateTicksProvider } from './tick_generator'; const DEBOUNCE_DELAY = 50; -export function timechartFn(dependencies) { +export function timechartFn(dependencies: LegacyDependenciesPluginStart) { const { config, $rootScope, $compile } = dependencies; - return function () { + return function() { return { help: 'Draw a timeseries chart', - render: function ($scope, $elem) { + render($scope: any, $elem: any) { const template = '
'; - const tickFormatters = require('plugins/timelion/services/tick_formatters')(); - const getxAxisFormatter = require('plugins/timelion/panels/timechart/xaxis_formatter')(config); - const generateTicks = require('plugins/timelion/panels/timechart/tick_generator')(); + const formatters = tickFormatters() as any; + const getxAxisFormatter = xaxisFormatterProvider(config); + const generateTicks = generateTicksProvider(); // TODO: I wonder if we should supply our own moment that sets this every time? // could just use angular's injection to provide a moment service? @@ -48,12 +54,12 @@ export function timechartFn(dependencies) { $scope.interval = $scope.interval; $scope.search = $scope.search || _.noop; - let legendValueNumbers; - let legendCaption; + let legendValueNumbers: any; + let legendCaption: any; const debouncedSetLegendNumbers = _.debounce(setLegendNumbers, DEBOUNCE_DELAY, { maxWait: DEBOUNCE_DELAY, leading: true, - trailing: false + trailing: false, }); // ensure legend is the same height with or without a caption so legend items do not move around const emptyCaption = '
'; @@ -66,12 +72,12 @@ export function timechartFn(dependencies) { }, selection: { mode: 'x', - color: '#ccc' + color: '#ccc', }, crosshair: { mode: 'x', color: '#C66', - lineWidth: 2 + lineWidth: 2, }, grid: { show: render.grid, @@ -79,13 +85,13 @@ export function timechartFn(dependencies) { borderColor: null, margin: 10, hoverable: true, - autoHighlight: false + autoHighlight: false, }, legend: { backgroundColor: 'rgb(255,255,255,0)', position: 'nw', labelBoxBorderColor: 'rgb(255,255,255,0)', - labelFormatter: function (label, series) { + labelFormatter(label: any, series: any) { const wrapperSpan = document.createElement('span'); const labelSpan = document.createElement('span'); const numberSpan = document.createElement('span'); @@ -104,13 +110,24 @@ export function timechartFn(dependencies) { wrapperSpan.appendChild(numberSpan); return wrapperSpan.outerHTML; - } + }, }, - colors: ['#01A4A4', '#C66', '#D0D102', '#616161', '#00A1CB', '#32742C', '#F18D05', '#113F8C', '#61AE24', '#D70060'] + colors: [ + '#01A4A4', + '#C66', + '#D0D102', + '#616161', + '#00A1CB', + '#32742C', + '#F18D05', + '#113F8C', + '#61AE24', + '#D70060', + ], }; const originalColorMap = new Map(); - $scope.chart.forEach((series, seriesIndex) => { + $scope.chart.forEach((series: any, seriesIndex: any) => { if (!series.color) { const colorIndex = seriesIndex % defaultOptions.colors.length; series.color = defaultOptions.colors[colorIndex]; @@ -118,8 +135,8 @@ export function timechartFn(dependencies) { originalColorMap.set(series, series.color); }); - let highlightedSeries; - let focusedSeries; + let highlightedSeries: any; + let focusedSeries: any; function unhighlightSeries() { if (highlightedSeries === null) { return; @@ -127,18 +144,18 @@ export function timechartFn(dependencies) { highlightedSeries = null; focusedSeries = null; - $scope.chart.forEach((series) => { + $scope.chart.forEach((series: any) => { series.color = originalColorMap.get(series); // reset the colors }); drawPlot($scope.chart); } - $scope.highlightSeries = _.debounce(function (id) { + $scope.highlightSeries = _.debounce(function(id: any) { if (highlightedSeries === id) { return; } highlightedSeries = id; - $scope.chart.forEach((series, seriesIndex) => { + $scope.chart.forEach((series: any, seriesIndex: any) => { if (seriesIndex !== id) { series.color = 'rgba(128,128,128,0.1)'; // mark as grey } else { @@ -147,58 +164,57 @@ export function timechartFn(dependencies) { }); drawPlot($scope.chart); }, DEBOUNCE_DELAY); - $scope.focusSeries = function (id) { + $scope.focusSeries = function(id: any) { focusedSeries = id; $scope.highlightSeries(id); }; - $scope.toggleSeries = function (id) { + $scope.toggleSeries = function(id: any) { const series = $scope.chart[id]; series._hide = !series._hide; drawPlot($scope.chart); }; - const cancelResize = observeResize($elem, function () { + const cancelResize = observeResize($elem, function() { drawPlot($scope.chart); }); - $scope.$on('$destroy', function () { + $scope.$on('$destroy', function() { cancelResize(); $elem.off('plothover'); $elem.off('plotselected'); $elem.off('mouseleave'); }); - $elem.on('plothover', function (event, pos, item) { + $elem.on('plothover', function(event: any, pos: any, item: any) { $rootScope.$broadcast('timelionPlotHover', event, pos, item); }); - $elem.on('plotselected', function (event, ranges) { + $elem.on('plotselected', function(event: any, ranges: any) { timefilter.setTime({ from: moment(ranges.xaxis.from), to: moment(ranges.xaxis.to), - mode: 'absolute', }); }); - $elem.on('mouseleave', function () { + $elem.on('mouseleave', function() { $rootScope.$broadcast('timelionPlotLeave'); }); - $scope.$on('timelionPlotHover', function (angularEvent, flotEvent, pos) { + $scope.$on('timelionPlotHover', function(angularEvent: any, flotEvent: any, pos: any) { if (!$scope.plot) return; $scope.plot.setCrosshair(pos); debouncedSetLegendNumbers(pos); }); - $scope.$on('timelionPlotLeave', function () { + $scope.$on('timelionPlotLeave', function() { if (!$scope.plot) return; $scope.plot.clearCrosshair(); clearLegendNumbers(); }); // Shamelessly borrowed from the flotCrosshairs example - function setLegendNumbers(pos) { + function setLegendNumbers(pos: any) { unhighlightSeries(); const plot = $scope.plot; @@ -212,10 +228,13 @@ export function timechartFn(dependencies) { let j; const dataset = plot.getData(); if (legendCaption) { - legendCaption.text(moment(pos.x).format(_.get(dataset, '[0]._global.legend.timeFormat', DEFAULT_TIME_FORMAT))); + legendCaption.text( + moment(pos.x).format( + _.get(dataset, '[0]._global.legend.timeFormat', DEFAULT_TIME_FORMAT) + ) + ); } for (i = 0; i < dataset.length; ++i) { - const series = dataset[i]; const precision = _.get(series, '_meta.precision', 2); @@ -249,13 +268,13 @@ export function timechartFn(dependencies) { if (legendCaption) { legendCaption.html(emptyCaption); } - _.each(legendValueNumbers, function (num) { + _.each(legendValueNumbers, function(num) { $(num).empty(); }); } let legendScope = $scope.$new(); - function drawPlot(plotConfig) { + function drawPlot(plotConfig: any) { if (!$('.chart-canvas', $elem).length) $elem.html(template); const canvasElem = $('.chart-canvas', $elem); @@ -265,56 +284,63 @@ export function timechartFn(dependencies) { return; } - const title = _(plotConfig).map('_title').compact().last(); + const title = _(plotConfig) + .map('_title') + .compact() + .last() as any; $('.chart-top-title', $elem).text(title == null ? '' : title); - const options = _.cloneDeep(defaultOptions); + const options = _.cloneDeep(defaultOptions) as any; // Get the X-axis tick format - const time = timefilter.getBounds(); + const time = timefilter.getBounds() as any; const interval = calculateInterval( time.min.valueOf(), time.max.valueOf(), config.get('timelion:target_buckets') || 200, $scope.interval, - config.get('timelion:min_interval') || '1ms', + config.get('timelion:min_interval') || '1ms' ); const format = getxAxisFormatter(interval); // Use moment to format ticks so we get timezone correction - options.xaxis.tickFormatter = function (val) { + options.xaxis.tickFormatter = function(val: any) { return moment(val).format(format); }; // Calculate how many ticks can fit on the axis const tickLetterWidth = 7; const tickPadding = 45; - options.xaxis.ticks = Math.floor($elem.width() / ((format.length * tickLetterWidth) + tickPadding)); - - const series = _.map(plotConfig, function (series, index) { - series = _.cloneDeep(_.defaults(series, { - shadowSize: 0, - lines: { - lineWidth: 3 - } - })); - series._id = index; + options.xaxis.ticks = Math.floor( + $elem.width() / (format.length * tickLetterWidth + tickPadding) + ); - if (series.color) { + const series = _.map(plotConfig, function(serie: any, index) { + serie = _.cloneDeep( + _.defaults(serie, { + shadowSize: 0, + lines: { + lineWidth: 3, + }, + }) + ); + serie._id = index; + + if (serie.color) { const span = document.createElement('span'); - span.style.color = series.color; - series.color = span.style.color; + span.style.color = serie.color; + serie.color = span.style.color; } - if (series._hide) { - series.data = []; - series.stack = false; - //series.color = "#ddd"; - series.label = '(hidden) ' + series.label; + if (serie._hide) { + serie.data = []; + serie.stack = false; + // serie.color = "#ddd"; + serie.label = '(hidden) ' + serie.label; } - if (series._global) { - _.merge(options, series._global, function (objVal, srcVal) { + if (serie._global) { + _.merge(options, serie._global, function(objVal, srcVal) { // This is kind of gross, it means that you can't replace a global value with a null // best you can do is an empty string. Deal with it. if (objVal == null) return srcVal; @@ -322,13 +348,13 @@ export function timechartFn(dependencies) { }); } - return series; + return serie; }); if (options.yaxes) { - options.yaxes.forEach(yaxis => { + options.yaxes.forEach((yaxis: any) => { if (yaxis && yaxis.units) { - yaxis.tickFormatter = tickFormatters[yaxis.units.type]; + yaxis.tickFormatter = formatters[yaxis.units.type]; const byteModes = ['bytes', 'bytes/s']; if (byteModes.includes(yaxis.units.type)) { yaxis.tickGenerator = generateTicks; @@ -337,6 +363,7 @@ export function timechartFn(dependencies) { }); } + // @ts-ignore $scope.plot = $.plot(canvasElem, _.compact(series), options); if ($scope.plot) { @@ -347,7 +374,7 @@ export function timechartFn(dependencies) { legendScope = $scope.$new(); // Used to toggle the series, and for displaying values on hover legendValueNumbers = canvasElem.find('.ngLegendValueNumber'); - _.each(canvasElem.find('.ngLegendValue'), function (elem) { + _.each(canvasElem.find('.ngLegendValue'), function(elem) { $compile(elem)(legendScope); }); @@ -364,7 +391,7 @@ export function timechartFn(dependencies) { } } $scope.$watch('chart', drawPlot); - } + }, }; }; } diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/tick_generator.js b/src/legacy/core_plugins/timelion/public/panels/timechart/tick_generator.ts similarity index 81% rename from src/legacy/core_plugins/timelion/public/panels/timechart/tick_generator.js rename to src/legacy/core_plugins/timelion/public/panels/timechart/tick_generator.ts index 5a624964274b1..f7d696a0316db 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/tick_generator.js +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/tick_generator.ts @@ -17,13 +17,12 @@ * under the License. */ -export default function generateTicksProvider() { - - function floorInBase(n, base) { +export function generateTicksProvider() { + function floorInBase(n: any, base: any) { return base * Math.floor(n / base); } - function generateTicks(axis) { + function generateTicks(axis: any) { const returnTicks = []; let tickSize = 2; let delta = axis.delta; @@ -31,13 +30,13 @@ export default function generateTicksProvider() { let tickVal; let tickCount = 0; - //Count the steps + // Count the steps while (Math.abs(delta) >= 1024) { steps++; delta /= 1024; } - //Set the tick size relative to the remaining delta + // Set the tick size relative to the remaining delta while (tickSize <= 1024) { if (delta <= tickSize) { break; @@ -46,17 +45,17 @@ export default function generateTicksProvider() { } axis.tickSize = tickSize * Math.pow(1024, steps); - //Calculate the new ticks + // Calculate the new ticks const tickMin = floorInBase(axis.min, axis.tickSize); do { - tickVal = tickMin + (tickCount++) * axis.tickSize; + tickVal = tickMin + tickCount++ * axis.tickSize; returnTicks.push(tickVal); } while (tickVal < axis.max); return returnTicks; } - return function (axis) { + return function(axis: any) { return generateTicks(axis); }; } diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts index 866314d32a955..2e5f43b82089b 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts @@ -17,7 +17,6 @@ * under the License. */ -// @ts-ignore import { timechartFn } from './schema'; import { Panel } from '../panel'; import { LegacyDependenciesPluginStart } from '../../shim'; diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/xaxis_formatter.js b/src/legacy/core_plugins/timelion/public/panels/timechart/xaxis_formatter.ts similarity index 91% rename from src/legacy/core_plugins/timelion/public/panels/timechart/xaxis_formatter.js rename to src/legacy/core_plugins/timelion/public/panels/timechart/xaxis_formatter.ts index 4e49c4eca6538..db3408dae33db 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/xaxis_formatter.js +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/xaxis_formatter.ts @@ -21,13 +21,12 @@ import moment from 'moment'; import { i18n } from '@kbn/i18n'; -export default function xaxisFormatterProvider(config) { - - function getFormat(esInterval) { +export function xaxisFormatterProvider(config: any) { + function getFormat(esInterval: any) { const parts = esInterval.match(/(\d+)(ms|s|m|h|d|w|M|y|)/); if (parts == null || parts[1] == null || parts[2] == null) { - throw new Error ( + throw new Error( i18n.translate('timelion.panels.timechart.unknownIntervalErrorMessage', { defaultMessage: 'Unknown interval', }) @@ -49,7 +48,7 @@ export default function xaxisFormatterProvider(config) { return config.get('dateFormat'); } - return function (esInterval) { + return function(esInterval: any) { return getFormat(esInterval); }; } diff --git a/src/legacy/core_plugins/timelion/public/services/tick_formatters.js b/src/legacy/core_plugins/timelion/public/services/tick_formatters.ts similarity index 70% rename from src/legacy/core_plugins/timelion/public/services/tick_formatters.js rename to src/legacy/core_plugins/timelion/public/services/tick_formatters.ts index 2d0a726ad53d0..2c78d2423cc06 100644 --- a/src/legacy/core_plugins/timelion/public/services/tick_formatters.js +++ b/src/legacy/core_plugins/timelion/public/services/tick_formatters.ts @@ -19,7 +19,7 @@ import _ from 'lodash'; -function baseTickFormatter(value, axis) { +function baseTickFormatter(value: any, axis: any) { const factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1; const formatted = '' + Math.round(value * factor) / factor; @@ -30,15 +30,18 @@ function baseTickFormatter(value, axis) { const decimal = formatted.indexOf('.'); const precision = decimal === -1 ? 0 : formatted.length - decimal - 1; if (precision < axis.tickDecimals) { - return (precision ? formatted : formatted + '.') + ('' + factor).substr(1, axis.tickDecimals - precision); + return ( + (precision ? formatted : formatted + '.') + + ('' + factor).substr(1, axis.tickDecimals - precision) + ); } } return formatted; } -function unitFormatter(divisor, units) { - return (val) => { +function unitFormatter(divisor: any, units: any) { + return (val: any) => { let index = 0; const isNegative = val < 0; val = Math.abs(val); @@ -46,22 +49,26 @@ function unitFormatter(divisor, units) { val /= divisor; index++; } - const value = Math.round(val * 100) / 100 * (isNegative ? -1 : 1); + const value = (Math.round(val * 100) / 100) * (isNegative ? -1 : 1); return `${value}${units[index]}`; }; } -export default function tickFormatters() { - const formatters = { - 'bits': unitFormatter(1000, ['b', 'kb', 'mb', 'gb', 'tb', 'pb']), +export function tickFormatters() { + const formatters = { + bits: unitFormatter(1000, ['b', 'kb', 'mb', 'gb', 'tb', 'pb']), 'bits/s': unitFormatter(1000, ['b/s', 'kb/s', 'mb/s', 'gb/s', 'tb/s', 'pb/s']), - 'bytes': unitFormatter(1024, ['B', 'KB', 'MB', 'GB', 'TB', 'PB']), + bytes: unitFormatter(1024, ['B', 'KB', 'MB', 'GB', 'TB', 'PB']), 'bytes/s': unitFormatter(1024, ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s', 'PB/s']), - 'currency': function (val, axis) { - return val.toLocaleString('en', { style: 'currency', currency: axis.options.units.prefix || 'USD' }); + currency(val: any, axis: any) { + return val.toLocaleString('en', { + style: 'currency', + currency: axis.options.units.prefix || 'USD', + }); }, - 'percent': function (val, axis) { - let precision = _.get(axis, 'tickDecimals', 0) - _.get(axis, 'options.units.tickDecimalsShift', 0); + percent(val: any, axis: any) { + let precision = + _.get(axis, 'tickDecimals', 0) - _.get(axis, 'options.units.tickDecimalsShift', 0); // toFixed only accepts values between 0 and 20 if (precision < 0) { precision = 0; @@ -71,12 +78,12 @@ export default function tickFormatters() { return (val * 100).toFixed(precision) + '%'; }, - 'custom': function (val, axis) { + custom(val: any, axis: any) { const formattedVal = baseTickFormatter(val, axis); const prefix = axis.options.units.prefix; const suffix = axis.options.units.suffix; return prefix + formattedVal + suffix; - } + }, }; return formatters; From 8539357617e8500c2fd71d672e1d9cf540bb87c0 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 6 Sep 2019 15:11:31 +0300 Subject: [PATCH 23/42] Use core.uiSettings --- .../timelion/public/shim/legacy_dependencies_plugin.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index 4ccf6e8a79151..d5864457fea62 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -18,10 +18,10 @@ */ import chrome from 'ui/chrome'; -import 'ui/es'; // required for $injector.get('es') below import { Plugin } from 'kibana/public'; // @ts-ignore import { VisFactoryProvider } from 'ui/vis/vis_factory'; +import { npStart, npSetup } from 'ui/new_platform'; import { initTimelionLegacyModule } from './timelion_legacy_module'; /** @internal */ @@ -42,7 +42,6 @@ export class LegacyDependenciesPlugin implements Plugin, Promise> { public async setup() { - // Init kibana/timelion_vis AngularJS module. initTimelionLegacyModule(); const $injector = await chrome.dangerouslyGetActiveInjector(); @@ -50,7 +49,7 @@ export class LegacyDependenciesPlugin return { $http: $injector.get('$http'), - config: chrome.getUiSettingsClient(), + config: npSetup.core.uiSettings, createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, } as LegacyDependenciesPluginSetup; } @@ -61,7 +60,7 @@ export class LegacyDependenciesPlugin return { $rootScope: $injector.get('$rootScope'), $compile: $injector.get('$compile'), - config: chrome.getUiSettingsClient(), + config: npStart.core.uiSettings, } as LegacyDependenciesPluginStart; } } From 81fde15ef5e2235d58e204e4c634bf61fc566134 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 6 Sep 2019 15:23:26 +0300 Subject: [PATCH 24/42] Refactor timelion request handler --- .../timelion/public/timelion_vis_fn.ts | 7 +- .../core_plugins/timelion/public/vis/index.ts | 4 +- .../public/vis/timelion_request_handler.ts | 97 +++++++++---------- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index b52de09ab0bba..a9428b92d3f39 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -24,10 +24,7 @@ import { KibanaContext, Render, } from 'src/plugins/data/common/expressions/types'; -import { - getTimelionRequestProvider, - TimelionSuccessResponse, -} from './vis/timelion_request_handler'; +import { getTimelionRequestHandler, TimelionSuccessResponse } from './vis/timelion_request_handler'; import { LegacyDependenciesPluginSetup } from './shim'; const name = 'timelion_vis'; @@ -72,7 +69,7 @@ export const getTimelionVisualizationConfig = ( }, }, async fn(context, args) { - const timelionRequestHandler = getTimelionRequestProvider(dependencies).handler; + const timelionRequestHandler = getTimelionRequestHandler(dependencies); const visParams = { expression: args.expression, interval: args.interval }; diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index d8ff5ec799e31..c457edb5fe4a9 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -21,13 +21,13 @@ import { i18n } from '@kbn/i18n'; // @ts-ignore import { DefaultEditorSize } from 'ui/vis/editor_size'; -import { getTimelionRequestProvider } from './timelion_request_handler'; +import { getTimelionRequestHandler } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; import { LegacyDependenciesPluginSetup } from '../shim'; export function getTimelionVisualization(dependencies: LegacyDependenciesPluginSetup) { - const timelionRequestHandler = getTimelionRequestProvider(dependencies).handler; + const timelionRequestHandler = getTimelionRequestHandler(dependencies); // return the visType object, which kibana will use to display and configure new // Vis object of this type. diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index d288cef85cec4..eda83e4586db6 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -51,61 +51,58 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } -export function getTimelionRequestProvider(dependencies: LegacyDependenciesPluginSetup) { +export function getTimelionRequestHandler(dependencies: LegacyDependenciesPluginSetup) { const { config, $http } = dependencies; const timezone = timezoneProvider(config)(); - return { - name: 'timelion', - handler({ - timeRange, - filters, - query, - visParams, - }: { - timeRange: TimeRange; - filters: Filter[]; - query: Query; - visParams: VisParams; - forceFetch?: boolean; - }) { - return new Promise((resolve, reject) => { - const expression = visParams.expression; - if (!expression) return; - const esQueryConfigs = getEsQueryConfig(config); - const httpResult = $http - .post('../api/timelion/run', { - sheet: [expression], - extended: { - es: { - filter: buildEsQuery(undefined, query, filters, esQueryConfigs), - }, + return ({ + timeRange, + filters, + query, + visParams, + }: { + timeRange: TimeRange; + filters: Filter[]; + query: Query; + visParams: VisParams; + forceFetch?: boolean; + }) => { + return new Promise((resolve, reject) => { + const expression = visParams.expression; + if (!expression) return; + const esQueryConfigs = getEsQueryConfig(config); + const httpResult = $http + .post('../api/timelion/run', { + sheet: [expression], + extended: { + es: { + filter: buildEsQuery(undefined, query, filters, esQueryConfigs), }, - time: _.extend(timeRange, { - interval: visParams.interval, - timezone, - }), - }) - .then((resp: any) => resp.data) - .catch((resp: any) => { - throw resp.data; - }); + }, + time: _.extend(timeRange, { + interval: visParams.interval, + timezone, + }), + }) + .then((resp: any) => resp.data) + .catch((resp: any) => { + throw resp.data; + }); - httpResult - .then(function(resp: TimelionSuccessResponse) { - resolve(resp); - }) - .catch(function(resp: any) { - const err = new Error(resp.message); - err.stack = resp.stack; - toastNotifications.addError(err, { - title: i18n.translate('timelion.requestHandlerErrorTitle', { - defaultMessage: 'Timelion request error', - }), - }); - reject(err); + httpResult + .then(function(resp: TimelionSuccessResponse) { + resolve(resp); + }) + .catch(function(resp: any) { + const err = new Error(resp.message); + err.stack = resp.stack; + toastNotifications.addError(err, { + title: i18n.translate('timelion.requestHandlerErrorTitle', { + defaultMessage: 'Timelion request error', + }), }); - }); - }, + reject(err); + }); + }); }; } From c505be308889856bf58328c9e2af5029b0a5b42a Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 9 Sep 2019 13:22:24 +0300 Subject: [PATCH 25/42] Remove Private from tests --- .../public/__tests__/_tick_generator.js | 6 +++-- .../__tests__/services/tick_formatters.js | 22 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js b/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js index 508cc5cd856d2..bcf221e73be7f 100644 --- a/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js +++ b/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js @@ -19,6 +19,8 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; +import { generateTicksProvider } from '../panels/timechart/tick_generator'; + describe('Tick Generator', function () { let generateTicks; @@ -40,8 +42,8 @@ describe('Tick Generator', function () { } ]; beforeEach(ngMock.module('kibana')); - beforeEach(ngMock.inject(function (Private) { - generateTicks = Private(require('plugins/timelion/panels/timechart/tick_generator')); + beforeEach(ngMock.inject(function () { + generateTicks = generateTicksProvider(); })); it('returns a function', function () { diff --git a/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js b/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js index 8e140b9bf992a..9da989177cb7e 100644 --- a/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js +++ b/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js @@ -19,19 +19,21 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; +import { tickFormatters } from '../../services/tick_formatters'; + describe('Tick Formatters', function () { - let tickFormatters; + let formatters; beforeEach(ngMock.module('kibana')); - beforeEach(ngMock.inject(function (Private) { - tickFormatters = Private(require('plugins/timelion/services/tick_formatters')); + beforeEach(ngMock.inject(function () { + formatters = tickFormatters(); })); describe('Bits mode', function () { let bitFormatter; beforeEach(function () { - bitFormatter = tickFormatters.bits; + bitFormatter = formatters.bits; }); it('is a function', function () { @@ -56,7 +58,7 @@ describe('Tick Formatters', function () { describe('Bits/s mode', function () { let bitsFormatter; beforeEach(function () { - bitsFormatter = tickFormatters['bits/s']; + bitsFormatter = formatters['bits/s']; }); it('is a function', function () { @@ -81,7 +83,7 @@ describe('Tick Formatters', function () { describe('Bytes mode', function () { let byteFormatter; beforeEach(function () { - byteFormatter = tickFormatters.bytes; + byteFormatter = formatters.bytes; }); it('is a function', function () { @@ -106,7 +108,7 @@ describe('Tick Formatters', function () { describe('Bytes/s mode', function () { let bytesFormatter; beforeEach(function () { - bytesFormatter = tickFormatters['bytes/s']; + bytesFormatter = formatters['bytes/s']; }); it('is a function', function () { @@ -131,7 +133,7 @@ describe('Tick Formatters', function () { describe('Currency mode', function () { let currencyFormatter; beforeEach(function () { - currencyFormatter = tickFormatters.currency; + currencyFormatter = formatters.currency; }); it('is a function', function () { @@ -163,7 +165,7 @@ describe('Tick Formatters', function () { describe('Percent mode', function () { let percentFormatter; beforeEach(function () { - percentFormatter = tickFormatters.percent; + percentFormatter = formatters.percent; }); it('is a function', function () { @@ -197,7 +199,7 @@ describe('Tick Formatters', function () { describe('Custom mode', function () { let customFormatter; beforeEach(function () { - customFormatter = tickFormatters.custom; + customFormatter = formatters.custom; }); it('is a function', function () { From 78680f1c082092c863b1992e52fe8e3fc4460026 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Mon, 9 Sep 2019 14:03:36 +0300 Subject: [PATCH 26/42] Remove redundant dependencies from tests --- .../public/__tests__/_tick_generator.js | 75 ++++++++++--------- .../__tests__/services/tick_formatters.js | 7 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js b/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js index bcf221e73be7f..66ac56acc6262 100644 --- a/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js +++ b/src/legacy/core_plugins/timelion/public/__tests__/_tick_generator.js @@ -18,50 +18,53 @@ */ import expect from '@kbn/expect'; -import ngMock from 'ng_mock'; import { generateTicksProvider } from '../panels/timechart/tick_generator'; describe('Tick Generator', function () { - let generateTicks; - const axes = [ - { - min: 0, - max: 5000, - delta: 100 - }, - { - min: 0, - max: 50000, - delta: 2000 - }, - { - min: 4096, - max: 6000, - delta: 250 - } - ]; - beforeEach(ngMock.module('kibana')); - beforeEach(ngMock.inject(function () { + + beforeEach(function () { generateTicks = generateTicksProvider(); - })); + }); - it('returns a function', function () { - expect(generateTicks).to.be.a('function'); + describe('generateTicksProvider()', function () { + it('should return a function', function () { + expect(generateTicks).to.be.a('function'); + }); }); - axes.forEach(axis => { - it(`generates ticks from ${axis.min} to ${axis.max}`, function () { - const ticks = generateTicks(axis); - let n = 1; - while (Math.pow(2, n) < axis.delta) n++; - const expectedDelta = Math.pow(2, n); - const expectedNr = parseInt((axis.max - axis.min) / expectedDelta) + 2; - expect(ticks instanceof Array).to.be(true); - expect(ticks.length).to.be(expectedNr); - expect(ticks[0]).to.equal(axis.min); - expect(ticks[parseInt(ticks.length / 2)]).to.equal(axis.min + expectedDelta * parseInt(ticks.length / 2)); - expect(ticks[ticks.length - 1]).to.equal(axis.min + expectedDelta * (ticks.length - 1)); + describe('generateTicks()', function () { + const axes = [ + { + min: 0, + max: 5000, + delta: 100 + }, + { + min: 0, + max: 50000, + delta: 2000 + }, + { + min: 4096, + max: 6000, + delta: 250 + } + ]; + + axes.forEach(axis => { + it(`generates ticks from ${axis.min} to ${axis.max}`, function () { + const ticks = generateTicks(axis); + let n = 1; + while (Math.pow(2, n) < axis.delta) n++; + const expectedDelta = Math.pow(2, n); + const expectedNr = parseInt((axis.max - axis.min) / expectedDelta) + 2; + expect(ticks instanceof Array).to.be(true); + expect(ticks.length).to.be(expectedNr); + expect(ticks[0]).to.equal(axis.min); + expect(ticks[parseInt(ticks.length / 2)]).to.equal(axis.min + expectedDelta * parseInt(ticks.length / 2)); + expect(ticks[ticks.length - 1]).to.equal(axis.min + expectedDelta * (ticks.length - 1)); + }); }); }); }); diff --git a/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js b/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js index 9da989177cb7e..cce72773f6b62 100644 --- a/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js +++ b/src/legacy/core_plugins/timelion/public/__tests__/services/tick_formatters.js @@ -18,17 +18,14 @@ */ import expect from '@kbn/expect'; -import ngMock from 'ng_mock'; import { tickFormatters } from '../../services/tick_formatters'; describe('Tick Formatters', function () { - let formatters; - beforeEach(ngMock.module('kibana')); - beforeEach(ngMock.inject(function () { + beforeEach(function () { formatters = tickFormatters(); - })); + }); describe('Bits mode', function () { let bitFormatter; From b51082bc3946aa0e014a97308f6641f39cf4b766 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Wed, 11 Sep 2019 12:33:30 +0300 Subject: [PATCH 27/42] Update visualizations paths --- src/legacy/core_plugins/timelion/public/legacy.ts | 2 +- src/legacy/core_plugins/timelion/public/plugin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index ce14194d4c2ce..8c4e95f4d3de1 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -20,7 +20,7 @@ import { PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; import { plugin } from '.'; -import { setup as visualizations } from '../../visualizations/public/np_ready/public/legacy'; +import { setup as visualizations } from '../../visualizations/public/legacy'; import { TimelionPluginSetupDependencies, TimelionPluginStartDependencies } from './plugin'; // @ts-ignore import panelRegistry from './lib/panel_registry'; diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 147a777f11955..a0c6479706f20 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -24,7 +24,7 @@ import { PluginInitializerContext, } from 'kibana/public'; import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; -import { VisualizationsSetup } from '../../visualizations/public/np_ready/public'; +import { VisualizationsSetup } from '../../visualizations/public/np_ready'; import { getTimelionVisualizationConfig } from './timelion_vis_fn'; import { getTimelionVisualization } from './vis'; import { getTimeChart } from './panels/timechart/timechart'; From bb3b87d562c19fddc5fe502a2e743840cfa0276f Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 13 Sep 2019 13:20:35 +0300 Subject: [PATCH 28/42] Change expressions paths due to expessions movement --- src/legacy/core_plugins/timelion/public/legacy.ts | 2 +- src/legacy/core_plugins/timelion/public/plugin.ts | 7 +++---- src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts | 6 +----- .../timelion/public/vis/timelion_request_handler.ts | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/legacy.ts b/src/legacy/core_plugins/timelion/public/legacy.ts index 8c4e95f4d3de1..8b8b5d4330b42 100644 --- a/src/legacy/core_plugins/timelion/public/legacy.ts +++ b/src/legacy/core_plugins/timelion/public/legacy.ts @@ -32,7 +32,7 @@ const __LEGACY = new LegacyDependenciesPlugin(); const setupPlugins: Readonly = { visualizations, - data: npSetup.plugins.data, + expressions: npSetup.plugins.expressions, __LEGACY, }; diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index a0c6479706f20..927cb71f23d8f 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -23,7 +23,7 @@ import { Plugin, PluginInitializerContext, } from 'kibana/public'; -import { Plugin as DataPublicPlugin } from 'src/plugins/data/public'; +import { Plugin as ExpressionsPlugin } from 'src/plugins/expressions/public'; import { VisualizationsSetup } from '../../visualizations/public/np_ready'; import { getTimelionVisualizationConfig } from './timelion_vis_fn'; import { getTimelionVisualization } from './vis'; @@ -36,7 +36,7 @@ import { /** @internal */ export interface TimelionPluginSetupDependencies { - data: ReturnType; + expressions: ReturnType; visualizations: VisualizationsSetup; // Temporary solution @@ -63,8 +63,7 @@ export class TimelionPlugin public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { const dependencies: LegacyDependenciesPluginSetup = await plugins.__LEGACY.setup(); - - plugins.data.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); + plugins.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); plugins.visualizations.types.registerVisualization(() => getTimelionVisualization(dependencies) ); diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index a9428b92d3f39..6d55f8bf1d76b 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -19,11 +19,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { - ExpressionFunction, - KibanaContext, - Render, -} from 'src/plugins/data/common/expressions/types'; +import { ExpressionFunction, KibanaContext, Render } from 'src/plugins/expressions/public'; import { getTimelionRequestHandler, TimelionSuccessResponse } from './vis/timelion_request_handler'; import { LegacyDependenciesPluginSetup } from './shim'; diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index eda83e4586db6..efb03518cb878 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -22,7 +22,7 @@ import _ from 'lodash'; import { buildEsQuery, getEsQueryConfig, Filter } from '@kbn/es-query'; // @ts-ignore import { timezoneProvider } from 'ui/vis/lib/timezone'; -import { KIBANA_CONTEXT_NAME } from 'src/plugins/data/common/expressions/types'; +import { KIBANA_CONTEXT_NAME } from 'src/plugins/expressions/public'; import { Query } from 'src/legacy/core_plugins/data/public'; import { TimeRange } from 'src/plugins/data/public'; import { VisParams } from 'ui/vis'; From fff56041cbdf2b75b20b953b6b98baa645287254 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 17 Sep 2019 16:43:11 +0300 Subject: [PATCH 29/42] Refactoring according to reviews --- .../public/panels/timechart/schema.ts | 4 +- .../public/panels/timechart/timechart.ts | 4 +- .../core_plugins/timelion/public/plugin.ts | 6 +++ .../timelion/public/timelion_vis_fn.ts | 4 +- .../core_plugins/timelion/public/vis/index.ts | 5 +- .../public/vis/timelion_request_handler.ts | 49 +++++++++---------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts index 042addb9aa139..a8c956bad8b82 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts @@ -26,14 +26,14 @@ import { timefilter } from 'ui/timefilter'; import observeResize from '../../lib/observe_resize'; // @ts-ignore import { calculateInterval, DEFAULT_TIME_FORMAT } from '../../../common/lib'; -import { LegacyDependenciesPluginStart } from '../../shim'; +import { TimelionStartDependencies } from '../../plugin'; import { tickFormatters } from '../../services/tick_formatters'; import { xaxisFormatterProvider } from './xaxis_formatter'; import { generateTicksProvider } from './tick_generator'; const DEBOUNCE_DELAY = 50; -export function timechartFn(dependencies: LegacyDependenciesPluginStart) { +export function timechartFn(dependencies: TimelionStartDependencies) { const { config, $rootScope, $compile } = dependencies; return function() { return { diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts index 2e5f43b82089b..63eabd6cb0edf 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/timechart.ts @@ -19,9 +19,9 @@ import { timechartFn } from './schema'; import { Panel } from '../panel'; -import { LegacyDependenciesPluginStart } from '../../shim'; +import { TimelionStartDependencies } from '../../plugin'; -export function getTimeChart(dependencies: LegacyDependenciesPluginStart) { +export function getTimeChart(dependencies: TimelionStartDependencies) { // Schema is broken out so that it may be extended for use in other plugins // Its also easier to test. return new Panel('timechart', timechartFn(dependencies)()); diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 927cb71f23d8f..a761049d1a32d 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -34,6 +34,12 @@ import { LegacyDependenciesPluginStart, } from './shim'; +/** @internal */ +export { LegacyDependenciesPluginStart as TimelionStartDependencies }; + +/** @internal */ +export { LegacyDependenciesPluginSetup as TimelionSetupDependencies }; + /** @internal */ export interface TimelionPluginSetupDependencies { expressions: ReturnType; diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index 6d55f8bf1d76b..d92f118ca70af 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -21,7 +21,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { ExpressionFunction, KibanaContext, Render } from 'src/plugins/expressions/public'; import { getTimelionRequestHandler, TimelionSuccessResponse } from './vis/timelion_request_handler'; -import { LegacyDependenciesPluginSetup } from './shim'; +import { TimelionSetupDependencies } from './plugin'; const name = 'timelion_vis'; @@ -41,7 +41,7 @@ type VisParams = Arguments; type Return = Promise>; export const getTimelionVisualizationConfig = ( - dependencies: LegacyDependenciesPluginSetup + dependencies: TimelionSetupDependencies ): ExpressionFunction => ({ name, type: 'render', diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index c457edb5fe4a9..00b1b6fbaaf0d 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -17,16 +17,15 @@ * under the License. */ -// @ts-ignore import { i18n } from '@kbn/i18n'; // @ts-ignore import { DefaultEditorSize } from 'ui/vis/editor_size'; import { getTimelionRequestHandler } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; -import { LegacyDependenciesPluginSetup } from '../shim'; +import { TimelionSetupDependencies } from '../plugin'; -export function getTimelionVisualization(dependencies: LegacyDependenciesPluginSetup) { +export function getTimelionVisualization(dependencies: TimelionSetupDependencies) { const timelionRequestHandler = getTimelionRequestHandler(dependencies); // return the visType object, which kibana will use to display and configure new diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index efb03518cb878..4d473d094fb03 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -17,7 +17,6 @@ * under the License. */ -import _ from 'lodash'; // @ts-ignore import { buildEsQuery, getEsQueryConfig, Filter } from '@kbn/es-query'; // @ts-ignore @@ -28,7 +27,7 @@ import { TimeRange } from 'src/plugins/data/public'; import { VisParams } from 'ui/vis'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; -import { LegacyDependenciesPluginSetup } from '../shim'; +import { TimelionSetupDependencies } from '../plugin'; interface Stats { cacheCount: number; @@ -51,7 +50,7 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } -export function getTimelionRequestHandler(dependencies: LegacyDependenciesPluginSetup) { +export function getTimelionRequestHandler(dependencies: TimelionSetupDependencies) { const { config, $http } = dependencies; const timezone = timezoneProvider(config)(); @@ -67,42 +66,38 @@ export function getTimelionRequestHandler(dependencies: LegacyDependenciesPlugin visParams: VisParams; forceFetch?: boolean; }) => { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { const expression = visParams.expression; + if (!expression) return; + const esQueryConfigs = getEsQueryConfig(config); - const httpResult = $http - .post('../api/timelion/run', { + + try { + const response = await $http.post('../api/timelion/run', { sheet: [expression], extended: { es: { filter: buildEsQuery(undefined, query, filters, esQueryConfigs), }, }, - time: _.extend(timeRange, { - interval: visParams.interval, - timezone, - }), - }) - .then((resp: any) => resp.data) - .catch((resp: any) => { - throw resp.data; + time: { ...timeRange, interval: visParams.interval, timezone }, }); - httpResult - .then(function(resp: TimelionSuccessResponse) { - resolve(resp); - }) - .catch(function(resp: any) { - const err = new Error(resp.message); - err.stack = resp.stack; - toastNotifications.addError(err, { - title: i18n.translate('timelion.requestHandlerErrorTitle', { - defaultMessage: 'Timelion request error', - }), - }); - reject(err); + resolve(response.data); + } catch (e) { + const err = new Error(e.data.message); + + err.stack = e.data.stack; + + toastNotifications.addError(err, { + title: i18n.translate('timelion.requestHandlerErrorTitle', { + defaultMessage: 'Timelion request error', + }), }); + + reject(err); + } }); }; } From 6ff49f68eaf435d8e70eeb547834aac8f2dd1b9c Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Thu, 19 Sep 2019 13:36:54 +0300 Subject: [PATCH 30/42] Add a comment over the uiCapabilities field --- src/legacy/plugin_discovery/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/legacy/plugin_discovery/types.ts b/src/legacy/plugin_discovery/types.ts index 5db76cd73477f..17a81a783a954 100644 --- a/src/legacy/plugin_discovery/types.ts +++ b/src/legacy/plugin_discovery/types.ts @@ -76,6 +76,7 @@ export interface LegacyPluginOptions { interpreter?: string[]; uiSettingDefaults?: Record; }>; + // TODO: Revise the field when Timelion plugin is moved from legacy to plugins. uiCapabilities?: Capabilities | (() => Partial); publicDir: any; configPrefix: any; From 8300bf9e71118a3b32b611feecfec4288f5ceccc Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Thu, 19 Sep 2019 13:47:08 +0300 Subject: [PATCH 31/42] Edit the comment --- src/legacy/plugin_discovery/types.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/legacy/plugin_discovery/types.ts b/src/legacy/plugin_discovery/types.ts index 17a81a783a954..f382afc38f25f 100644 --- a/src/legacy/plugin_discovery/types.ts +++ b/src/legacy/plugin_discovery/types.ts @@ -76,7 +76,10 @@ export interface LegacyPluginOptions { interpreter?: string[]; uiSettingDefaults?: Record; }>; - // TODO: Revise the field when Timelion plugin is moved from legacy to plugins. + /** + * TODO: Revise the field when Timelion plugin is moved from legacy to plugins. + * https://github.com/elastic/kibana/pull/44039#discussion_r326105564 + */ uiCapabilities?: Capabilities | (() => Partial); publicDir: any; configPrefix: any; From a8821c298b64f270e10b835655470f06db487175 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Fri, 20 Sep 2019 14:15:54 +0300 Subject: [PATCH 32/42] Ignore uiCapabilities issue --- src/legacy/core_plugins/timelion/index.ts | 2 ++ src/legacy/plugin_discovery/types.ts | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/timelion/index.ts b/src/legacy/core_plugins/timelion/index.ts index c111e25d78f15..77e62ed02718c 100644 --- a/src/legacy/core_plugins/timelion/index.ts +++ b/src/legacy/core_plugins/timelion/index.ts @@ -43,6 +43,8 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl .default([]), }).default(); }, + // @ts-ignore + // https://github.com/elastic/kibana/pull/44039#discussion_r326582255 uiCapabilities() { return { timelion: { diff --git a/src/legacy/plugin_discovery/types.ts b/src/legacy/plugin_discovery/types.ts index f382afc38f25f..a789434a4caae 100644 --- a/src/legacy/plugin_discovery/types.ts +++ b/src/legacy/plugin_discovery/types.ts @@ -76,11 +76,7 @@ export interface LegacyPluginOptions { interpreter?: string[]; uiSettingDefaults?: Record; }>; - /** - * TODO: Revise the field when Timelion plugin is moved from legacy to plugins. - * https://github.com/elastic/kibana/pull/44039#discussion_r326105564 - */ - uiCapabilities?: Capabilities | (() => Partial); + uiCapabilities?: Capabilities; publicDir: any; configPrefix: any; config: any; From 3d1271429e7378e6f551889756ad8b975a35705c Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 23 Sep 2019 16:22:13 +0300 Subject: [PATCH 33/42] Take angular controller out --- .../timelion/public/shim/legacy_dependencies_plugin.ts | 7 +++---- src/legacy/core_plugins/timelion/public/vis/index.ts | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index d5864457fea62..9ce4c08e7a265 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -20,7 +20,7 @@ import chrome from 'ui/chrome'; import { Plugin } from 'kibana/public'; // @ts-ignore -import { VisFactoryProvider } from 'ui/vis/vis_factory'; +import { visFactory } from 'ui/vis/vis_factory'; import { npStart, npSetup } from 'ui/new_platform'; import { initTimelionLegacyModule } from './timelion_legacy_module'; @@ -28,7 +28,7 @@ import { initTimelionLegacyModule } from './timelion_legacy_module'; export interface LegacyDependenciesPluginSetup { $http: any; config: any; - createAngularVisualization: Function; + createBaseVisualization: Function; } /** @internal */ @@ -45,12 +45,11 @@ export class LegacyDependenciesPlugin initTimelionLegacyModule(); const $injector = await chrome.dangerouslyGetActiveInjector(); - const Private = $injector.get('Private'); return { $http: $injector.get('$http'), config: npSetup.core.uiSettings, - createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, + createBaseVisualization: visFactory.createBaseVisualization, } as LegacyDependenciesPluginSetup; } diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index 00b1b6fbaaf0d..bcea78343333b 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -24,19 +24,22 @@ import { getTimelionRequestHandler } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; import { TimelionSetupDependencies } from '../plugin'; +// @ts-ignore +import { AngularVisController } from '../../../../ui/public/vis/vis_types/angular_vis_type'; export function getTimelionVisualization(dependencies: TimelionSetupDependencies) { const timelionRequestHandler = getTimelionRequestHandler(dependencies); // return the visType object, which kibana will use to display and configure new // Vis object of this type. - return dependencies.createAngularVisualization({ + return dependencies.createBaseVisualization({ name: 'timelion', title: 'Timelion', icon: 'visTimelion', description: i18n.translate('timelion.timelionDescription', { defaultMessage: 'Build time-series using functional expressions', }), + visualization: AngularVisController, visConfig: { defaults: { expression: '.es(*)', From c90c7a08eb12c743727bd7c5235d087d09d98cc6 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 23 Sep 2019 17:56:11 +0300 Subject: [PATCH 34/42] Get rid of --- .../public/shim/legacy_dependencies_plugin.ts | 4 ---- .../public/vis/timelion_request_handler.ts | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index 9ce4c08e7a265..3c9a0fefb8546 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -26,7 +26,6 @@ import { initTimelionLegacyModule } from './timelion_legacy_module'; /** @internal */ export interface LegacyDependenciesPluginSetup { - $http: any; config: any; createBaseVisualization: Function; } @@ -44,10 +43,7 @@ export class LegacyDependenciesPlugin public async setup() { initTimelionLegacyModule(); - const $injector = await chrome.dangerouslyGetActiveInjector(); - return { - $http: $injector.get('$http'), config: npSetup.core.uiSettings, createBaseVisualization: visFactory.createBaseVisualization, } as LegacyDependenciesPluginSetup; diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index 4d473d094fb03..a217e2c5b0cd0 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -21,6 +21,7 @@ import { buildEsQuery, getEsQueryConfig, Filter } from '@kbn/es-query'; // @ts-ignore import { timezoneProvider } from 'ui/vis/lib/timezone'; +import { npSetup } from 'ui/new_platform'; import { KIBANA_CONTEXT_NAME } from 'src/plugins/expressions/public'; import { Query } from 'src/legacy/core_plugins/data/public'; import { TimeRange } from 'src/plugins/data/public'; @@ -50,8 +51,10 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } +const { http } = npSetup.core; + export function getTimelionRequestHandler(dependencies: TimelionSetupDependencies) { - const { config, $http } = dependencies; + const { config } = dependencies; const timezone = timezoneProvider(config)(); return ({ @@ -74,17 +77,19 @@ export function getTimelionRequestHandler(dependencies: TimelionSetupDependencie const esQueryConfigs = getEsQueryConfig(config); try { - const response = await $http.post('../api/timelion/run', { - sheet: [expression], - extended: { - es: { - filter: buildEsQuery(undefined, query, filters, esQueryConfigs), + const data = await http.post('../api/timelion/run', { + body: JSON.stringify({ + sheet: [expression], + extended: { + es: { + filter: buildEsQuery(undefined, query, filters, esQueryConfigs), + }, }, - }, - time: { ...timeRange, interval: visParams.interval, timezone }, + time: { ...timeRange, interval: visParams.interval, timezone }, + }), }); - resolve(response.data); + resolve(data); } catch (e) { const err = new Error(e.data.message); From 7a8ff51d7bd6a80356f1f4e890be514bdea456ad Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 23 Sep 2019 18:04:14 +0300 Subject: [PATCH 35/42] Get rid of config --- src/legacy/core_plugins/timelion/public/plugin.ts | 2 +- .../public/shim/legacy_dependencies_plugin.ts | 4 +--- .../core_plugins/timelion/public/timelion_vis_fn.ts | 12 +++++++----- src/legacy/core_plugins/timelion/public/vis/index.ts | 2 +- .../timelion/public/vis/timelion_request_handler.ts | 10 ++++------ 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index a761049d1a32d..97061e2a4a7d0 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -69,7 +69,7 @@ export class TimelionPlugin public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { const dependencies: LegacyDependenciesPluginSetup = await plugins.__LEGACY.setup(); - plugins.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); + plugins.expressions.registerFunction(() => getTimelionVisualizationConfig()); plugins.visualizations.types.registerVisualization(() => getTimelionVisualization(dependencies) ); diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index 3c9a0fefb8546..9e857678b1470 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -21,12 +21,11 @@ import chrome from 'ui/chrome'; import { Plugin } from 'kibana/public'; // @ts-ignore import { visFactory } from 'ui/vis/vis_factory'; -import { npStart, npSetup } from 'ui/new_platform'; +import { npStart } from 'ui/new_platform'; import { initTimelionLegacyModule } from './timelion_legacy_module'; /** @internal */ export interface LegacyDependenciesPluginSetup { - config: any; createBaseVisualization: Function; } @@ -44,7 +43,6 @@ export class LegacyDependenciesPlugin initTimelionLegacyModule(); return { - config: npSetup.core.uiSettings, createBaseVisualization: visFactory.createBaseVisualization, } as LegacyDependenciesPluginSetup; } diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index d92f118ca70af..30958b0ed8b9a 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -21,7 +21,6 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { ExpressionFunction, KibanaContext, Render } from 'src/plugins/expressions/public'; import { getTimelionRequestHandler, TimelionSuccessResponse } from './vis/timelion_request_handler'; -import { TimelionSetupDependencies } from './plugin'; const name = 'timelion_vis'; @@ -40,9 +39,12 @@ type Context = KibanaContext | null; type VisParams = Arguments; type Return = Promise>; -export const getTimelionVisualizationConfig = ( - dependencies: TimelionSetupDependencies -): ExpressionFunction => ({ +export const getTimelionVisualizationConfig = (): ExpressionFunction< + typeof name, + Context, + Arguments, + Return +> => ({ name, type: 'render', context: { @@ -65,7 +67,7 @@ export const getTimelionVisualizationConfig = ( }, }, async fn(context, args) { - const timelionRequestHandler = getTimelionRequestHandler(dependencies); + const timelionRequestHandler = getTimelionRequestHandler(); const visParams = { expression: args.expression, interval: args.interval }; diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index bcea78343333b..54001b879da57 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -28,7 +28,7 @@ import { TimelionSetupDependencies } from '../plugin'; import { AngularVisController } from '../../../../ui/public/vis/vis_types/angular_vis_type'; export function getTimelionVisualization(dependencies: TimelionSetupDependencies) { - const timelionRequestHandler = getTimelionRequestHandler(dependencies); + const timelionRequestHandler = getTimelionRequestHandler(); // return the visType object, which kibana will use to display and configure new // Vis object of this type. diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index a217e2c5b0cd0..025983ea7fc28 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -28,7 +28,6 @@ import { TimeRange } from 'src/plugins/data/public'; import { VisParams } from 'ui/vis'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; -import { TimelionSetupDependencies } from '../plugin'; interface Stats { cacheCount: number; @@ -51,11 +50,10 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } -const { http } = npSetup.core; +const { http, uiSettings } = npSetup.core; -export function getTimelionRequestHandler(dependencies: TimelionSetupDependencies) { - const { config } = dependencies; - const timezone = timezoneProvider(config)(); +export function getTimelionRequestHandler() { + const timezone = timezoneProvider(uiSettings)(); return ({ timeRange, @@ -74,7 +72,7 @@ export function getTimelionRequestHandler(dependencies: TimelionSetupDependencie if (!expression) return; - const esQueryConfigs = getEsQueryConfig(config); + const esQueryConfigs = getEsQueryConfig(uiSettings); try { const data = await http.post('../api/timelion/run', { From 9653ddb5979e3afc57028b6e18bc44a26d943e9d Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 23 Sep 2019 18:08:30 +0300 Subject: [PATCH 36/42] Get rid of config in start --- .../timelion/public/panels/timechart/schema.ts | 12 +++++++----- .../public/shim/legacy_dependencies_plugin.ts | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts index a8c956bad8b82..5c28c443670ef 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts @@ -22,6 +22,7 @@ import _ from 'lodash'; import $ from 'jquery'; import moment from 'moment-timezone'; import { timefilter } from 'ui/timefilter'; +import { npSetup } from 'ui/new_platform'; // @ts-ignore import observeResize from '../../lib/observe_resize'; // @ts-ignore @@ -32,21 +33,22 @@ import { xaxisFormatterProvider } from './xaxis_formatter'; import { generateTicksProvider } from './tick_generator'; const DEBOUNCE_DELAY = 50; +const { uiSettings } = npSetup.core; export function timechartFn(dependencies: TimelionStartDependencies) { - const { config, $rootScope, $compile } = dependencies; + const { $rootScope, $compile } = dependencies; return function() { return { help: 'Draw a timeseries chart', render($scope: any, $elem: any) { const template = '
'; const formatters = tickFormatters() as any; - const getxAxisFormatter = xaxisFormatterProvider(config); + const getxAxisFormatter = xaxisFormatterProvider(uiSettings); const generateTicks = generateTicksProvider(); // TODO: I wonder if we should supply our own moment that sets this every time? // could just use angular's injection to provide a moment service? - moment.tz.setDefault(config.get('dateFormat:tz')); + moment.tz.setDefault(uiSettings.get('dateFormat:tz')); const render = $scope.seriesList.render || {}; @@ -297,9 +299,9 @@ export function timechartFn(dependencies: TimelionStartDependencies) { const interval = calculateInterval( time.min.valueOf(), time.max.valueOf(), - config.get('timelion:target_buckets') || 200, + uiSettings.get('timelion:target_buckets') || 200, $scope.interval, - config.get('timelion:min_interval') || '1ms' + uiSettings.get('timelion:min_interval') || '1ms' ); const format = getxAxisFormatter(interval); diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index 9e857678b1470..b9904aee519f0 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -33,7 +33,6 @@ export interface LegacyDependenciesPluginSetup { export interface LegacyDependenciesPluginStart { $rootScope: any; $compile: any; - config: any; } export class LegacyDependenciesPlugin From 7b4b10444f270ef12d0ef771b6df6c639970a025 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 24 Sep 2019 14:25:49 +0300 Subject: [PATCH 37/42] Unwrap handler from redundant promise --- .../public/vis/timelion_request_handler.ts | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index 025983ea7fc28..47457fd55a59c 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -55,7 +55,7 @@ const { http, uiSettings } = npSetup.core; export function getTimelionRequestHandler() { const timezone = timezoneProvider(uiSettings)(); - return ({ + return async function({ timeRange, filters, query, @@ -66,41 +66,35 @@ export function getTimelionRequestHandler() { query: Query; visParams: VisParams; forceFetch?: boolean; - }) => { - return new Promise(async (resolve, reject) => { - const expression = visParams.expression; + }): Promise { + const expression = visParams.expression; - if (!expression) return; + if (!expression) return; - const esQueryConfigs = getEsQueryConfig(uiSettings); + const esQueryConfigs = getEsQueryConfig(uiSettings); - try { - const data = await http.post('../api/timelion/run', { - body: JSON.stringify({ - sheet: [expression], - extended: { - es: { - filter: buildEsQuery(undefined, query, filters, esQueryConfigs), - }, + try { + return await http.post('../api/timelion/run', { + body: JSON.stringify({ + sheet: [expression], + extended: { + es: { + filter: buildEsQuery(undefined, query, filters, esQueryConfigs), }, - time: { ...timeRange, interval: visParams.interval, timezone }, - }), - }); + }, + time: { ...timeRange, interval: visParams.interval, timezone }, + }), + }); + } catch (e) { + const err = new Error(e.data.message); - resolve(data); - } catch (e) { - const err = new Error(e.data.message); + err.stack = e.data.stack; - err.stack = e.data.stack; - - toastNotifications.addError(err, { - title: i18n.translate('timelion.requestHandlerErrorTitle', { - defaultMessage: 'Timelion request error', - }), - }); - - reject(err); - } - }); + toastNotifications.addError(err, { + title: i18n.translate('timelion.requestHandlerErrorTitle', { + defaultMessage: 'Timelion request error', + }), + }); + } }; } From 68ae787cb762e99420e3660302cc3d2725398f63 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 24 Sep 2019 16:10:44 +0300 Subject: [PATCH 38/42] Move npSetup npStart dependencies in a high level --- .../public/panels/timechart/schema.ts | 4 +- .../core_plugins/timelion/public/plugin.ts | 37 ++++++++++++++----- .../timelion/public/timelion_vis_fn.ts | 12 +++--- .../core_plugins/timelion/public/vis/index.ts | 2 +- .../public/vis/timelion_request_handler.ts | 7 ++-- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts index 5c28c443670ef..a9b788ca93055 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts @@ -22,7 +22,6 @@ import _ from 'lodash'; import $ from 'jquery'; import moment from 'moment-timezone'; import { timefilter } from 'ui/timefilter'; -import { npSetup } from 'ui/new_platform'; // @ts-ignore import observeResize from '../../lib/observe_resize'; // @ts-ignore @@ -33,10 +32,9 @@ import { xaxisFormatterProvider } from './xaxis_formatter'; import { generateTicksProvider } from './tick_generator'; const DEBOUNCE_DELAY = 50; -const { uiSettings } = npSetup.core; export function timechartFn(dependencies: TimelionStartDependencies) { - const { $rootScope, $compile } = dependencies; + const { $rootScope, $compile, uiSettings } = dependencies; return function() { return { help: 'Draw a timeseries chart', diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 97061e2a4a7d0..ec404d75b5edd 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -22,6 +22,8 @@ import { LegacyCoreStart, Plugin, PluginInitializerContext, + UiSettingsClientContract, + HttpSetup, } from 'kibana/public'; import { Plugin as ExpressionsPlugin } from 'src/plugins/expressions/public'; import { VisualizationsSetup } from '../../visualizations/public/np_ready'; @@ -34,12 +36,6 @@ import { LegacyDependenciesPluginStart, } from './shim'; -/** @internal */ -export { LegacyDependenciesPluginStart as TimelionStartDependencies }; - -/** @internal */ -export { LegacyDependenciesPluginSetup as TimelionSetupDependencies }; - /** @internal */ export interface TimelionPluginSetupDependencies { expressions: ReturnType; @@ -57,6 +53,21 @@ export interface TimelionPluginStartDependencies { __LEGACY: LegacyDependenciesPlugin; } +interface DependenciesPluginSetup { + uiSettings: UiSettingsClientContract; + http: HttpSetup; +} + +interface DependenciesPluginStart { + uiSettings: UiSettingsClientContract; +} + +/** @internal */ +export type TimelionSetupDependencies = DependenciesPluginSetup & LegacyDependenciesPluginSetup; + +/** @internal */ +export type TimelionStartDependencies = DependenciesPluginStart & LegacyDependenciesPluginStart; + /** @internal */ export class TimelionPlugin implements @@ -68,15 +79,23 @@ export class TimelionPlugin } public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { - const dependencies: LegacyDependenciesPluginSetup = await plugins.__LEGACY.setup(); - plugins.expressions.registerFunction(() => getTimelionVisualizationConfig()); + const dependencies: TimelionSetupDependencies = { + uiSettings: core.uiSettings, + http: core.http, + ...(await plugins.__LEGACY.setup()), + }; + + plugins.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); plugins.visualizations.types.registerVisualization(() => getTimelionVisualization(dependencies) ); } public async start(core: CoreStart & LegacyCoreStart, plugins: TimelionPluginStartDependencies) { - const dependencies: LegacyDependenciesPluginStart = await plugins.__LEGACY.start(); + const dependencies: TimelionStartDependencies = { + uiSettings: core.uiSettings, + ...(await plugins.__LEGACY.start()), + }; const timelionUiEnabled = core.injectedMetadata.getInjectedVar('timelionUiEnabled'); if (timelionUiEnabled === false) { diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index 30958b0ed8b9a..d92f118ca70af 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -21,6 +21,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { ExpressionFunction, KibanaContext, Render } from 'src/plugins/expressions/public'; import { getTimelionRequestHandler, TimelionSuccessResponse } from './vis/timelion_request_handler'; +import { TimelionSetupDependencies } from './plugin'; const name = 'timelion_vis'; @@ -39,12 +40,9 @@ type Context = KibanaContext | null; type VisParams = Arguments; type Return = Promise>; -export const getTimelionVisualizationConfig = (): ExpressionFunction< - typeof name, - Context, - Arguments, - Return -> => ({ +export const getTimelionVisualizationConfig = ( + dependencies: TimelionSetupDependencies +): ExpressionFunction => ({ name, type: 'render', context: { @@ -67,7 +65,7 @@ export const getTimelionVisualizationConfig = (): ExpressionFunction< }, }, async fn(context, args) { - const timelionRequestHandler = getTimelionRequestHandler(); + const timelionRequestHandler = getTimelionRequestHandler(dependencies); const visParams = { expression: args.expression, interval: args.interval }; diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index 54001b879da57..bcea78343333b 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -28,7 +28,7 @@ import { TimelionSetupDependencies } from '../plugin'; import { AngularVisController } from '../../../../ui/public/vis/vis_types/angular_vis_type'; export function getTimelionVisualization(dependencies: TimelionSetupDependencies) { - const timelionRequestHandler = getTimelionRequestHandler(); + const timelionRequestHandler = getTimelionRequestHandler(dependencies); // return the visType object, which kibana will use to display and configure new // Vis object of this type. diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index 47457fd55a59c..d3d1fa7f8e1d2 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -21,13 +21,13 @@ import { buildEsQuery, getEsQueryConfig, Filter } from '@kbn/es-query'; // @ts-ignore import { timezoneProvider } from 'ui/vis/lib/timezone'; -import { npSetup } from 'ui/new_platform'; import { KIBANA_CONTEXT_NAME } from 'src/plugins/expressions/public'; import { Query } from 'src/legacy/core_plugins/data/public'; import { TimeRange } from 'src/plugins/data/public'; import { VisParams } from 'ui/vis'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; +import { TimelionSetupDependencies } from '../plugin'; interface Stats { cacheCount: number; @@ -50,9 +50,8 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } -const { http, uiSettings } = npSetup.core; - -export function getTimelionRequestHandler() { +export function getTimelionRequestHandler(dependencies: TimelionSetupDependencies) { + const { uiSettings, http } = dependencies; const timezone = timezoneProvider(uiSettings)(); return async function({ From bb3ec7a2d81336619d855153b86a26edd0d94a1c Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 24 Sep 2019 17:16:49 +0300 Subject: [PATCH 39/42] Rename some details --- src/legacy/core_plugins/timelion/public/plugin.ts | 14 ++++++-------- .../public/shim/legacy_dependencies_plugin.ts | 2 -- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index ec404d75b5edd..e5a451fa543fb 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -53,20 +53,18 @@ export interface TimelionPluginStartDependencies { __LEGACY: LegacyDependenciesPlugin; } -interface DependenciesPluginSetup { - uiSettings: UiSettingsClientContract; - http: HttpSetup; -} - -interface DependenciesPluginStart { +interface TimelionVisualizationDependencies { uiSettings: UiSettingsClientContract; + http?: HttpSetup; } /** @internal */ -export type TimelionSetupDependencies = DependenciesPluginSetup & LegacyDependenciesPluginSetup; +export type TimelionSetupDependencies = TimelionVisualizationDependencies & + LegacyDependenciesPluginSetup; /** @internal */ -export type TimelionStartDependencies = DependenciesPluginStart & LegacyDependenciesPluginStart; +export type TimelionStartDependencies = TimelionVisualizationDependencies & + LegacyDependenciesPluginStart; /** @internal */ export class TimelionPlugin diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index b9904aee519f0..e1628bd3763cc 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -21,7 +21,6 @@ import chrome from 'ui/chrome'; import { Plugin } from 'kibana/public'; // @ts-ignore import { visFactory } from 'ui/vis/vis_factory'; -import { npStart } from 'ui/new_platform'; import { initTimelionLegacyModule } from './timelion_legacy_module'; /** @internal */ @@ -52,7 +51,6 @@ export class LegacyDependenciesPlugin return { $rootScope: $injector.get('$rootScope'), $compile: $injector.get('$compile'), - config: npStart.core.uiSettings, } as LegacyDependenciesPluginStart; } } From 97088040c0d76236e848aa920e0ba66923c44bab Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 24 Sep 2019 18:02:23 +0300 Subject: [PATCH 40/42] Fix reviews --- src/legacy/core_plugins/timelion/public/plugin.ts | 2 +- src/legacy/plugin_discovery/types.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index e5a451fa543fb..bc1430f0d7d6d 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -63,7 +63,7 @@ export type TimelionSetupDependencies = TimelionVisualizationDependencies & LegacyDependenciesPluginSetup; /** @internal */ -export type TimelionStartDependencies = TimelionVisualizationDependencies & +export type TimelionStartDependencies = Pick & LegacyDependenciesPluginStart; /** @internal */ diff --git a/src/legacy/plugin_discovery/types.ts b/src/legacy/plugin_discovery/types.ts index a789434a4caae..c14daa37f5706 100644 --- a/src/legacy/plugin_discovery/types.ts +++ b/src/legacy/plugin_discovery/types.ts @@ -73,7 +73,6 @@ export interface LegacyPluginOptions { visTypes: string[]; embeddableActions?: string[]; embeddableFactories?: string[]; - interpreter?: string[]; uiSettingDefaults?: Record; }>; uiCapabilities?: Capabilities; From dff86b391065e62676735f1c76891eca2472a94f Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 24 Sep 2019 18:52:07 +0300 Subject: [PATCH 41/42] fix CI --- src/legacy/core_plugins/timelion/public/plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index bc1430f0d7d6d..314e6751a81c3 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -53,9 +53,10 @@ export interface TimelionPluginStartDependencies { __LEGACY: LegacyDependenciesPlugin; } +/** @private */ interface TimelionVisualizationDependencies { uiSettings: UiSettingsClientContract; - http?: HttpSetup; + http: HttpSetup; } /** @internal */ From bb28ce83fee5c42d7d4901044e34ec93dcfe7092 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Thu, 26 Sep 2019 12:42:55 +0300 Subject: [PATCH 42/42] Take visFactory out --- .../core_plugins/timelion/public/plugin.ts | 16 ++++------------ .../public/shim/legacy_dependencies_plugin.ts | 16 ++-------------- .../timelion/public/timelion_vis_fn.ts | 4 ++-- .../core_plugins/timelion/public/vis/index.ts | 7 ++++--- .../public/vis/timelion_request_handler.ts | 4 ++-- 5 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index 314e6751a81c3..4adfac3726b95 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -30,11 +30,7 @@ import { VisualizationsSetup } from '../../visualizations/public/np_ready'; import { getTimelionVisualizationConfig } from './timelion_vis_fn'; import { getTimelionVisualization } from './vis'; import { getTimeChart } from './panels/timechart/timechart'; -import { - LegacyDependenciesPlugin, - LegacyDependenciesPluginSetup, - LegacyDependenciesPluginStart, -} from './shim'; +import { LegacyDependenciesPlugin, LegacyDependenciesPluginStart } from './shim'; /** @internal */ export interface TimelionPluginSetupDependencies { @@ -54,15 +50,11 @@ export interface TimelionPluginStartDependencies { } /** @private */ -interface TimelionVisualizationDependencies { +export interface TimelionVisualizationDependencies { uiSettings: UiSettingsClientContract; http: HttpSetup; } -/** @internal */ -export type TimelionSetupDependencies = TimelionVisualizationDependencies & - LegacyDependenciesPluginSetup; - /** @internal */ export type TimelionStartDependencies = Pick & LegacyDependenciesPluginStart; @@ -78,12 +70,12 @@ export class TimelionPlugin } public async setup(core: CoreSetup, plugins: TimelionPluginSetupDependencies) { - const dependencies: TimelionSetupDependencies = { + const dependencies: TimelionVisualizationDependencies = { uiSettings: core.uiSettings, http: core.http, - ...(await plugins.__LEGACY.setup()), }; + plugins.__LEGACY.setup(); plugins.expressions.registerFunction(() => getTimelionVisualizationConfig(dependencies)); plugins.visualizations.types.registerVisualization(() => getTimelionVisualization(dependencies) diff --git a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts index e1628bd3763cc..82c908e78ce7b 100644 --- a/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts +++ b/src/legacy/core_plugins/timelion/public/shim/legacy_dependencies_plugin.ts @@ -19,15 +19,8 @@ import chrome from 'ui/chrome'; import { Plugin } from 'kibana/public'; -// @ts-ignore -import { visFactory } from 'ui/vis/vis_factory'; import { initTimelionLegacyModule } from './timelion_legacy_module'; -/** @internal */ -export interface LegacyDependenciesPluginSetup { - createBaseVisualization: Function; -} - /** @internal */ export interface LegacyDependenciesPluginStart { $rootScope: any; @@ -35,14 +28,9 @@ export interface LegacyDependenciesPluginStart { } export class LegacyDependenciesPlugin - implements - Plugin, Promise> { - public async setup() { + implements Plugin> { + public setup() { initTimelionLegacyModule(); - - return { - createBaseVisualization: visFactory.createBaseVisualization, - } as LegacyDependenciesPluginSetup; } public async start() { diff --git a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts index d92f118ca70af..86bc9a8088217 100644 --- a/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts +++ b/src/legacy/core_plugins/timelion/public/timelion_vis_fn.ts @@ -21,7 +21,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { ExpressionFunction, KibanaContext, Render } from 'src/plugins/expressions/public'; import { getTimelionRequestHandler, TimelionSuccessResponse } from './vis/timelion_request_handler'; -import { TimelionSetupDependencies } from './plugin'; +import { TimelionVisualizationDependencies } from './plugin'; const name = 'timelion_vis'; @@ -41,7 +41,7 @@ type VisParams = Arguments; type Return = Promise>; export const getTimelionVisualizationConfig = ( - dependencies: TimelionSetupDependencies + dependencies: TimelionVisualizationDependencies ): ExpressionFunction => ({ name, type: 'render', diff --git a/src/legacy/core_plugins/timelion/public/vis/index.ts b/src/legacy/core_plugins/timelion/public/vis/index.ts index bcea78343333b..e7f1c91a3393d 100644 --- a/src/legacy/core_plugins/timelion/public/vis/index.ts +++ b/src/legacy/core_plugins/timelion/public/vis/index.ts @@ -20,19 +20,20 @@ import { i18n } from '@kbn/i18n'; // @ts-ignore import { DefaultEditorSize } from 'ui/vis/editor_size'; +import { visFactory } from '../../../visualizations/public'; import { getTimelionRequestHandler } from './timelion_request_handler'; import visConfigTemplate from './timelion_vis.html'; import editorConfigTemplate from './timelion_vis_params.html'; -import { TimelionSetupDependencies } from '../plugin'; +import { TimelionVisualizationDependencies } from '../plugin'; // @ts-ignore import { AngularVisController } from '../../../../ui/public/vis/vis_types/angular_vis_type'; -export function getTimelionVisualization(dependencies: TimelionSetupDependencies) { +export function getTimelionVisualization(dependencies: TimelionVisualizationDependencies) { const timelionRequestHandler = getTimelionRequestHandler(dependencies); // return the visType object, which kibana will use to display and configure new // Vis object of this type. - return dependencies.createBaseVisualization({ + return visFactory.createBaseVisualization({ name: 'timelion', title: 'Timelion', icon: 'visTimelion', diff --git a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts index d3d1fa7f8e1d2..1fbf371c8f91e 100644 --- a/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts +++ b/src/legacy/core_plugins/timelion/public/vis/timelion_request_handler.ts @@ -27,7 +27,7 @@ import { TimeRange } from 'src/plugins/data/public'; import { VisParams } from 'ui/vis'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; -import { TimelionSetupDependencies } from '../plugin'; +import { TimelionVisualizationDependencies } from '../plugin'; interface Stats { cacheCount: number; @@ -50,7 +50,7 @@ export interface TimelionSuccessResponse { type: KIBANA_CONTEXT_NAME; } -export function getTimelionRequestHandler(dependencies: TimelionSetupDependencies) { +export function getTimelionRequestHandler(dependencies: TimelionVisualizationDependencies) { const { uiSettings, http } = dependencies; const timezone = timezoneProvider(uiSettings)();