Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NP] Migrate saved object mappings and migration scripts for Dashboard #63864

Merged
merged 10 commits into from
Apr 22, 2020
1 change: 1 addition & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export {
SavedObjectsMigrationLogger,
SavedObjectsRawDoc,
SavedObjectSanitizedDoc,
SavedObjectUnsanitizedDoc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rudolf I'm going to stop fighting against this export. It's a parameter type of a public core API anyway.

SavedObjectsRepositoryFactory,
SavedObjectsResolveImportErrorsOptions,
SavedObjectsSchema,
Expand Down
5 changes: 3 additions & 2 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1679,8 +1679,6 @@ export interface SavedObjectMigrationContext {
log: SavedObjectsMigrationLogger;
}

// Warning: (ae-forgotten-export) The symbol "SavedObjectUnsanitizedDoc" needs to be exported by the entry point index.d.ts
//
// @public
export type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc;

Expand Down Expand Up @@ -2314,6 +2312,9 @@ export class SavedObjectTypeRegistry {
registerType(type: SavedObjectsType): void;
}

// @public
export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial<Referencable>;

// @public
export type ScopeableRequest = KibanaRequest | LegacyRequest | FakeRequest;

Expand Down
20 changes: 0 additions & 20 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Fs from 'fs';
import { resolve } from 'path';
import { promisify } from 'util';

import { migrations } from './migrations';
import { importApi } from './server/routes/api/import';
import { exportApi } from './server/routes/api/export';
import mappings from './mappings.json';
Expand Down Expand Up @@ -120,23 +119,6 @@ export default function(kibana) {
],

savedObjectsManagement: {
dashboard: {
icon: 'dashboardApp',
defaultSearchField: 'title',
isImportableAndExportable: true,
getTitle(obj) {
return obj.attributes.title;
},
getEditUrl(obj) {
return `/management/kibana/objects/savedDashboards/${encodeURIComponent(obj.id)}`;
},
getInAppUrl(obj) {
return {
path: `/app/kibana#/dashboard/${encodeURIComponent(obj.id)}`,
uiCapabilitiesPath: 'dashboard.show',
};
},
},
url: {
defaultSearchField: 'url',
isImportableAndExportable: true,
Expand Down Expand Up @@ -177,8 +159,6 @@ export default function(kibana) {

mappings,
uiSettingDefaults: getUiSettingDefaults(),

migrations,
},

uiCapabilities: async function() {
Expand Down
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
106 changes: 0 additions & 106 deletions src/legacy/core_plugins/kibana/migrations/migrations.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,28 @@
*/

import { SavedObjectReference } from 'kibana/public';
import { GridData } from '../application';

export interface SavedObjectAttributes {
import { GridData } from '../';

interface SavedObjectAttributes {
kibanaSavedObjectMeta: {
searchSourceJSON: string;
};
}

export interface Doc<Attributes extends SavedObjectAttributes = SavedObjectAttributes> {
interface Doc<Attributes extends SavedObjectAttributes = SavedObjectAttributes> {
references: SavedObjectReference[];
attributes: Attributes;
id: string;
type: string;
}

export interface DocPre700<Attributes extends SavedObjectAttributes = SavedObjectAttributes> {
interface DocPre700<Attributes extends SavedObjectAttributes = SavedObjectAttributes> {
attributes: Attributes;
id: string;
type: string;
}

export interface SavedObjectAttributes {
kibanaSavedObjectMeta: {
searchSourceJSON: string;
};
}

interface DashboardAttributes extends SavedObjectAttributes {
panelsJSON: string;
description: string;
Expand All @@ -55,8 +50,6 @@ interface DashboardAttributes extends SavedObjectAttributes {
optionsJSON?: string;
}

export type DashboardAttributes730ToLatest = DashboardAttributes;

interface DashboardAttributesTo720 extends SavedObjectAttributes {
panelsJSON: string;
description: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@
* under the License.
*/

// @ts-ignore
export { migrations } from './migrations';
export interface GridData {
w: number;
h: number;
x: number;
y: number;
i: string;
}
36 changes: 36 additions & 0 deletions src/plugins/dashboard/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { GridData } from './embeddable/types';
export {
RawSavedDashboardPanel730ToLatest,
DashboardDoc730ToLatest,
DashboardDoc700To720,
DashboardDocPre700,
} from './bwc/types';
export {
SavedDashboardPanelTo60,
SavedDashboardPanel610,
SavedDashboardPanel620,
SavedDashboardPanel630,
SavedDashboardPanel640To720,
SavedDashboardPanel730ToLatest,
} from './types';

export { migratePanelsTo730 } from './migrate_to_730_panels';
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
import { migratePanelsTo730 } from './migrate_to_730_panels';
import {
RawSavedDashboardPanelTo60,
RawSavedDashboardPanel610,
RawSavedDashboardPanel620,
RawSavedDashboardPanel630,
RawSavedDashboardPanel640To720,
DEFAULT_PANEL_WIDTH,
DEFAULT_PANEL_HEIGHT,
SavedDashboardPanelTo60,
SavedDashboardPanel730ToLatest,
} from '../../../../../../plugins/dashboard/public';
RawSavedDashboardPanel610,
RawSavedDashboardPanel620,
} from './bwc/types';
import { SavedDashboardPanelTo60, SavedDashboardPanel730ToLatest } from './types';

test('6.0 migrates uiState, sort, scales, and gridData', async () => {
const uiState = {
Expand Down Expand Up @@ -96,8 +93,8 @@ test('6.0 migration gives default width and height when missing', () => {
},
];
const newPanels = migratePanelsTo730(panels, '8.0.0', true);
expect(newPanels[0].gridData.w).toBe(DEFAULT_PANEL_WIDTH);
expect(newPanels[0].gridData.h).toBe(DEFAULT_PANEL_HEIGHT);
expect(newPanels[0].gridData.w).toBe(24);
expect(newPanels[0].gridData.h).toBe(15);
expect(newPanels[0].version).toBe('8.0.0');
});

Expand Down
Loading