Skip to content

Commit

Permalink
Kibana 7.7.0: Chart split orientation is wrong (#67840)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
alexwizp and elasticmachine authored Jun 3, 2020
1 parent c718afc commit d7b830a
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 @@ -623,12 +623,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 @@ -656,7 +656,7 @@ describe('migration visualization', () => {
{
id: '2',
schema: 'split',
params: { foo: 'bar', row: true },
params: { foo: 'bar' },
},
{
id: '3',
Expand All @@ -681,7 +681,7 @@ describe('migration visualization', () => {
{
id: '2',
schema: 'split',
params: { foo: 'bar', row: true },
params: { foo: 'bar' },
},
];
const tableDoc = generateDoc('table', aggs);
Expand All @@ -701,12 +701,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 @@ -731,15 +731,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 @@ -1386,11 +1386,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 @@ -1416,7 +1416,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 @@ -1453,12 +1453,38 @@ 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();
});
});

describe('7.8.0 tsvb split_color_mode', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,50 @@ const migrateOperatorKeyTypo: SavedObjectMigrationFn<any, any> = (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<any, any> = (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<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
Expand Down Expand Up @@ -673,6 +717,6 @@ export const visualizationSavedObjectTypeMigrations = {
),
'7.3.1': flow<SavedObjectMigrationFn<any, any>>(migrateFiltersAggQueryStringQueries),
'7.4.2': flow<SavedObjectMigrationFn<any, any>>(transformSplitFiltersStringToQueryObject),
'7.7.0': flow<SavedObjectMigrationFn<any, any>>(migrateOperatorKeyTypo),
'7.7.0': flow<SavedObjectMigrationFn<any, any>>(migrateOperatorKeyTypo, migrateSplitByChartRow),
'7.8.0': flow<SavedObjectMigrationFn<any, any>>(migrateTsvbDefaultColorPalettes),
};

0 comments on commit d7b830a

Please sign in to comment.