Skip to content

Commit

Permalink
[NP] Migrate saved object mappings and migration scripts for Dashboard (
Browse files Browse the repository at this point in the history
#63864) (#64194)

* Migrate saved objects

* Move common used types and fucntions to dashboard/common

* Fix unit tests

* Update server.api.md

* Fix TS

* Update i18n IDs

* Update TS

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
maryia-lapata and elasticmachine authored Apr 23, 2020
1 parent c64c8ac commit 949f94b
Show file tree
Hide file tree
Showing 34 changed files with 437 additions and 394 deletions.
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,
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 @@ -174,8 +156,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

0 comments on commit 949f94b

Please sign in to comment.