From d39432c3eeb69f77baa8f4d2947d61620ab5f059 Mon Sep 17 00:00:00 2001 From: Peter Pisljar Date: Wed, 12 Jun 2019 12:26:31 +0200 Subject: [PATCH] Initial visualizations plugin. (#35625) (#38639) --- .../core_plugins/visualizations/index.ts | 38 +++++++++++ .../core_plugins/visualizations/package.json | 4 ++ .../public/filters/filters_service.ts | 42 ++++++++++++ .../visualizations/public/filters/index.ts | 20 ++++++ .../visualizations/public/index.ts | 68 +++++++++++++++++++ .../visualizations/public/types/index.ts | 32 +++++++++ .../public/types/types_service.ts | 59 ++++++++++++++++ .../{utils => vis/vis_filters}/brush_event.js | 0 .../vis_filters}/brush_event.test.js | 2 +- src/legacy/ui/public/vis/vis_filters/index.js | 20 ++++++ .../vis/{ => vis_filters}/vis_filters.js | 6 +- 11 files changed, 287 insertions(+), 4 deletions(-) create mode 100644 src/legacy/core_plugins/visualizations/index.ts create mode 100644 src/legacy/core_plugins/visualizations/package.json create mode 100644 src/legacy/core_plugins/visualizations/public/filters/filters_service.ts create mode 100644 src/legacy/core_plugins/visualizations/public/filters/index.ts create mode 100644 src/legacy/core_plugins/visualizations/public/index.ts create mode 100644 src/legacy/core_plugins/visualizations/public/types/index.ts create mode 100644 src/legacy/core_plugins/visualizations/public/types/types_service.ts rename src/legacy/ui/public/{utils => vis/vis_filters}/brush_event.js (100%) rename src/legacy/ui/public/{utils/__tests__ => vis/vis_filters}/brush_event.test.js (99%) create mode 100644 src/legacy/ui/public/vis/vis_filters/index.js rename src/legacy/ui/public/vis/{ => vis_filters}/vis_filters.js (95%) diff --git a/src/legacy/core_plugins/visualizations/index.ts b/src/legacy/core_plugins/visualizations/index.ts new file mode 100644 index 0000000000000..bb9ef1588bdc2 --- /dev/null +++ b/src/legacy/core_plugins/visualizations/index.ts @@ -0,0 +1,38 @@ +/* + * 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 { resolve } from 'path'; +import { Legacy } from '../../../../kibana'; + +// eslint-disable-next-line import/no-default-export +export default function VisualizationsPlugin(kibana: any) { + const config: Legacy.PluginSpecOptions = { + id: 'visualizations', + require: ['data'], + publicDir: resolve(__dirname, 'public'), + config: (Joi: any) => { + return Joi.object({ + enabled: Joi.boolean().default(true), + }).default(); + }, + init: (server: Legacy.Server) => ({}), + }; + + return new kibana.Plugin(config); +} diff --git a/src/legacy/core_plugins/visualizations/package.json b/src/legacy/core_plugins/visualizations/package.json new file mode 100644 index 0000000000000..5b436f0c2fef2 --- /dev/null +++ b/src/legacy/core_plugins/visualizations/package.json @@ -0,0 +1,4 @@ +{ + "name": "visualizations", + "version": "kibana" +} diff --git a/src/legacy/core_plugins/visualizations/public/filters/filters_service.ts b/src/legacy/core_plugins/visualizations/public/filters/filters_service.ts new file mode 100644 index 0000000000000..60c26d7cbdc1d --- /dev/null +++ b/src/legacy/core_plugins/visualizations/public/filters/filters_service.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. + */ + +// @ts-ignore +import { VisFiltersProvider, createFilter } from 'ui/vis/vis_filters'; + +/** + * Vis Filters Service + * + * @internal + */ +export class FiltersService { + public setup() { + return { + VisFiltersProvider, + createFilter, + }; + } + + public stop() { + // nothing to do here yet + } +} + +/** @public */ +export type FiltersSetup = ReturnType; diff --git a/src/legacy/core_plugins/visualizations/public/filters/index.ts b/src/legacy/core_plugins/visualizations/public/filters/index.ts new file mode 100644 index 0000000000000..591f7c9bc7715 --- /dev/null +++ b/src/legacy/core_plugins/visualizations/public/filters/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 { FiltersService, FiltersSetup } from './filters_service'; diff --git a/src/legacy/core_plugins/visualizations/public/index.ts b/src/legacy/core_plugins/visualizations/public/index.ts new file mode 100644 index 0000000000000..202c2354f89eb --- /dev/null +++ b/src/legacy/core_plugins/visualizations/public/index.ts @@ -0,0 +1,68 @@ +/* + * 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 { FiltersService, FiltersSetup } from './filters'; +import { TypesService, TypesSetup } from './types'; + +class VisualizationsPlugin { + private readonly filters: FiltersService; + private readonly types: TypesService; + + constructor() { + this.filters = new FiltersService(); + this.types = new TypesService(); + } + + public setup() { + return { + filters: this.filters.setup(), + types: this.types.setup(), + }; + } + + public stop() { + this.filters.stop(); + this.types.stop(); + } +} + +/** + * We export visualizations here so that users importing from 'plugins/visualizations' + * will automatically receive the response value of the `setup` contract, mimicking + * the data that will eventually be injected by the new platform. + */ +export const visualizations = new VisualizationsPlugin().setup(); + +/** @public */ +export interface VisualizationsSetup { + filters: FiltersSetup; + types: TypesSetup; +} + +/** @public types */ +export { + Vis, + VisParams, + VisProvider, + VisState, + VisualizationController, + VisType, + VisTypesRegistry, + Status, +} from './types'; diff --git a/src/legacy/core_plugins/visualizations/public/types/index.ts b/src/legacy/core_plugins/visualizations/public/types/index.ts new file mode 100644 index 0000000000000..a7830a8eb9704 --- /dev/null +++ b/src/legacy/core_plugins/visualizations/public/types/index.ts @@ -0,0 +1,32 @@ +/* + * 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 { + TypesService, + // types + TypesSetup, + Vis, + VisParams, + VisProvider, + VisState, + VisualizationController, + VisType, + VisTypesRegistry, + Status, +} from './types_service'; diff --git a/src/legacy/core_plugins/visualizations/public/types/types_service.ts b/src/legacy/core_plugins/visualizations/public/types/types_service.ts new file mode 100644 index 0000000000000..82ab0ceb00baf --- /dev/null +++ b/src/legacy/core_plugins/visualizations/public/types/types_service.ts @@ -0,0 +1,59 @@ +/* + * 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 +import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; +// @ts-ignore +import { VisProvider as Vis } from 'ui/vis/index.js'; +// @ts-ignore +import { VisFactoryProvider as VisFactory } from 'ui/vis/vis_factory'; +import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; + +/** + * Vis Types Service + * + * @internal + */ +export class TypesService { + public setup() { + return { + Vis, + VisFactory, + VisTypesRegistryProvider, + defaultFeedbackMessage, // make default in base vis type, or move? + }; + } + + public stop() { + // nothing to do here yet + } +} + +/** @public */ +export type TypesSetup = ReturnType; + +/** @public types */ +import * as types from 'ui/vis/vis'; +export type Vis = types.Vis; +export type VisParams = types.VisParams; +export type VisProvider = types.VisProvider; +export type VisState = types.VisState; +export { VisualizationController, VisType } from 'ui/vis/vis_types/vis_type'; +export { VisTypesRegistry } from 'ui/registry/vis_types'; +export { Status } from 'ui/vis/update_status'; diff --git a/src/legacy/ui/public/utils/brush_event.js b/src/legacy/ui/public/vis/vis_filters/brush_event.js similarity index 100% rename from src/legacy/ui/public/utils/brush_event.js rename to src/legacy/ui/public/vis/vis_filters/brush_event.js diff --git a/src/legacy/ui/public/utils/__tests__/brush_event.test.js b/src/legacy/ui/public/vis/vis_filters/brush_event.test.js similarity index 99% rename from src/legacy/ui/public/utils/__tests__/brush_event.test.js rename to src/legacy/ui/public/vis/vis_filters/brush_event.test.js index 40e485e26a5e6..af41cfac32bda 100644 --- a/src/legacy/ui/public/utils/__tests__/brush_event.test.js +++ b/src/legacy/ui/public/vis/vis_filters/brush_event.test.js @@ -39,7 +39,7 @@ jest.mock('ui/chrome', import _ from 'lodash'; import moment from 'moment'; import expect from '@kbn/expect'; -import { onBrushEvent } from '../brush_event'; +import { onBrushEvent } from './brush_event'; import { timefilter } from 'ui/timefilter'; describe('brushEvent', () => { diff --git a/src/legacy/ui/public/vis/vis_filters/index.js b/src/legacy/ui/public/vis/vis_filters/index.js new file mode 100644 index 0000000000000..a31749947c6cb --- /dev/null +++ b/src/legacy/ui/public/vis/vis_filters/index.js @@ -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 { VisFiltersProvider, createFilter } from './vis_filters'; diff --git a/src/legacy/ui/public/vis/vis_filters.js b/src/legacy/ui/public/vis/vis_filters/vis_filters.js similarity index 95% rename from src/legacy/ui/public/vis/vis_filters.js rename to src/legacy/ui/public/vis/vis_filters/vis_filters.js index 281c889d72069..b7a62721e118c 100644 --- a/src/legacy/ui/public/vis/vis_filters.js +++ b/src/legacy/ui/public/vis/vis_filters/vis_filters.js @@ -18,9 +18,9 @@ */ import _ from 'lodash'; -import { pushFilterBarFilters } from '../filter_manager/push_filters'; -import { FilterBarQueryFilterProvider } from '../filter_manager/query_filter'; -import { onBrushEvent } from '../utils/brush_event'; +import { pushFilterBarFilters } from '../../filter_manager/push_filters'; +import { FilterBarQueryFilterProvider } from '../../filter_manager/query_filter'; +import { onBrushEvent } from './brush_event'; /** * For terms aggregations on `__other__` buckets, this assembles a list of applicable filter