mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Lens] include empty rows setting for date histogram (#127453)
This commit is contained in:
parent
accb6bdf01
commit
354cd01ecb
43 changed files with 333 additions and 95 deletions
|
@ -19,6 +19,7 @@ import {
|
|||
commonRenameFilterReferences,
|
||||
commonRenameOperationsForFormula,
|
||||
commonRenameRecordsField,
|
||||
commonSetIncludeEmptyRowsDateHistogram,
|
||||
commonSetLastValueShowArrayValues,
|
||||
commonUpdateVisLayerType,
|
||||
getLensCustomVisualizationMigrations,
|
||||
|
@ -95,7 +96,8 @@ export const makeLensEmbeddableFactory =
|
|||
'8.2.0': (state) => {
|
||||
const lensState = state as unknown as { attributes: LensDocShape810<VisState810> };
|
||||
let migratedLensState = commonSetLastValueShowArrayValues(lensState.attributes);
|
||||
migratedLensState = commonEnhanceTableRowHeight(lensState.attributes);
|
||||
migratedLensState = commonEnhanceTableRowHeight(migratedLensState);
|
||||
migratedLensState = commonSetIncludeEmptyRowsDateHistogram(migratedLensState);
|
||||
return {
|
||||
...lensState,
|
||||
attributes: migratedLensState,
|
||||
|
|
|
@ -225,6 +225,20 @@ export const commonEnhanceTableRowHeight = (
|
|||
return newAttributes;
|
||||
};
|
||||
|
||||
export const commonSetIncludeEmptyRowsDateHistogram = (
|
||||
attributes: LensDocShape810
|
||||
): LensDocShape810<VisState820> => {
|
||||
const newAttributes = cloneDeep(attributes);
|
||||
for (const layer of Object.values(newAttributes.state.datasourceStates.indexpattern.layers)) {
|
||||
for (const column of Object.values(layer.columns)) {
|
||||
if (column.operationType === 'date_histogram') {
|
||||
column.params.includeEmptyRows = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newAttributes;
|
||||
};
|
||||
|
||||
const getApplyCustomVisualizationMigrationToLens = (id: string, migration: MigrateFunction) => {
|
||||
return (savedObject: { attributes: LensDocShape }) => {
|
||||
if (savedObject.attributes.visualizationType !== id) return savedObject;
|
||||
|
|
|
@ -1993,4 +1993,75 @@ describe('Lens migrations', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('8.2.0 include empty rows for date histogram columns', () => {
|
||||
const context = { log: { warning: () => {} } } as unknown as SavedObjectMigrationContext;
|
||||
const example = {
|
||||
type: 'lens',
|
||||
id: 'mocked-saved-object-id',
|
||||
attributes: {
|
||||
savedObjectId: '1',
|
||||
title: 'MyRenamedOps',
|
||||
description: '',
|
||||
visualizationType: null,
|
||||
state: {
|
||||
datasourceMetaData: {
|
||||
filterableIndexPatterns: [],
|
||||
},
|
||||
datasourceStates: {
|
||||
indexpattern: {
|
||||
currentIndexPatternId: 'logstash-*',
|
||||
layers: {
|
||||
'2': {
|
||||
columns: {
|
||||
'3': {
|
||||
label: '@timestamp',
|
||||
dataType: 'date',
|
||||
operationType: 'date_histogram',
|
||||
sourceField: '@timestamp',
|
||||
isBucketed: true,
|
||||
scale: 'interval',
|
||||
params: { interval: 'auto', timeZone: 'Europe/Berlin' },
|
||||
},
|
||||
'4': {
|
||||
label: '@timestamp',
|
||||
dataType: 'date',
|
||||
operationType: 'date_histogram',
|
||||
sourceField: '@timestamp',
|
||||
isBucketed: true,
|
||||
scale: 'interval',
|
||||
params: { interval: 'auto' },
|
||||
},
|
||||
'6': {
|
||||
label: 'Sum of bytes',
|
||||
dataType: 'number',
|
||||
operationType: 'sum',
|
||||
sourceField: 'bytes',
|
||||
isBucketed: false,
|
||||
scale: 'ratio',
|
||||
},
|
||||
},
|
||||
columnOrder: ['3', '4', '5'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
visualization: {},
|
||||
query: { query: '', language: 'kuery' },
|
||||
filters: [],
|
||||
},
|
||||
},
|
||||
} as unknown as SavedObjectUnsanitizedDoc<LensDocShape810>;
|
||||
|
||||
it('should set include empty rows for all date histogram columns', () => {
|
||||
const result = migrations['8.2.0'](example, context) as ReturnType<
|
||||
SavedObjectMigrationFn<LensDocShape, LensDocShape>
|
||||
>;
|
||||
|
||||
const layer2Columns =
|
||||
result.attributes.state.datasourceStates.indexpattern.layers['2'].columns;
|
||||
expect(layer2Columns['3'].params).toHaveProperty('includeEmptyRows', true);
|
||||
expect(layer2Columns['4'].params).toHaveProperty('includeEmptyRows', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -42,6 +42,7 @@ import {
|
|||
fixLensTopValuesCustomFormatting,
|
||||
commonSetLastValueShowArrayValues,
|
||||
commonEnhanceTableRowHeight,
|
||||
commonSetIncludeEmptyRowsDateHistogram,
|
||||
} from './common_migrations';
|
||||
|
||||
interface LensDocShapePre710<VisualizationState = unknown> {
|
||||
|
@ -477,6 +478,12 @@ const enhanceTableRowHeight: SavedObjectMigrationFn<LensDocShape810, LensDocShap
|
|||
return { ...newDoc, attributes: commonEnhanceTableRowHeight(newDoc.attributes) };
|
||||
};
|
||||
|
||||
const setIncludeEmptyRowsDateHistogram: SavedObjectMigrationFn<LensDocShape810, LensDocShape810> = (
|
||||
doc
|
||||
) => {
|
||||
return { ...doc, attributes: commonSetIncludeEmptyRowsDateHistogram(doc.attributes) };
|
||||
};
|
||||
|
||||
const lensMigrations: SavedObjectMigrationMap = {
|
||||
'7.7.0': removeInvalidAccessors,
|
||||
// The order of these migrations matter, since the timefield migration relies on the aggConfigs
|
||||
|
@ -491,7 +498,11 @@ const lensMigrations: SavedObjectMigrationMap = {
|
|||
'7.15.0': addLayerTypeToVisualization,
|
||||
'7.16.0': moveDefaultReversedPaletteToCustom,
|
||||
'8.1.0': flow(renameFilterReferences, renameRecordsField, addParentFormatter),
|
||||
'8.2.0': flow(setLastValueShowArrayValues, enhanceTableRowHeight),
|
||||
'8.2.0': flow(
|
||||
setLastValueShowArrayValues,
|
||||
setIncludeEmptyRowsDateHistogram,
|
||||
enhanceTableRowHeight
|
||||
),
|
||||
};
|
||||
|
||||
export const getAllMigrations = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue