mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Lens] Multi metric partition charts (#143966)
This commit is contained in:
parent
3190eddd5c
commit
e2d3bb9dec
67 changed files with 2533 additions and 743 deletions
|
@ -32,6 +32,7 @@ import {
|
|||
getLensDataViewMigrations,
|
||||
commonMigrateMetricIds,
|
||||
commonMigratePartitionChartGroups,
|
||||
commonMigratePartitionMetrics,
|
||||
commonMigrateIndexPatternDatasource,
|
||||
} from '../migrations/common_migrations';
|
||||
import {
|
||||
|
@ -160,12 +161,15 @@ export const makeLensEmbeddableFactory =
|
|||
'8.6.0': (state) => {
|
||||
const lensState = state as unknown as SavedObject<LensDocShape850<VisState850>>;
|
||||
|
||||
const migratedLensState = commonMigrateIndexPatternDatasource(lensState.attributes);
|
||||
let migratedLensState = commonMigrateIndexPatternDatasource(lensState.attributes);
|
||||
migratedLensState = commonMigratePartitionMetrics(migratedLensState);
|
||||
return {
|
||||
...lensState,
|
||||
attributes: migratedLensState,
|
||||
} as unknown as SerializableRecord;
|
||||
},
|
||||
// FOLLOW THESE GUIDELINES IF YOU ARE ADDING A NEW MIGRATION!
|
||||
// 1. Make sure you are applying migrations for a given version in the same order here as they are applied in x-pack/plugins/lens/server/migrations/saved_object_migrations.ts
|
||||
}),
|
||||
getLensCustomVisualizationMigrations(customVisualizationMigrations)
|
||||
),
|
||||
|
|
|
@ -541,3 +541,32 @@ export const commonMigratePartitionChartGroups = (
|
|||
layers: Array<{ primaryGroups?: string[]; secondaryGroups?: string[] }>;
|
||||
}>;
|
||||
};
|
||||
|
||||
export const commonMigratePartitionMetrics = (attributes: LensDocShape860<unknown>) => {
|
||||
if (attributes.visualizationType !== 'lnsPie') {
|
||||
return attributes as LensDocShape860<unknown>;
|
||||
}
|
||||
|
||||
const partitionAttributes = attributes as LensDocShape860<{
|
||||
shape: string;
|
||||
layers: Array<{ metric: string }>;
|
||||
}>;
|
||||
|
||||
return {
|
||||
...attributes,
|
||||
state: {
|
||||
...attributes.state,
|
||||
visualization: {
|
||||
...partitionAttributes.state.visualization,
|
||||
layers: partitionAttributes.state.visualization.layers.map((layer) => ({
|
||||
...layer,
|
||||
metrics: [layer.metric],
|
||||
metric: undefined,
|
||||
})),
|
||||
},
|
||||
},
|
||||
} as LensDocShape860<{
|
||||
shape: string;
|
||||
layers: Array<{ metrics: string[] }>;
|
||||
}>;
|
||||
};
|
||||
|
|
|
@ -2364,6 +2364,49 @@ describe('Lens migrations', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('8.6.0 migrates partition metrics', () => {
|
||||
const context = { log: { warn: () => {} } } as unknown as SavedObjectMigrationContext;
|
||||
const example = {
|
||||
type: 'lens',
|
||||
id: 'mocked-saved-object-id',
|
||||
attributes: {
|
||||
savedObjectId: '1',
|
||||
title: 'some title',
|
||||
description: '',
|
||||
visualizationType: 'lnsPie',
|
||||
state: {
|
||||
visualization: {
|
||||
layers: [
|
||||
{
|
||||
metric: 'some-metric',
|
||||
},
|
||||
],
|
||||
},
|
||||
datasourceStates: {
|
||||
indexpattern: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as SavedObjectUnsanitizedDoc<LensDocShape810>;
|
||||
|
||||
it('make metric an array', () => {
|
||||
const result = migrations['8.6.0'](example, context) as ReturnType<
|
||||
SavedObjectMigrationFn<LensDocShape, LensDocShape>
|
||||
>;
|
||||
expect(
|
||||
(result.attributes.state.visualization as { layers: Array<{ metrics: string[] }> })
|
||||
.layers[0]
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"metric": undefined,
|
||||
"metrics": Array [
|
||||
"some-metric",
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('8.6.0 migrates indexpattern datasource', () => {
|
||||
const context = { log: { warn: () => {} } } as unknown as SavedObjectMigrationContext;
|
||||
const example = {
|
||||
|
|
|
@ -60,6 +60,7 @@ import {
|
|||
getLensDataViewMigrations,
|
||||
commonMigrateMetricIds,
|
||||
commonMigratePartitionChartGroups,
|
||||
commonMigratePartitionMetrics,
|
||||
commonMigrateIndexPatternDatasource,
|
||||
} from './common_migrations';
|
||||
|
||||
|
@ -554,6 +555,13 @@ const migratePartitionChartGroups: SavedObjectMigrationFn<LensDocShape840, LensD
|
|||
),
|
||||
});
|
||||
|
||||
const migratePartitionMetrics: SavedObjectMigrationFn<LensDocShape860, LensDocShape860> = (
|
||||
doc
|
||||
) => ({
|
||||
...doc,
|
||||
attributes: commonMigratePartitionMetrics(doc.attributes),
|
||||
});
|
||||
|
||||
const lensMigrations: SavedObjectMigrationMap = {
|
||||
'7.7.0': removeInvalidAccessors,
|
||||
// The order of these migrations matter, since the timefield migration relies on the aggConfigs
|
||||
|
@ -575,7 +583,9 @@ const lensMigrations: SavedObjectMigrationMap = {
|
|||
),
|
||||
'8.3.0': flow(lockOldMetricVisSettings, preserveOldLegendSizeDefault, fixValueLabelsInXY),
|
||||
'8.5.0': flow(migrateMetricIds, enrichAnnotationLayers, migratePartitionChartGroups),
|
||||
'8.6.0': flow(migrateIndexPatternDatasource),
|
||||
'8.6.0': flow(migrateIndexPatternDatasource, migratePartitionMetrics),
|
||||
// FOLLOW THESE GUIDELINES IF YOU ARE ADDING A NEW MIGRATION!
|
||||
// 1. Make sure you are applying migrations for a given version in the same order here as they are applied in x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts
|
||||
};
|
||||
|
||||
export const getAllMigrations = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue