mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Lens] Introduce separate dimension groups for mosaic rows and columns (#139214)
* [Lens] Introduce separate dimension groups for mosaic rows and columns * swap labels * fix nits Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
This commit is contained in:
parent
c771828242
commit
6ed79f42db
22 changed files with 297 additions and 70 deletions
|
@ -29,6 +29,7 @@ import {
|
|||
getLensFilterMigrations,
|
||||
getLensDataViewMigrations,
|
||||
commonMigrateMetricIds,
|
||||
commonMigratePartitionChartGroups,
|
||||
} from '../migrations/common_migrations';
|
||||
import {
|
||||
CustomVisualizationMigrations,
|
||||
|
@ -134,7 +135,13 @@ export const makeLensEmbeddableFactory =
|
|||
},
|
||||
'8.5.0': (state) => {
|
||||
const lensState = state as unknown as { attributes: LensDocShape840<VisState840> };
|
||||
const migratedLensState = commonMigrateMetricIds(lensState.attributes);
|
||||
let migratedLensState = commonMigrateMetricIds(lensState.attributes);
|
||||
migratedLensState = commonMigratePartitionChartGroups(
|
||||
migratedLensState as LensDocShape840<{
|
||||
shape: string;
|
||||
layers: Array<{ groups?: string[] }>;
|
||||
}>
|
||||
);
|
||||
return {
|
||||
...lensState,
|
||||
attributes: migratedLensState,
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
|
||||
import { DataViewSpec } from '@kbn/data-views-plugin/common';
|
||||
import { Filter } from '@kbn/es-query';
|
||||
import { getLensDataViewMigrations, getLensFilterMigrations } from './common_migrations';
|
||||
import {
|
||||
getLensDataViewMigrations,
|
||||
getLensFilterMigrations,
|
||||
commonMigratePartitionChartGroups,
|
||||
} from './common_migrations';
|
||||
import { LensDocShape840 } from '..';
|
||||
|
||||
describe('Lens migrations', () => {
|
||||
describe('applying filter migrations', () => {
|
||||
|
@ -106,4 +111,62 @@ describe('Lens migrations', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('migrate partition chart "groups" to new shape', () => {
|
||||
['donut', 'pie', 'treemap', 'mosaic', 'waffle'].forEach((chartType: string) => {
|
||||
it(`should migrate "group" to "primaryGroups" for "${chartType}" chart`, () => {
|
||||
const lensVisualizationSavedObject = {
|
||||
attributes: {
|
||||
state: {
|
||||
visualization: {
|
||||
shape: chartType,
|
||||
layers: [{ groups: ['a'] }],
|
||||
},
|
||||
},
|
||||
} as LensDocShape840<{
|
||||
shape: string;
|
||||
layers: Array<{ groups?: string[] }>;
|
||||
}>,
|
||||
};
|
||||
|
||||
const migratedVisualization = commonMigratePartitionChartGroups(
|
||||
lensVisualizationSavedObject.attributes
|
||||
).state.visualization;
|
||||
|
||||
expect(migratedVisualization.layers[0]).not.toHaveProperty('groups');
|
||||
expect(migratedVisualization.layers[0]).toHaveProperty('primaryGroups', ['a']);
|
||||
});
|
||||
});
|
||||
|
||||
it(`should migrate "group" to "primaryGroups" and "secondaryGroups" for mosaic`, () => {
|
||||
const lensVisualizationSavedObject = {
|
||||
attributes: {
|
||||
state: {
|
||||
visualization: {
|
||||
shape: 'mosaic',
|
||||
layers: [{ groups: ['a', 'b'] }],
|
||||
},
|
||||
},
|
||||
} as LensDocShape840<{
|
||||
shape: string;
|
||||
layers: Array<{ groups?: string[] }>;
|
||||
}>,
|
||||
};
|
||||
|
||||
const migratedVisualization = commonMigratePartitionChartGroups(
|
||||
lensVisualizationSavedObject.attributes
|
||||
).state.visualization;
|
||||
|
||||
expect(migratedVisualization.layers[0]).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"primaryGroups": Array [
|
||||
"a",
|
||||
],
|
||||
"secondaryGroups": Array [
|
||||
"b",
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,8 +31,9 @@ import {
|
|||
LensDocShape830,
|
||||
VisStatePre830,
|
||||
LensDocShape840,
|
||||
LensDocShape850,
|
||||
} from './types';
|
||||
import { DOCUMENT_FIELD_NAME, layerTypes, LegacyMetricState } from '../../common';
|
||||
import { DOCUMENT_FIELD_NAME, layerTypes, LegacyMetricState, isPartitionShape } from '../../common';
|
||||
import { LensDocShape } from './saved_object_migrations';
|
||||
|
||||
export const commonRenameOperationsForFormula = (
|
||||
|
@ -438,3 +439,51 @@ export const commonMigrateMetricIds = (
|
|||
|
||||
return newAttributes;
|
||||
};
|
||||
|
||||
export const commonMigratePartitionChartGroups = (
|
||||
attributes: LensDocShape840<{
|
||||
shape: string;
|
||||
layers: Array<{ groups?: string[] }>;
|
||||
}>
|
||||
): LensDocShape850<{
|
||||
shape: string;
|
||||
layers: Array<{ primaryGroups?: string[]; secondaryGroups?: string[] }>;
|
||||
}> => {
|
||||
if (
|
||||
attributes.state.visualization?.layers &&
|
||||
isPartitionShape(attributes.state.visualization.shape)
|
||||
) {
|
||||
return {
|
||||
...attributes,
|
||||
state: {
|
||||
...attributes.state,
|
||||
visualization: {
|
||||
...attributes.state.visualization,
|
||||
layers: attributes.state.visualization.layers.map((l) => {
|
||||
const groups = l.groups;
|
||||
|
||||
if (groups) {
|
||||
delete l.groups;
|
||||
if (attributes.state.visualization.shape === 'mosaic') {
|
||||
return {
|
||||
...l,
|
||||
primaryGroups: [groups[0]],
|
||||
secondaryGroups: groups.length === 2 ? [groups[1]] : undefined,
|
||||
};
|
||||
}
|
||||
return {
|
||||
...l,
|
||||
primaryGroups: groups,
|
||||
};
|
||||
}
|
||||
return l;
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return attributes as LensDocShape850<{
|
||||
shape: string;
|
||||
layers: Array<{ primaryGroups?: string[]; secondaryGroups?: string[] }>;
|
||||
}>;
|
||||
};
|
||||
|
|
|
@ -54,6 +54,7 @@ import {
|
|||
commonPreserveOldLegendSizeDefault,
|
||||
getLensDataViewMigrations,
|
||||
commonMigrateMetricIds,
|
||||
commonMigratePartitionChartGroups,
|
||||
} from './common_migrations';
|
||||
|
||||
interface LensDocShapePre710<VisualizationState = unknown> {
|
||||
|
@ -520,6 +521,18 @@ const migrateMetricIds: SavedObjectMigrationFn<LensDocShape840, LensDocShape840>
|
|||
attributes: commonMigrateMetricIds(doc.attributes),
|
||||
});
|
||||
|
||||
const migratePartitionChartGroups: SavedObjectMigrationFn<LensDocShape840, LensDocShape840> = (
|
||||
doc
|
||||
) => ({
|
||||
...doc,
|
||||
attributes: commonMigratePartitionChartGroups(
|
||||
doc.attributes as LensDocShape840<{
|
||||
shape: string;
|
||||
layers: Array<{ groups?: string[] }>;
|
||||
}>
|
||||
),
|
||||
});
|
||||
|
||||
const lensMigrations: SavedObjectMigrationMap = {
|
||||
'7.7.0': removeInvalidAccessors,
|
||||
// The order of these migrations matter, since the timefield migration relies on the aggConfigs
|
||||
|
@ -540,7 +553,7 @@ const lensMigrations: SavedObjectMigrationMap = {
|
|||
enhanceTableRowHeight
|
||||
),
|
||||
'8.3.0': flow(lockOldMetricVisSettings, preserveOldLegendSizeDefault, fixValueLabelsInXY),
|
||||
'8.5.0': flow(migrateMetricIds),
|
||||
'8.5.0': flow(migrateMetricIds, migratePartitionChartGroups),
|
||||
};
|
||||
|
||||
export const getAllMigrations = (
|
||||
|
|
|
@ -272,3 +272,5 @@ export type VisState830 = XYVisualizationState830;
|
|||
|
||||
export type VisState840 = VisState830;
|
||||
export type LensDocShape840<VisualizationState = unknown> = LensDocShape830<VisualizationState>;
|
||||
|
||||
export type LensDocShape850<VisualizationState = unknown> = LensDocShape840<VisualizationState>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue