Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional visualizations plugin cleanup before moving to NP #59318

Merged
merged 16 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from '../../../../../../plugins/data/public';

import { buildTabularInspectorData } from './build_tabular_inspector_data';
import { calculateObjectHash } from '../../../../visualizations/public';
import { calculateObjectHash } from '../../../../../../plugins/kibana_utils/common/calculate_object_hash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be imported from the root?

import { tabifyAggResponse } from '../../../../../core_plugins/data/public';
import { PersistedState } from '../../../../../../plugins/visualizations/public';
import { Adapters } from '../../../../../../plugins/inspector/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import { i18n } from '@kbn/i18n';
import { createInputControlVisController } from './vis_controller';
import { getControlsTab } from './components/editor/controls_tab';
import { OptionsTab } from './components/editor/options_tab';
import { Status, defaultFeedbackMessage } from '../../visualizations/public';
import { Status } from '../../visualizations/public';
import { InputControlVisDependencies } from './plugin';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/common/default_feedback_message';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should be imported from the root?


export function createInputControlVisTypeDefinition(deps: InputControlVisDependencies) {
const InputControlVisController = createInputControlVisController(deps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function setServices(newServices: any) {
// EXPORT legacy static dependencies, should be migrated when available in a new version;
export { angular };
export { wrapInI18nContext } from 'ui/i18n';
export { buildVislibDimensions } from '../../../visualizations/public';
export { getRequestInspectorStats, getResponseInspectorStats } from '../../../data/public';
// @ts-ignore
export { intervalOptions } from 'ui/agg_types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { getPainlessError } from './get_painless_error';
import { discoverResponseHandler } from './response_handler';
import {
angular,
buildVislibDimensions,
getRequestInspectorStats,
getResponseInspectorStats,
getServices,
Expand Down Expand Up @@ -818,13 +817,28 @@ function discoverController(
if ($scope.opts.timefield) {
const tabifiedData = tabifyAggResponse($scope.vis.aggs, resp);
$scope.searchSource.rawResponse = resp;
Promise.resolve(
buildVislibDimensions($scope.vis, {
timeRange: $scope.timeRange,
searchSource: $scope.searchSource,
})
).then(resp => {
$scope.histogramData = discoverResponseHandler(tabifiedData, resp);
const metric = $scope.vis.aggs.aggs[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of clarity, I would put this code into a buildVislibDimensions function in this file

const agg = $scope.vis.aggs.aggs[0];
agg.params.timeRange = $scope.timeRange;
agg.buckets.setBounds(agg);
const { esUnit, esValue } = agg.buckets.getInterval();
$scope.histogramData = discoverResponseHandler(tabifiedData, {
x: {
accessor: 1,
label: agg.makeLabel(),
params: {
date: true,
interval: moment.duration(esValue, esUnit),
intervalESValue: esValue,
intervalESUnit: esUnit,
format: agg.buckets.getScaledDateFormat(),
bounds: agg.buckets.getBounds(),
},
},
y: {
accessor: 0,
label: metric.makeLabel(),
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n';
import { npStart } from 'ui/new_platform';
import { SavedObjectLoader } from '../../../../../plugins/saved_objects/public';
import { createSavedDashboardLoader } from '../dashboard';
import { TypesService, createSavedVisLoader } from '../../../visualizations/public';
import { start as visualizations } from '../../../visualizations/public/np_ready/public/legacy';
import { createSavedSearchesLoader } from '../../../../../plugins/discover/public';

/**
Expand Down Expand Up @@ -58,10 +58,7 @@ const services = {

savedObjectManagementRegistry.register({
id: 'savedVisualizations',
service: createSavedVisLoader({
...services,
...{ visualizationTypes: new TypesService().start() },
}),
service: visualizations.savedVisualizationsLoader,
title: 'visualizations',
});

Expand Down
10 changes: 2 additions & 8 deletions src/legacy/core_plugins/timelion/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import '../../data/public/legacy';
import './services/saved_sheet_register';

import rootTemplate from 'plugins/timelion/index.html';
import { createSavedVisLoader, TypesService } from '../../visualizations/public';
import { start as visualizations } from '../../visualizations/public/np_ready/public/legacy';

import { loadKbnTopNavDirectives } from '../../../../plugins/kibana_legacy/public';
loadKbnTopNavDirectives(npStart.plugins.navigation.ui);
Expand Down Expand Up @@ -127,13 +127,7 @@ app.controller('timelion', function(
timefilter.enableAutoRefreshSelector();
timefilter.enableTimeRangeSelector();

const savedVisualizations = createSavedVisLoader({
savedObjectsClient: npStart.core.savedObjects.client,
indexPatterns: npStart.plugins.data.indexPatterns,
chrome: npStart.core.chrome,
overlays: npStart.core.overlays,
visualizationTypes: new TypesService().start(),
});
const savedVisualizations = visualizations.savedVisualizationsLoader;
const timezone = Private(timezoneProvider)();

const defaultExpression = '.es(*)';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { metricsRequestHandler } from './request_handler';
import { EditorController } from './editor_controller';
// @ts-ignore
import { PANEL_TYPES } from '../../../../plugins/vis_type_timeseries/common/panel_types';
import { defaultFeedbackMessage } from '../../visualizations/public';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/common/default_feedback_message';

export const metricsVisDefinition = {
name: 'metrics',
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/core_plugins/vis_type_vega/public/vega_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

import { i18n } from '@kbn/i18n';
// @ts-ignore
import { Status, defaultFeedbackMessage } from '../../visualizations/public';
import { Status } from '../../visualizations/public';
import { DefaultEditorSize } from '../../vis_default_editor/public';
import { VegaVisualizationDependencies } from './plugin';
import { VegaVisEditor } from './components';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/common/default_feedback_message';

import { createVegaRequestHandler } from './vega_request_handler';
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,11 @@ export { Vis, VisParams, VisState } from './vis';
import { VisualizeEmbeddableFactory, VisualizeEmbeddable } from './embeddable';
export type VisualizeEmbeddableFactoryContract = PublicContract<VisualizeEmbeddableFactory>;
export type VisualizeEmbeddableContract = PublicContract<VisualizeEmbeddable>;
export { TypesService } from './vis_types/types_service';
export { Status } from './legacy/update_status'; // should remove
export { VISUALIZE_EMBEDDABLE_TYPE, VisualizeInput } from './embeddable';
export { SchemaConfig } from './legacy/build_pipeline';

export function plugin(initializerContext: PluginInitializerContext) {
return new VisualizationsPlugin(initializerContext);
}

/** @public static code */
export { TypesService } from './vis_types/types_service';
export { VISUALIZE_EMBEDDABLE_TYPE, VisualizeInput } from './embeddable';

export { Status } from './legacy/update_status';
export { buildPipeline, buildVislibDimensions, SchemaConfig } from './legacy/build_pipeline';

// @ts-ignore
export { updateOldState } from './legacy/vis_update_state';
export { calculateObjectHash } from './legacy/calculate_object_hash';
export { createSavedVisLoader } from './saved_visualizations/saved_visualizations';
export { defaultFeedbackMessage } from './misc/default_feedback_message';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { PersistedState } from '../../../../../../../plugins/visualizations/public';
import { calculateObjectHash } from './calculate_object_hash';
import { calculateObjectHash } from '../../../../../../../plugins/kibana_utils/common/calculate_object_hash';
import { Vis } from '../vis';

enum Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,32 @@ export class TypesService {
this.types[visDefinition.name] = visDefinition;
};
return {
/**
* registers a visualization type
* @param {VisType} config - visualization type definition
*/
createBaseVisualization: (config: any) => {
const vis = new BaseVisType(config);
registerVisualization(() => vis);
},
/**
* registers a visualization which uses react for rendering
* @param {VisType} config - visualization type definition
*/
createReactVisualization: (config: any) => {
const vis = new ReactVisType(config);
registerVisualization(() => vis);
},
/**
* registers a visualization alias
* alias is a visualization type without implementation, it just redirects somewhere in kibana
* @param {VisTypeAlias} config - visualization alias definition
*/
registerAlias: visTypeAliasRegistry.add,
/**
* allows to hide specific visualization types from create visualization dialog
* @param {string[]} typeNames - list of type ids to hide
*/
hideTypes: (typeNames: string[]) => {
typeNames.forEach((name: string) => {
if (this.types[name]) {
Expand All @@ -90,12 +107,22 @@ export class TypesService {

public start() {
return {
/**
* returns specific visualization or undefined if not found
* @param {string} visualization - id of visualization to return
*/
get: (visualization: string) => {
return this.types[visualization];
},
/**
* returns all registered visualization types
*/
all: () => {
return [...Object.values(this.types)];
},
/**
* returns all registered aliases
*/
getAliases: visTypeAliasRegistry.get,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface ShowNewVisModalParams {
onClose?: () => void;
}

/**
* shows modal dialog that allows you to create new visualization
* @param {string[]} editorParams
* @param {function} onClose - function that will be called when dialog is closed
*/
export function showNewVisModal({ editorParams = [], onClose }: ShowNewVisModalParams = {}) {
const container = document.createElement('div');
let isClosed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

// adopted form https://github.com/bevacqua/hash-sum

function pad(hash, len) {
function pad(hash: string, len: number): string {
while (hash.length < len) {
hash = '0' + hash;
}
return hash;
}

function fold(hash, text) {
function fold(hash: number, text: string): number {
let i;
let chr;
let len;
Expand All @@ -35,22 +35,25 @@ function fold(hash, text) {
}
for (i = 0, len = text.length; i < len; i++) {
chr = text.charCodeAt(i);
// eslint-disable-next-line no-bitwise
hash = (hash << 5) - hash + chr;
// eslint-disable-next-line no-bitwise
hash |= 0;
}
return hash < 0 ? hash * -2 : hash;
}

function foldObject(hash, o, seen) {
function foldObject(hash: number, o: any, seen: any[]) {
function foldKey(h: number, key: string): number {
return foldValue(h, o[key], key, seen);
}

return Object.keys(o)
.sort()
.reduce(foldKey, hash);
function foldKey(hash, key) {
return foldValue(hash, o[key], key, seen);
}
}

function foldValue(input, value, key, seen) {
function foldValue(input: number, value: any, key: string, seen: any[]) {
const hash = fold(fold(fold(input, key), toString(value)), typeof value);
if (value === null) {
return fold(hash, 'null');
Expand All @@ -72,11 +75,11 @@ function foldValue(input, value, key, seen) {
return fold(hash, value.toString());
}

function toString(o) {
function toString(o: object): string {
return Object.prototype.toString.call(o);
}

function sum(o) {
function sum(o: object): string {
return pad(foldValue(0, o, '', []).toString(16), 8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { i18n } from '@kbn/i18n';

export const defaultFeedbackMessage = i18n.translate('visualizations.defaultFeedbackMessage', {
export const defaultFeedbackMessage = i18n.translate('kibana_utils.defaultFeedbackMessage', {
defaultMessage: 'Have feedback? Please create an issue in {link}.',
values: {
link:
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,6 @@
"timelion.vis.intervalLabel": "間隔",
"uiActions.actionPanel.title": "オプション",
"uiActions.errors.incompatibleAction": "操作に互換性がありません",
"visualizations.defaultFeedbackMessage": "フィードバックがありますか?{link} で問題を報告してください。",
"visualizations.newVisWizard.betaDescription": "このビジュアライゼーションはベータ段階で、変更される可能性があります。デザインとコードはオフィシャル GA 機能よりも完成度が低く、現状のまま保証なしで提供されています。ベータ機能にはオフィシャル GA 機能の SLA が適用されません",
"visualizations.newVisWizard.betaTitle": "ベータ",
"visualizations.newVisWizard.chooseSourceTitle": "ソースの選択",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,6 @@
"timelion.vis.intervalLabel": "时间间隔",
"uiActions.actionPanel.title": "选项",
"uiActions.errors.incompatibleAction": "操作不兼容",
"visualizations.defaultFeedbackMessage": "想反馈?请在“{link}中创建问题。",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n removed, but not added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats what our i18n tool does and should be ok

"visualizations.newVisWizard.betaDescription": "此可视化为公测版,可能会进行更改。设计和代码相对于正式发行版功能还不够成熟,将按原样提供,且不提供任何保证。公测版功能不受正式发行版功能支持 SLA 的约束",
"visualizations.newVisWizard.betaTitle": "公测版",
"visualizations.newVisWizard.chooseSourceTitle": "选择源",
Expand Down