From 332460d197eac810fe6ad0382667e3c51fe9964c Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 24 Mar 2020 21:21:35 +0100 Subject: [PATCH] Move lens saved object setup to Kibana platform --- x-pack/legacy/plugins/lens/index.ts | 19 +----- x-pack/legacy/plugins/lens/mappings.json | 35 ----------- x-pack/plugins/lens/server/plugin.tsx | 2 + x-pack/plugins/lens/server/saved_objects.ts | 65 +++++++++++++++++++++ 4 files changed, 68 insertions(+), 53 deletions(-) delete mode 100644 x-pack/legacy/plugins/lens/mappings.json create mode 100644 x-pack/plugins/lens/server/saved_objects.ts diff --git a/x-pack/legacy/plugins/lens/index.ts b/x-pack/legacy/plugins/lens/index.ts index b1c67fb81ba0..e9a901c58cd9 100644 --- a/x-pack/legacy/plugins/lens/index.ts +++ b/x-pack/legacy/plugins/lens/index.ts @@ -7,12 +7,7 @@ import * as Joi from 'joi'; import { resolve } from 'path'; import { LegacyPluginInitializer } from 'src/legacy/types'; -import mappings from './mappings.json'; -import { - PLUGIN_ID, - getEditPath, - NOT_INTERNATIONALIZED_PRODUCT_NAME, -} from '../../../plugins/lens/common'; +import { PLUGIN_ID, NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../../plugins/lens/common'; export const lens: LegacyPluginInitializer = kibana => { return new kibana.Plugin({ @@ -32,18 +27,6 @@ export const lens: LegacyPluginInitializer = kibana => { visualize: [`plugins/${PLUGIN_ID}/legacy`], embeddableFactories: [`plugins/${PLUGIN_ID}/legacy`], styleSheetPaths: resolve(__dirname, 'public/index.scss'), - mappings, - savedObjectsManagement: { - lens: { - defaultSearchField: 'title', - isImportableAndExportable: true, - getTitle: (obj: { attributes: { title: string } }) => obj.attributes.title, - getInAppUrl: (obj: { id: string }) => ({ - path: getEditPath(obj.id), - uiCapabilitiesPath: 'lens.show', - }), - }, - }, }, config: () => { diff --git a/x-pack/legacy/plugins/lens/mappings.json b/x-pack/legacy/plugins/lens/mappings.json deleted file mode 100644 index 8304cf9c9cb6..000000000000 --- a/x-pack/legacy/plugins/lens/mappings.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "lens": { - "properties": { - "title": { - "type": "text" - }, - "visualizationType": { - "type": "keyword" - }, - "state": { - "type": "flattened" - }, - "expression": { - "index": false, - "type": "keyword" - } - } - }, - "lens-ui-telemetry": { - "properties": { - "name": { - "type": "keyword" - }, - "type": { - "type": "keyword" - }, - "date": { - "type": "date" - }, - "count": { - "type": "integer" - } - } - } -} diff --git a/x-pack/plugins/lens/server/plugin.tsx b/x-pack/plugins/lens/server/plugin.tsx index e805f9f7e0a9..3611658fbbcd 100644 --- a/x-pack/plugins/lens/server/plugin.tsx +++ b/x-pack/plugins/lens/server/plugin.tsx @@ -14,6 +14,7 @@ import { initializeLensTelemetry, scheduleLensTelemetry, } from './usage'; +import { setupSavedObjects } from './saved_objects'; export interface PluginSetupContract { usageCollection?: UsageCollectionSetup; @@ -33,6 +34,7 @@ export class LensServerPlugin implements Plugin<{}, {}, {}, {}> { this.telemetryLogger = initializerContext.logger.get('telemetry'); } setup(core: CoreSetup, plugins: PluginSetupContract) { + setupSavedObjects(core); setupRoutes(core); if (plugins.usageCollection && plugins.taskManager) { registerLensUsageCollector( diff --git a/x-pack/plugins/lens/server/saved_objects.ts b/x-pack/plugins/lens/server/saved_objects.ts new file mode 100644 index 000000000000..42dc750878f4 --- /dev/null +++ b/x-pack/plugins/lens/server/saved_objects.ts @@ -0,0 +1,65 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { CoreSetup } from 'kibana/server'; +import { getEditPath } from '../common'; + +export function setupSavedObjects(core: CoreSetup) { + core.savedObjects.registerType({ + name: 'lens', + hidden: false, + namespaceAgnostic: false, + management: { + icon: 'lensApp', + defaultSearchField: 'title', + importableAndExportable: true, + getTitle: (obj: { attributes: { title: string } }) => obj.attributes.title, + getInAppUrl: (obj: { id: string }) => ({ + path: getEditPath(obj.id), + uiCapabilitiesPath: 'visualize.show', + }), + }, + mappings: { + properties: { + title: { + type: 'text', + }, + visualizationType: { + type: 'keyword', + }, + state: { + type: 'flattened', + }, + expression: { + index: false, + type: 'keyword', + }, + }, + }, + }); + + core.savedObjects.registerType({ + name: 'lens-ui-telemetry', + hidden: false, + namespaceAgnostic: false, + mappings: { + properties: { + name: { + type: 'keyword', + }, + type: { + type: 'keyword', + }, + date: { + type: 'date', + }, + count: { + type: 'integer', + }, + }, + }, + }); +}