Skip to content

Commit

Permalink
Kibana 7.7.0: Chart split orientation is wrong (#67840) (#68101)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
# Conflicts:
#	src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
  • Loading branch information
alexwizp authored Jun 4, 2020
1 parent 3610e9e commit 2139661
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -630,7 +630,7 @@ describe('migration visualization', () => {
{
id: '2',
schema: 'split',
params: { foo: 'bar', row: true },
params: { foo: 'bar' },
},
{
id: '3',
Expand All @@ -655,7 +655,7 @@ describe('migration visualization', () => {
{
id: '2',
schema: 'split',
params: { foo: 'bar', row: true },
params: { foo: 'bar' },
},
];
const tableDoc = generateDoc('table', aggs);
Expand All @@ -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',
Expand All @@ -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);

Expand Down Expand Up @@ -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: {
Expand All @@ -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;

Expand Down Expand Up @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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),
};

0 comments on commit 2139661

Please sign in to comment.