Skip to content

Commit 41723e8

Browse files
committed
Add vis migration to add properties for vislib replacement
1 parent 7440a85 commit 41723e8

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/plugins/visualizations/server/saved_objects/visualization_migrations.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
* under the License.
1818
*/
1919

20-
import { SavedObjectMigrationFn } from 'kibana/server';
2120
import { cloneDeep, get, omit, has, flow } from 'lodash';
21+
22+
import { SavedObjectMigrationFn } from 'kibana/server';
23+
import { ChartType } from '../../../vis_type_xy/common/types';
2224
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';
2325

2426
const migrateIndexPattern: SavedObjectMigrationFn<any, any> = (doc) => {
@@ -750,6 +752,39 @@ const removeTSVBSearchSource: SavedObjectMigrationFn<any, any> = (doc) => {
750752
return doc;
751753
};
752754

755+
/**
756+
* Migrate vislib bar, line and area charts to use new vis_type_xy plugin
757+
*/
758+
const migrateVislibAreaLineBarTypes: SavedObjectMigrationFn<any, any> = (doc) => {
759+
const visStateJSON = get(doc, 'attributes.visState');
760+
let visState;
761+
762+
if (visStateJSON) {
763+
try {
764+
visState = JSON.parse(visStateJSON);
765+
} catch (e) {
766+
// Let it go, the data is invalid and we'll leave it as is
767+
}
768+
if (visState && [ChartType.Area, ChartType.Line, ChartType.Histogram].includes(visState.type)) {
769+
return {
770+
...doc,
771+
attributes: {
772+
...doc.attributes,
773+
visState: JSON.stringify({
774+
...visState,
775+
params: {
776+
...visState.params,
777+
isVislibVis: true,
778+
detailedTooltip: false,
779+
},
780+
}),
781+
},
782+
};
783+
}
784+
}
785+
return doc;
786+
};
787+
753788
export const visualizationSavedObjectTypeMigrations = {
754789
/**
755790
* We need to have this migration twice, once with a version prior to 7.0.0 once with a version
@@ -781,5 +816,5 @@ export const visualizationSavedObjectTypeMigrations = {
781816
'7.4.2': flow(transformSplitFiltersStringToQueryObject),
782817
'7.7.0': flow(migrateOperatorKeyTypo, migrateSplitByChartRow),
783818
'7.8.0': flow(migrateTsvbDefaultColorPalettes),
784-
'7.10.0': flow(migrateFilterRatioQuery, removeTSVBSearchSource),
819+
'7.10.0': flow(migrateFilterRatioQuery, removeTSVBSearchSource, migrateVislibAreaLineBarTypes),
785820
};

0 commit comments

Comments
 (0)