|
17 | 17 | * under the License. |
18 | 18 | */ |
19 | 19 |
|
20 | | -import { SavedObjectMigrationFn } from 'kibana/server'; |
21 | 20 | import { cloneDeep, get, omit, has, flow } from 'lodash'; |
| 21 | + |
| 22 | +import { SavedObjectMigrationFn } from 'kibana/server'; |
| 23 | +import { ChartType } from '../../../vis_type_xy/common/types'; |
22 | 24 | import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common'; |
23 | 25 |
|
24 | 26 | const migrateIndexPattern: SavedObjectMigrationFn<any, any> = (doc) => { |
@@ -750,6 +752,39 @@ const removeTSVBSearchSource: SavedObjectMigrationFn<any, any> = (doc) => { |
750 | 752 | return doc; |
751 | 753 | }; |
752 | 754 |
|
| 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 | + |
753 | 788 | export const visualizationSavedObjectTypeMigrations = { |
754 | 789 | /** |
755 | 790 | * 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 = { |
781 | 816 | '7.4.2': flow(transformSplitFiltersStringToQueryObject), |
782 | 817 | '7.7.0': flow(migrateOperatorKeyTypo, migrateSplitByChartRow), |
783 | 818 | '7.8.0': flow(migrateTsvbDefaultColorPalettes), |
784 | | - '7.10.0': flow(migrateFilterRatioQuery, removeTSVBSearchSource), |
| 819 | + '7.10.0': flow(migrateFilterRatioQuery, removeTSVBSearchSource, migrateVislibAreaLineBarTypes), |
785 | 820 | }; |
0 commit comments