Skip to content

Commit

Permalink
Migrate saved objects
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-lapata committed Apr 12, 2020
1 parent d662cb5 commit fb5b543
Show file tree
Hide file tree
Showing 9 changed files with 2,299 additions and 55 deletions.
54 changes: 0 additions & 54 deletions src/legacy/core_plugins/kibana/mappings.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
{
"dashboard": {
"properties": {
"description": {
"type": "text"
},
"hits": {
"type": "integer"
},
"kibanaSavedObjectMeta": {
"properties": {
"searchSourceJSON": {
"type": "text"
}
}
},
"optionsJSON": {
"type": "text"
},
"panelsJSON": {
"type": "text"
},
"refreshInterval": {
"properties": {
"display": {
"type": "keyword"
},
"pause": {
"type": "boolean"
},
"section": {
"type": "integer"
},
"value": {
"type": "integer"
}
}
},
"timeFrom": {
"type": "keyword"
},
"timeRestore": {
"type": "boolean"
},
"timeTo": {
"type": "keyword"
},
"title": {
"type": "text"
},
"version": {
"type": "integer"
}
}
},
"url": {
"properties": {
"accessCount": {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"savedObjects"
],
"optionalPlugins": ["home", "share", "usageCollection"],
"server": false,
"server": true,
"ui": true
}
30 changes: 30 additions & 0 deletions src/plugins/dashboard/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { PluginInitializerContext } from '../../../core/server';
import { DashboardPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, Kibana Platform `plugin()` initializer.

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

export { DashboardPluginSetup, DashboardPluginStart } from './types';
53 changes: 53 additions & 0 deletions src/plugins/dashboard/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
Logger,
} from '../../../core/server';

import { dashboardSavedObjectType } from './saved_objects';

import { DashboardPluginSetup, DashboardPluginStart } from './types';

export class DashboardPlugin implements Plugin<DashboardPluginSetup, DashboardPluginStart> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup) {
this.logger.debug('dashboard: Setup');

core.savedObjects.registerType(dashboardSavedObjectType);

return {};
}

public start(core: CoreStart) {
this.logger.debug('dashboard: Started');
return {};
}

public stop() {}
}
67 changes: 67 additions & 0 deletions src/plugins/dashboard/server/saved_objects/dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 { SavedObjectsType } from 'kibana/server';
import { dashboardSavedObjectTypeMigrations } from './dashboard_migrations';

export const dashboardSavedObjectType: SavedObjectsType = {
name: 'dashboard',
hidden: false,
namespaceAgnostic: false,
management: {
icon: 'dashboardApp',
defaultSearchField: 'title',
importableAndExportable: true,
getTitle(obj) {
return obj.attributes.title;
},
getEditUrl(obj) {
return `/management/kibana/objects/savedVisualizations/${encodeURIComponent(obj.id)}`;
},
getInAppUrl(obj) {
return {
path: `/app/kibana#/visualize/edit/${encodeURIComponent(obj.id)}`,
uiCapabilitiesPath: 'visualize.show',
};
},
},
mappings: {
properties: {
description: { type: 'text' },
hits: { type: 'integer' },
kibanaSavedObjectMeta: { properties: { searchSourceJSON: { type: 'text' } } },
optionsJSON: { type: 'text' },
panelsJSON: { type: 'text' },
refreshInterval: {
properties: {
display: { type: 'keyword' },
pause: { type: 'boolean' },
section: { type: 'integer' },
value: { type: 'integer' },
},
},
timeFrom: { type: 'keyword' },
timeRestore: { type: 'boolean' },
timeTo: { type: 'keyword' },
title: { type: 'text' },
version: { type: 'integer' },
},
},
migrations: dashboardSavedObjectTypeMigrations,
};
Loading

0 comments on commit fb5b543

Please sign in to comment.