mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
This commit is contained in:
parent
e8968738fe
commit
9bcb0ae1ec
2 changed files with 42 additions and 5 deletions
|
@ -965,6 +965,41 @@ describe('state_helpers', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('should not carry over label when operation and field change at the same time', () => {
|
||||
expect(
|
||||
replaceColumn({
|
||||
layer: {
|
||||
indexPatternId: '1',
|
||||
columnOrder: ['col1'],
|
||||
columns: {
|
||||
col1: {
|
||||
label: 'My custom label',
|
||||
customLabel: true,
|
||||
dataType: 'date',
|
||||
isBucketed: true,
|
||||
|
||||
// Private
|
||||
operationType: 'date_histogram',
|
||||
sourceField: 'timestamp',
|
||||
params: {
|
||||
interval: 'h',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
indexPattern,
|
||||
columnId: 'col1',
|
||||
op: 'terms',
|
||||
field: indexPattern.fields[4],
|
||||
visualizationGroups: [],
|
||||
}).columns.col1
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
label: 'Top values of source',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should carry over label on operation switch when customLabel flag on previousColumn is set', () => {
|
||||
expect(
|
||||
replaceColumn({
|
||||
|
|
|
@ -827,12 +827,14 @@ function applyReferenceTransition({
|
|||
);
|
||||
}
|
||||
|
||||
function copyCustomLabel(
|
||||
newColumn: IndexPatternColumn,
|
||||
previousOptions: { customLabel?: boolean; label: string }
|
||||
) {
|
||||
function copyCustomLabel(newColumn: IndexPatternColumn, previousOptions: IndexPatternColumn) {
|
||||
const adjustedColumn = { ...newColumn };
|
||||
if (previousOptions.customLabel) {
|
||||
const operationChanged = newColumn.operationType !== previousOptions.operationType;
|
||||
const fieldChanged =
|
||||
('sourceField' in newColumn && newColumn.sourceField) !==
|
||||
('sourceField' in previousOptions && previousOptions.sourceField);
|
||||
// only copy custom label if either used operation or used field stayed the same
|
||||
if (previousOptions.customLabel && (!operationChanged || !fieldChanged)) {
|
||||
adjustedColumn.customLabel = true;
|
||||
adjustedColumn.label = previousOptions.label;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue