[Lens] Rename datasources (#142553)

* Rename to textBased instead of textBasedLanguages

* [Lens] Rename datasources to textBased and formBased

* Fix css

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Move datasources under a common foler

* Fix types

* Revert css classes

* Add migration script

* Fix lens embeddable functional tests

* Fix types

* Fixes cases test

* Adds migration script test

* Revert

* Update jest integration test

* Fix security solution tests

* Fix jest test

* Address type nit

* Fix types

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Stratoula Kalafateli 2022-10-12 11:25:24 +03:00 committed by GitHub
parent 005a6eabb5
commit 8c4976f25d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
271 changed files with 1309 additions and 1282 deletions

View file

@ -7,6 +7,7 @@
import { EmbeddableRegistryDefinition } from '@kbn/embeddable-plugin/server';
import type { SerializableRecord } from '@kbn/utility-types';
import type { SavedObject } from '@kbn/core-saved-objects-common';
import {
mergeMigrationFunctionMaps,
MigrateFunctionsObject,
@ -31,6 +32,7 @@ import {
getLensDataViewMigrations,
commonMigrateMetricIds,
commonMigratePartitionChartGroups,
commonMigrateIndexPatternDatasource,
} from '../migrations/common_migrations';
import {
CustomVisualizationMigrations,
@ -155,6 +157,15 @@ export const makeLensEmbeddableFactory =
attributes: migratedLensState,
} as unknown as SerializableRecord;
},
'8.6.0': (state) => {
const lensState = state as unknown as SavedObject<LensDocShape850<VisState850>>;
const migratedLensState = commonMigrateIndexPatternDatasource(lensState.attributes);
return {
...lensState,
attributes: migratedLensState,
} as unknown as SerializableRecord;
},
}),
getLensCustomVisualizationMigrations(customVisualizationMigrations)
),

View file

@ -34,6 +34,7 @@ import {
XYVisStatePre850,
VisState850,
LensDocShape850,
LensDocShape860,
} from './types';
import { DOCUMENT_FIELD_NAME, LegacyMetricState } from '../../common';
import { isPartitionShape } from '../../common/visualizations';
@ -477,6 +478,22 @@ export const commonMigrateMetricIds = (
return newAttributes;
};
export const commonMigrateIndexPatternDatasource = (
attributes: LensDocShape850<unknown>
): LensDocShape860<unknown> => {
const newAttrs = {
...attributes,
state: {
...attributes.state,
datasourceStates: {
formBased: attributes.state.datasourceStates.indexpattern,
},
},
};
return newAttrs;
};
export const commonMigratePartitionChartGroups = (
attributes: LensDocShape850<{
shape: string;

View file

@ -2363,4 +2363,100 @@ describe('Lens migrations', () => {
expect(result.attributes.visualizationType).toBe('lnsMetric');
});
});
describe('8.6.0 migrates indexpattern datasource', () => {
const context = { log: { warn: () => {} } } as unknown as SavedObjectMigrationContext;
const example = {
type: 'lens',
id: 'mock-saved-object-id',
attributes: {
state: {
datasourceMetaData: {
filterableIndexPatterns: [
{
id: 'logstash-*',
title: 'logstash-*',
},
],
},
datasourceStates: {
indexpattern: {
currentIndexPatternId: 'logstash-*',
layers: {
'c61a8afb-a185-4fae-a064-fb3846f6c451': {
columnOrder: ['2cd09808-3915-49f4-b3b0-82767eba23f7'],
columns: {
'2cd09808-3915-49f4-b3b0-82767eba23f7': {
dataType: 'number',
isBucketed: false,
label: 'Maximum of bytes',
operationType: 'max',
scale: 'ratio',
sourceField: 'bytes',
},
'd3e62a7a-c259-4fff-a2fc-eebf20b7008a': {
dataType: 'number',
isBucketed: false,
label: 'Minimum of bytes',
operationType: 'min',
scale: 'ratio',
sourceField: 'bytes',
},
'd6e40cea-6299-43b4-9c9d-b4ee305a2ce8': {
dataType: 'date',
isBucketed: true,
label: 'Date Histogram of @timestamp',
operationType: 'date_histogram',
params: {
interval: 'auto',
},
scale: 'interval',
sourceField: '@timestamp',
},
},
indexPatternId: 'logstash-*',
},
},
},
},
filters: [],
query: {
language: 'kuery',
query: '',
},
visualization: {
accessor: '2cd09808-3915-49f4-b3b0-82767eba23f7',
isHorizontal: false,
layerId: 'c61a8afb-a185-4fae-a064-fb3846f6c451',
layers: [
{
accessors: [
'd3e62a7a-c259-4fff-a2fc-eebf20b7008a',
'26ef70a9-c837-444c-886e-6bd905ee7335',
],
layerId: 'c61a8afb-a185-4fae-a064-fb3846f6c451',
seriesType: 'area',
splitAccessor: '54cd64ed-2a44-4591-af84-b2624504569a',
xAccessor: 'd6e40cea-6299-43b4-9c9d-b4ee305a2ce8',
},
],
legend: {
isVisible: true,
position: 'right',
},
preferredSeriesType: 'area',
},
},
title: 'Artistpreviouslyknownaslens',
visualizationType: 'lnsXY',
},
};
it('migrates the indexpattern datasource to formBased', () => {
const result = migrations['8.6.0'](example, context);
expect(result.attributes.state.datasourceStates.formBased).toBe(
example.attributes.state.datasourceStates.indexpattern
);
});
});
});

View file

@ -38,6 +38,7 @@ import {
LensDocShape850,
LensDocShape840,
VisState850,
LensDocShape860,
} from './types';
import {
commonRenameOperationsForFormula,
@ -59,6 +60,7 @@ import {
getLensDataViewMigrations,
commonMigrateMetricIds,
commonMigratePartitionChartGroups,
commonMigrateIndexPatternDatasource,
} from './common_migrations';
interface LensDocShapePre710<VisualizationState = unknown> {
@ -533,6 +535,13 @@ const migrateMetricIds: SavedObjectMigrationFn<LensDocShape850, LensDocShape850>
attributes: commonMigrateMetricIds(doc.attributes),
});
const migrateIndexPatternDatasource: SavedObjectMigrationFn<LensDocShape850, LensDocShape860> = (
doc
) => ({
...doc,
attributes: commonMigrateIndexPatternDatasource(doc.attributes),
});
const migratePartitionChartGroups: SavedObjectMigrationFn<LensDocShape840, LensDocShape840> = (
doc
) => ({
@ -566,6 +575,7 @@ const lensMigrations: SavedObjectMigrationMap = {
),
'8.3.0': flow(lockOldMetricVisSettings, preserveOldLegendSizeDefault, fixValueLabelsInXY),
'8.5.0': flow(migrateMetricIds, enrichAnnotationLayers, migratePartitionChartGroups),
'8.6.0': flow(migrateIndexPatternDatasource),
};
export const getAllMigrations = (

View file

@ -303,3 +303,24 @@ export type VisState840 = VisState830;
export type LensDocShape840<VisualizationState = unknown> = LensDocShape830<VisualizationState>;
export type LensDocShape850<VisualizationState = unknown> = LensDocShape840<VisualizationState>;
export type LensDocShape860<VisualizationState = unknown> = Omit<
LensDocShape850<VisualizationState>,
'state'
> & {
state: Omit<LensDocShape850<VisualizationState>['state'], 'datasourceStates'> & {
datasourceStates: {
// This is hardcoded as our only datasource
formBased: {
currentIndexPatternId: string;
layers: Record<
string,
{
columnOrder: string[];
columns: Record<string, Record<string, unknown>>;
}
>;
};
};
};
};