Skip to content

Commit

Permalink
[NP] Migrate Tagcloud to NP (#63445)
Browse files Browse the repository at this point in the history
* [NP] Migrate Tagcloud to NP

* Fixed eslint issue

* Added styles import and disabled eslint in some lines with paths

* Added a simple server part and moved tests

* Imported setFormatService to fix initialization

* Fixed import of setFormatService

* Removed unnecessary eslint disable comment
  • Loading branch information
DianaDerevyankina authored Apr 23, 2020
1 parent dc5fb63 commit 7045b02
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"visTypeMarkdown": "src/plugins/vis_type_markdown",
"visTypeMetric": "src/plugins/vis_type_metric",
"visTypeTable": "src/plugins/vis_type_table",
"visTypeTagCloud": "src/legacy/core_plugins/vis_type_tagcloud",
"visTypeTagCloud": "src/plugins/vis_type_tagcloud",
"visTypeTimeseries": ["src/legacy/core_plugins/vis_type_timeseries", "src/plugins/vis_type_timeseries"],
"visTypeVega": "src/legacy/core_plugins/vis_type_vega",
"visTypeVislib": "src/legacy/core_plugins/vis_type_vislib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import expect from '@kbn/expect';
import _ from 'lodash';
import d3 from 'd3';

import { TagCloud } from '../tag_cloud';
import { fromNode, delay } from 'bluebird';
import { ImageComparator } from 'test_utils/image_comparator';
import simpleloadPng from './simpleload.png';

// Replace with mock when converting to jest tests
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { seedColors } from '../../../../../../plugins/charts/public/services/colors/seed_colors';
// Will be replaced with new path when tests are moved
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { TagCloud } from '../../../../../../plugins/vis_type_tagcloud/public/components/tag_cloud';

describe('tag cloud tests', function() {
const minValue = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { ImageComparator } from 'test_utils/image_comparator';
import { createTagCloudVisualization } from '../tag_cloud_visualization';
import basicdrawPng from './basicdraw.png';
import afterresizePng from './afterresize.png';
import afterparamChange from './afterparamchange.png';
Expand All @@ -32,7 +31,14 @@ import { ExprVis } from '../../../../../../plugins/visualizations/public/express
import { seedColors } from '../../../../../../plugins/charts/public/services/colors/seed_colors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { BaseVisType } from '../../../../../../plugins/visualizations/public/vis_types/base_vis_type';
import { createTagCloudVisTypeDefinition } from '../../tag_cloud_type';
// Will be replaced with new path when tests are moved
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createTagCloudVisTypeDefinition } from '../../../../../../plugins/vis_type_tagcloud/public/tag_cloud_type';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createTagCloudVisualization } from '../../../../../../plugins/vis_type_tagcloud/public/components/tag_cloud_visualization';
import { npStart } from 'ui/new_platform';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setFormatService } from '../../../../../../plugins/vis_type_tagcloud/public/services';

const THRESHOLD = 0.65;
const PIXEL_DIFF = 64;
Expand Down Expand Up @@ -66,6 +72,8 @@ describe('TagCloudVisualizationTest', function() {
},
});

before(() => setFormatService(npStart.plugins.data.fieldFormats));

beforeEach(ngMock.module('kibana'));

describe('TagCloudVisualization - basics', function() {
Expand Down
44 changes: 0 additions & 44 deletions src/legacy/core_plugins/vis_type_tagcloud/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/legacy/core_plugins/vis_type_tagcloud/package.json

This file was deleted.

26 changes: 26 additions & 0 deletions src/plugins/vis_type_tagcloud/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
7 changes: 7 additions & 0 deletions src/plugins/vis_type_tagcloud/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "visTypeTagcloud",
"version": "kibana",
"ui": true,
"server": true,
"requiredPlugins": ["data", "expressions", "visualizations", "charts"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import React from 'react';
import { EuiPanel } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import { ValidatedDualRange } from '../../../../../../src/plugins/kibana_react/public';
import { SelectOption, SwitchOption } from '../../../../../plugins/charts/public';
import { VisOptionsProps } from '../../../vis_default_editor/public';
import { ValidatedDualRange } from '../../../kibana_react/public';
import { SelectOption, SwitchOption } from '../../../charts/public';
import { TagCloudVisParams } from '../types';

function TagCloudOptions({ stateParams, setValue, vis }: VisOptionsProps<TagCloudVisParams>) {
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 "tgc" to avoid conflicts.
// Examples
// tgcChart
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 'kibana/public';
import { TagCloudPlugin as Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
* under the License.
*/

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

import { createTagCloudFn } from './tag_cloud_fn';
import { createTagCloudVisTypeDefinition } from './tag_cloud_type';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
import { DataPublicPluginStart } from '../../data/public';
import { setFormatService } from './services';
import { ConfigSchema } from '../config';

import './index.scss';

/** @internal */
export interface TagCloudPluginSetupDependencies {
Expand All @@ -46,9 +49,9 @@ export interface TagCloudVisPluginStartDependencies {

/** @internal */
export class TagCloudPlugin implements Plugin<void, void> {
initializerContext: PluginInitializerContext;
initializerContext: PluginInitializerContext<ConfigSchema>;

constructor(initializerContext: PluginInitializerContext) {
constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
this.initializerContext = initializerContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* under the License.
*/

import { createGetterSetter } from '../../../../plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
import { createGetterSetter } from '../../kibana_utils/public';
import { DataPublicPluginStart } from '../../data/public';

export const [getFormatService, setFormatService] = createGetterSetter<
DataPublicPluginStart['fieldFormats']
>('data.fieldFormats');

export { npStart } from 'ui/new_platform';
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

import { createTagCloudFn } from './tag_cloud_fn';

// eslint-disable-next-line
import { functionWrapper } from '../../../../plugins/expressions/common/expression_functions/specs/tests/utils';
import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';

describe('interpreter/functions#tagcloud', () => {
const fn = functionWrapper(createTagCloudFn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

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

import {
ExpressionFunctionDefinition,
KibanaDatatable,
Render,
} from '../../../../plugins/expressions/public';
import { ExpressionFunctionDefinition, KibanaDatatable, Render } from '../../expressions/public';
import { TagCloudVisParams } from './types';

const name = 'tagcloud';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

import { Schemas } from '../../../../plugins/vis_default_editor/public';
import { Schemas } from '../../vis_default_editor/public';

import { TagCloudOptions } from './components/tag_cloud_options';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
* under the License.
*/

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

const plugins: Readonly<TagCloudPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
visualizations: npSetup.plugins.visualizations,
charts: npSetup.plugins.charts,
};
import { configSchema, ConfigSchema } from '../config';

const pluginInstance = plugin({} as PluginInitializerContext);
export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
deprecations: ({ renameFromRoot }) => [
renameFromRoot('tagcloud.enabled', 'vis_type_tagcloud.enabled'),
],
};

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core, { data: npStart.plugins.data });
export const plugin = () => ({
setup() {},
start() {},
});

0 comments on commit 7045b02

Please sign in to comment.