Move lens saved object setup to Kibana platform (#61157)

This commit is contained in:
Tim Roes 2020-03-25 17:56:49 +01:00 committed by GitHub
parent 11bcfae3a7
commit b8e3ccb356
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 53 deletions

View file

@ -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: () => {

View file

@ -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"
}
}
}
}

View file

@ -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<PluginStartContract>, plugins: PluginSetupContract) {
setupSavedObjects(core);
setupRoutes(core);
if (plugins.usageCollection && plugins.taskManager) {
registerLensUsageCollector(

View file

@ -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',
},
},
},
});
}