Skip to content

Commit

Permalink
[NP] TSVB (elastic#63237)
Browse files Browse the repository at this point in the history
* Move TSVB into new platform

* Get rid of isFunction checks

* Remove extra import of styling constants

* Move styles importing into plugin.ts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	.github/CODEOWNERS
  • Loading branch information
sulemanof committed Apr 15, 2020
1 parent af15120 commit 6672a95
Show file tree
Hide file tree
Showing 211 changed files with 65 additions and 129 deletions.
45 changes: 0 additions & 45 deletions src/legacy/core_plugins/vis_type_timeseries/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/legacy/core_plugins/vis_type_timeseries/package.json

This file was deleted.

2 changes: 2 additions & 0 deletions src/plugins/vis_type_timeseries/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"version": "8.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["data", "expressions", "visualizations"],
"optionalPlugins": ["usageCollection"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import uuid from 'uuid';
import _ from 'lodash';

const newFn = () => ({ id: uuid.v1() });

Expand All @@ -30,30 +29,23 @@ export function handleChange(props, doc) {
if (row.id === doc.id) return doc;
return row;
});
if (_.isFunction(props.onChange)) {
props.onChange(_.assign({}, model, part));
}
props.onChange?.({ ...model, ...part });
}

export function handleDelete(props, doc) {
const { model, name } = props;
const collection = model[name] || [];
const part = {};
part[name] = collection.filter(row => row.id !== doc.id);
if (_.isFunction(props.onChange)) {
props.onChange(_.assign({}, model, part));
}
props.onChange?.({ ...model, ...part });
}

export function handleAdd(props, fn = newFn) {
if (!_.isFunction(fn)) fn = newFn;
const { model, name } = props;
const collection = model[name] || [];
const part = {};
part[name] = collection.concat([fn()]);
if (_.isFunction(props.onChange)) {
props.onChange(_.assign({}, model, part));
}
props.onChange?.({ ...model, ...part });
}

export const collectionActions = { handleAdd, handleDelete, handleChange };
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const createNumberHandler = handleChange => {
if (!detectIE() || e.keyCode === 13) e.preventDefault();

const value = Number(_.get(e, 'target.value', defaultValue));
if (_.isFunction(handleChange)) {
return handleChange({ [name]: value });
}
return handleChange?.({ [name]: value });
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import _ from 'lodash';

export const createSelectHandler = handleChange => {
return name => selectedOptions => {
if (_.isFunction(handleChange)) {
return handleChange({
[name]: _.get(selectedOptions, '[0].value', null),
});
}
return handleChange?.({
[name]: _.get(selectedOptions, '[0].value', null),
});
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export const createTextHandler = handleChange => {
if (!detectIE() || e.keyCode === 13) e.preventDefault();

const value = _.get(e, 'target.value', defaultValue);
if (_.isFunction(handleChange)) {
return handleChange({ [name]: value });
}
return handleChange?.({ [name]: value });
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { getUISettings } from '../../services';
import { getUISettings } from '../../../services';

export function getDefaultQueryLanguage() {
return getUISettings().get('search:queryLanguage');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import handlebars from 'handlebars/dist/handlebars';
import { isNumber } from 'lodash';
import { inputFormats, outputFormats, isDuration } from '../lib/durations';
import { getFieldFormats } from '../../services';
import { getFieldFormats } from '../../../services';

export const createTickFormatter = (format = '0,0.[00]', template, getConfig = null) => {
const fieldFormats = getFieldFormats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { createTickFormatter } from './tick_formatter';
import { getFieldFormatsRegistry } from '../../../../../../test_utils/public/stub_field_formats';
import { setFieldFormats } from '../../services';
import { setFieldFormats } from '../../../services';

const mockUiSettings = {
get: item => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { createBrushHandler } from '../lib/create_brush_handler';
import { fetchFields } from '../lib/fetch_fields';
import { extractIndexPatterns } from '../../../../../plugins/vis_type_timeseries/common/extract_index_patterns';
import { esKuery } from '../../../../../plugins/data/public';
import { getSavedObjectsClient, getUISettings, getDataStart, getCoreStart } from '../services';
import { getSavedObjectsClient, getUISettings, getDataStart, getCoreStart } from '../../services';

import { CoreStartContextProvider } from '../contexts/query_input_bar_context';
import { KibanaContextProvider } from '../../../../../plugins/kibana_react/public';
Expand Down Expand Up @@ -96,7 +96,7 @@ export class VisEditor extends Component {
return true;
};

handleChange = async partialModel => {
handleChange = partialModel => {
if (isEmpty(partialModel)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { EuiToolTip, EuiIcon } from '@elastic/eui';
import { replaceVars } from '../../lib/replace_vars';
import { fieldFormats } from '../../../../../../../plugins/data/public';
import { FormattedMessage } from '@kbn/i18n/react';
import { getFieldFormats } from '../../../services';
import { getFieldFormats } from '../../../../services';

import { METRIC_TYPES } from '../../../../../../../plugins/vis_type_timeseries/common/metric_types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { getInterval } from '../../lib/get_interval';
import { areFieldsDifferent } from '../../lib/charts';
import { createXaxisFormatter } from '../../lib/create_xaxis_formatter';
import { STACKED_OPTIONS } from '../../../visualizations/constants';
import { getCoreStart, getUISettings } from '../../../services';
import { getCoreStart, getUISettings } from '../../../../services';

export class TimeseriesVisualization extends Component {
static propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { fetchIndexPatternFields } from './lib/fetch_fields';
import { getSavedObjectsClient, getUISettings, getI18n } from './services';
import { getSavedObjectsClient, getUISettings, getI18n } from '../services';
import { VisEditor } from './components/vis_editor';

export class EditorController {
constructor(el, vis, eventEmitter, embeddableHandler) {
Expand Down Expand Up @@ -55,19 +56,14 @@ export class EditorController {
this.state.isLoaded = true;
};

getComponent = () => {
return this.state.vis.type.editorConfig.component;
};

async render(params) {
const Component = this.getComponent();
const I18nContext = getI18n().Context;

!this.state.isLoaded && (await this.fetchDefaultParams());

render(
<I18nContext>
<Component
<VisEditor
config={getUISettings()}
vis={this.state.vis}
visFields={this.state.fields}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import 'src/legacy/ui/public/styles/styling_constants';

// Prefix all styles with "tvb" to avoid conflicts.
// Examples
// tvbChart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { MetricsPluginSetupDependencies } from './plugin';
import { plugin } from '.';

const plugins: Readonly<MetricsPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
visualizations: npSetup.plugins.visualizations,
};

const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core, npStart.plugins);
// @ts-ignore
export { EditorController } from './editor_controller';
export * from './lib';
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/
import { i18n } from '@kbn/i18n';
import { extractIndexPatterns } from '../../../../../plugins/vis_type_timeseries/common/extract_index_patterns';
import { getCoreStart } from '../services';
import { extractIndexPatterns } from '../../../common/extract_index_patterns';
import { getCoreStart } from '../../services';

export async function fetchFields(indexPatterns = ['*']) {
const patterns = Array.isArray(indexPatterns) ? indexPatterns : [indexPatterns];
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/vis_type_timeseries/public/application/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

// @ts-ignore
export { validateInterval } from './validate_interval';
export { getTimezone } from './get_timezone';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import color from 'color';
import { getUISettings } from '../services';
import { getUISettings } from '../../services';

const isDarkTheme = () => getUISettings().get('theme:darkMode');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import { EuiIcon } from '@elastic/eui';
import { getTimezone } from '../../../lib/get_timezone';
import { eventBus, ACTIVE_CURSOR } from '../../lib/active_cursor';
import { getUISettings } from '../../../services';
import { getUISettings } from '../../../../services';
import { GRID_LINE_CONFIG, ICON_TYPES_MAP, STACKED_OPTIONS } from '../../constants';
import { AreaSeriesDecorator } from './decorators/area_decorator';
import { BarSeriesDecorator } from './decorators/bar_decorator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { PluginInitializerContext } from '../../../../core/public';
import { PluginInitializerContext } from '../../../core/public';
import { MetricsPlugin as Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@

import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import {
ExpressionFunctionDefinition,
KibanaContext,
Render,
} from '../../../../plugins/expressions/public';
import { PersistedState } from '../../../../plugins/visualizations/public';
import { ExpressionFunctionDefinition, KibanaContext, Render } from '../../expressions/public';
import { PersistedState } from '../../visualizations/public';

// @ts-ignore
import { metricsRequestHandler } from './request_handler';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import { i18n } from '@kbn/i18n';

// @ts-ignore
import { metricsRequestHandler } from './request_handler';
import { EditorController } from './application';
// @ts-ignore
import { EditorController } from './editor_controller';
// @ts-ignore
import { PANEL_TYPES } from '../../../../plugins/vis_type_timeseries/common/panel_types';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/public';
import { PANEL_TYPES } from '../common/panel_types';
import { defaultFeedbackMessage } from '../../kibana_utils/public';

export const metricsVisDefinition = {
name: 'metrics',
Expand Down Expand Up @@ -69,12 +68,9 @@ export const metricsVisDefinition = {
show_legend: 1,
show_grid: 1,
},
component: require('./components/vis_editor').VisEditor,
component: require('./application/components/vis_editor').VisEditor,
},
editor: EditorController,
editorConfig: {
component: require('./components/vis_editor').VisEditor,
},
options: {
showQueryBar: false,
showFilterBar: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/

import './application/index.scss';

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public';
import { VisualizationsSetup } from '../../../../plugins/visualizations/public';
import { Plugin as ExpressionsPublicPlugin } from '../../expressions/public';
import { VisualizationsSetup } from '../../visualizations/public';

import { createMetricsFn } from './metrics_fn';
import { metricsVisDefinition } from './metrics_type';
Expand All @@ -30,7 +33,7 @@ import {
setCoreStart,
setDataStart,
} from './services';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
import { DataPublicPluginStart } from '../../data/public';

/** @internal */
export interface MetricsPluginSetupDependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* under the License.
*/

import { validateInterval } from './lib/validate_interval';
import { getTimezone } from './lib/get_timezone';
import { getTimezone, validateInterval } from './application';
import { getUISettings, getDataStart, getCoreStart } from './services';

export const metricsRequestHandler = async ({
Expand Down
Loading

0 comments on commit 6672a95

Please sign in to comment.