File tree Expand file tree Collapse file tree 8 files changed +101
-71
lines changed Expand file tree Collapse file tree 8 files changed +101
-71
lines changed Original file line number Diff line number Diff line change 77import { resolve } from 'path' ;
88import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils' ;
99import { init } from './init' ;
10- import { mappings } from './server/mappings' ;
1110import { CANVAS_APP , CANVAS_TYPE , CUSTOM_ELEMENT_TYPE } from './common/lib' ;
12- import { migrations } from './migrations' ;
1311
1412export function canvas ( kibana ) {
1513 return new kibana . Plugin ( {
@@ -33,8 +31,6 @@ export function canvas(kibana) {
3331 'plugins/canvas/lib/window_error_handler.js' ,
3432 ] ,
3533 home : [ 'plugins/canvas/legacy_register_feature' ] ,
36- mappings,
37- migrations,
3834 savedObjectsManagement : {
3935 [ CANVAS_TYPE ] : {
4036 icon : 'canvasApp' ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { initRoutes } from './routes';
1414import { registerCanvasUsageCollector } from './collectors' ;
1515import { loadSampleData } from './sample_data' ;
1616import { setupInterpreter } from './setup_interpreter' ;
17+ import { customElementType , workpadType } from './saved_objects' ;
1718
1819interface PluginsSetup {
1920 expressions : ExpressionsServerSetup ;
@@ -29,6 +30,9 @@ export class CanvasPlugin implements Plugin {
2930 }
3031
3132 public async setup ( coreSetup : CoreSetup , plugins : PluginsSetup ) {
33+ coreSetup . savedObjects . registerType ( customElementType ) ;
34+ coreSetup . savedObjects . registerType ( workpadType ) ;
35+
3236 plugins . features . registerFeature ( {
3337 id : 'canvas' ,
3438 name : 'Canvas' ,
Original file line number Diff line number Diff line change 44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- // @ts -ignore converting /libs/constants to TS breaks CI
8- import { CANVAS_TYPE , CUSTOM_ELEMENT_TYPE } from '../common/lib/constants' ;
7+ import { SavedObjectsType } from 'src/core/server' ;
8+ import { CUSTOM_ELEMENT_TYPE } from '../../../../legacy/plugins/canvas /common/lib/constants' ;
99
10- export const mappings = {
11- [ CANVAS_TYPE ] : {
12- dynamic : false ,
13- properties : {
14- name : {
15- type : 'text' ,
16- fields : {
17- keyword : {
18- type : 'keyword' ,
19- } ,
20- } ,
21- } ,
22- '@timestamp' : { type : 'date' } ,
23- '@created' : { type : 'date' } ,
24- } ,
25- } ,
26- [ CUSTOM_ELEMENT_TYPE ] : {
10+ export const customElementType : SavedObjectsType = {
11+ name : CUSTOM_ELEMENT_TYPE ,
12+ hidden : false ,
13+ namespaceType : 'single' ,
14+ mappings : {
2715 dynamic : false ,
2816 properties : {
2917 name : {
@@ -41,4 +29,5 @@ export const mappings = {
4129 '@created' : { type : 'date' } ,
4230 } ,
4331 } ,
32+ migrations : { } ,
4433} ;
Original file line number Diff line number Diff line change 44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import { CANVAS_TYPE } from './common/lib' ;
7+ import { workpadType } from './workpad' ;
8+ import { customElementType } from './custom_element' ;
89
9- export const migrations = {
10- [ CANVAS_TYPE ] : {
11- '7.0.0' : doc => {
12- if ( doc . attributes ) {
13- delete doc . attributes . id ;
14- }
15- return doc ;
16- } ,
17- } ,
18- } ;
10+ export { customElementType , workpadType } ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+ * or more contributor license agreements. Licensed under the Elastic License;
4+ * you may not use this file except in compliance with the Elastic License.
5+ */
6+
7+ import { removeAttributesId } from './remove_attributes_id' ;
8+
9+ const context : any = {
10+ log : jest . fn ( ) ,
11+ } ;
12+
13+ describe ( `removeAttributesId` , ( ) => {
14+ it ( 'does not throw error on empty object' , ( ) => {
15+ const migratedDoc = removeAttributesId ( { } as any , context ) ;
16+ expect ( migratedDoc ) . toMatchInlineSnapshot ( `Object {}` ) ;
17+ } ) ;
18+
19+ it ( 'removes id from "attributes"' , ( ) => {
20+ const migratedDoc = removeAttributesId (
21+ {
22+ foo : true ,
23+ attributes : {
24+ id : '123' ,
25+ bar : true ,
26+ } ,
27+ } as any ,
28+ context
29+ ) ;
30+ expect ( migratedDoc ) . toMatchInlineSnapshot ( `
31+ Object {
32+ "attributes": Object {
33+ "bar": true,
34+ },
35+ "foo": true,
36+ }
37+ ` ) ;
38+ } ) ;
39+ } ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+ * or more contributor license agreements. Licensed under the Elastic License;
4+ * you may not use this file except in compliance with the Elastic License.
5+ */
6+
7+ import { SavedObjectMigrationFn } from 'src/core/server' ;
8+
9+ export const removeAttributesId : SavedObjectMigrationFn = doc => {
10+ if ( typeof doc . attributes === 'object' && doc . attributes !== null ) {
11+ delete ( doc . attributes as any ) . id ;
12+ }
13+ return doc ;
14+ } ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+ * or more contributor license agreements. Licensed under the Elastic License;
4+ * you may not use this file except in compliance with the Elastic License.
5+ */
6+
7+ import { SavedObjectsType } from 'src/core/server' ;
8+ import { CANVAS_TYPE } from '../../../../legacy/plugins/canvas/common/lib/constants' ;
9+ import { removeAttributesId } from './migrations/remove_attributes_id' ;
10+
11+ export const workpadType : SavedObjectsType = {
12+ name : CANVAS_TYPE ,
13+ hidden : false ,
14+ namespaceType : 'single' ,
15+ mappings : {
16+ dynamic : false ,
17+ properties : {
18+ name : {
19+ type : 'text' ,
20+ fields : {
21+ keyword : {
22+ type : 'keyword' ,
23+ } ,
24+ } ,
25+ } ,
26+ '@timestamp' : { type : 'date' } ,
27+ '@created' : { type : 'date' } ,
28+ } ,
29+ } ,
30+ migrations : {
31+ '7.0.0' : removeAttributesId ,
32+ } ,
33+ } ;
You can’t perform that action at this time.
0 commit comments