mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> # Conflicts: # src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
This commit is contained in:
parent
3610e9ea4c
commit
21396610a3
2 changed files with 84 additions and 14 deletions
|
@ -597,12 +597,12 @@ describe('migration visualization', () => {
|
|||
{
|
||||
id: '2',
|
||||
schema: 'split',
|
||||
params: { foo: 'bar', row: true },
|
||||
params: { foo: 'bar' },
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
schema: 'split',
|
||||
params: { hey: 'ya', row: false },
|
||||
params: { hey: 'ya' },
|
||||
},
|
||||
];
|
||||
const tableDoc = generateDoc('table', aggs);
|
||||
|
@ -630,7 +630,7 @@ describe('migration visualization', () => {
|
|||
{
|
||||
id: '2',
|
||||
schema: 'split',
|
||||
params: { foo: 'bar', row: true },
|
||||
params: { foo: 'bar' },
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
|
@ -655,7 +655,7 @@ describe('migration visualization', () => {
|
|||
{
|
||||
id: '2',
|
||||
schema: 'split',
|
||||
params: { foo: 'bar', row: true },
|
||||
params: { foo: 'bar' },
|
||||
},
|
||||
];
|
||||
const tableDoc = generateDoc('table', aggs);
|
||||
|
@ -675,12 +675,12 @@ describe('migration visualization', () => {
|
|||
{
|
||||
id: '2',
|
||||
schema: 'split',
|
||||
params: { foo: 'bar', row: true },
|
||||
params: { foo: 'bar' },
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
schema: 'split',
|
||||
params: { hey: 'ya', row: false },
|
||||
params: { hey: 'ya' },
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
|
@ -705,15 +705,15 @@ describe('migration visualization', () => {
|
|||
{
|
||||
id: '2',
|
||||
schema: 'split',
|
||||
params: { foo: 'bar', row: true },
|
||||
params: { foo: 'bar' },
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
schema: 'split',
|
||||
params: { hey: 'ya', row: false },
|
||||
params: { hey: 'ya' },
|
||||
},
|
||||
];
|
||||
const expected = [{}, { foo: 'bar', row: true }, { hey: 'ya' }];
|
||||
const expected = [{}, { foo: 'bar' }, { hey: 'ya' }];
|
||||
const migrated = migrate(generateDoc('table', aggs));
|
||||
const actual = JSON.parse(migrated.attributes.visState);
|
||||
|
||||
|
@ -1360,11 +1360,11 @@ describe('migration visualization', () => {
|
|||
doc as Parameters<SavedObjectMigrationFn>[0],
|
||||
savedObjectMigrationContext
|
||||
);
|
||||
const generateDoc = (params: any) => ({
|
||||
const generateDoc = (visState: any) => ({
|
||||
attributes: {
|
||||
title: 'My Vis',
|
||||
description: 'This is my super cool vis.',
|
||||
visState: JSON.stringify({ params }),
|
||||
visState: JSON.stringify(visState),
|
||||
uiStateJSON: '{}',
|
||||
version: 1,
|
||||
kibanaSavedObjectMeta: {
|
||||
|
@ -1390,7 +1390,7 @@ describe('migration visualization', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
const timeSeriesDoc = generateDoc(params);
|
||||
const timeSeriesDoc = generateDoc({ params });
|
||||
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
|
||||
const migratedParams = JSON.parse(migratedtimeSeriesDoc.attributes.visState).params;
|
||||
|
||||
|
@ -1427,11 +1427,37 @@ describe('migration visualization', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
const timeSeriesDoc = generateDoc(params);
|
||||
const timeSeriesDoc = generateDoc({ params });
|
||||
const migratedtimeSeriesDoc = migrate(timeSeriesDoc);
|
||||
const migratedParams = JSON.parse(migratedtimeSeriesDoc.attributes.visState).params;
|
||||
|
||||
expect(migratedParams.gauge_color_rules[1]).toEqual(params.gauge_color_rules[1]);
|
||||
});
|
||||
|
||||
it('should move "row" field on split chart by a row or column to vis.params', () => {
|
||||
const visData = {
|
||||
type: 'area',
|
||||
aggs: [
|
||||
{
|
||||
id: '1',
|
||||
schema: 'metric',
|
||||
params: {},
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'terms',
|
||||
schema: 'split',
|
||||
params: { foo: 'bar', row: true },
|
||||
},
|
||||
],
|
||||
params: {},
|
||||
};
|
||||
|
||||
const migrated = migrate(generateDoc(visData));
|
||||
const actual = JSON.parse(migrated.attributes.visState);
|
||||
|
||||
expect(actual.aggs.filter((agg: any) => 'row' in agg.params)).toEqual([]);
|
||||
expect(actual.params.row).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -130,6 +130,50 @@ const migrateOperatorKeyTypo: SavedObjectMigrationFn = (doc) => {
|
|||
return doc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Moving setting wether to do a row or column split to vis.params
|
||||
*
|
||||
* @see https://github.com/elastic/kibana/pull/58462/files#diff-ae69fe15b20a5099d038e9bbe2ed3849
|
||||
**/
|
||||
const migrateSplitByChartRow: SavedObjectMigrationFn = (doc) => {
|
||||
const visStateJSON = get<string>(doc, 'attributes.visState');
|
||||
let visState: any;
|
||||
|
||||
if (visStateJSON) {
|
||||
try {
|
||||
visState = JSON.parse(visStateJSON);
|
||||
} catch (e) {
|
||||
// Let it go, the data is invalid and we'll leave it as is
|
||||
}
|
||||
|
||||
if (visState && visState.aggs && visState.params) {
|
||||
let row: boolean | undefined;
|
||||
|
||||
visState.aggs.forEach((agg: any) => {
|
||||
if (agg.type === 'terms' && agg.schema === 'split' && 'row' in agg.params) {
|
||||
row = agg.params.row;
|
||||
|
||||
delete agg.params.row;
|
||||
}
|
||||
});
|
||||
|
||||
if (row !== undefined) {
|
||||
visState.params.row = row;
|
||||
}
|
||||
|
||||
return {
|
||||
...doc,
|
||||
attributes: {
|
||||
...doc.attributes,
|
||||
visState: JSON.stringify(visState),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
// Migrate date histogram aggregation (remove customInterval)
|
||||
const migrateDateHistogramAggregation: SavedObjectMigrationFn = (doc) => {
|
||||
const visStateJSON = get<string>(doc, 'attributes.visState');
|
||||
|
@ -603,5 +647,5 @@ export const visualizationSavedObjectTypeMigrations = {
|
|||
),
|
||||
'7.3.1': flow<SavedObjectMigrationFn>(migrateFiltersAggQueryStringQueries),
|
||||
'7.4.2': flow<SavedObjectMigrationFn>(transformSplitFiltersStringToQueryObject),
|
||||
'7.7.0': flow<SavedObjectMigrationFn>(migrateOperatorKeyTypo),
|
||||
'7.7.0': flow<SavedObjectMigrationFn>(migrateOperatorKeyTypo, migrateSplitByChartRow),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue