mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
🐛 Keep custom label when set (#126773)
This commit is contained in:
parent
c36efa6af8
commit
5c225cbaa1
2 changed files with 67 additions and 10 deletions
|
@ -322,11 +322,13 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn, 'field
|
|||
return {
|
||||
...oldColumn,
|
||||
dataType: field.type as DataType,
|
||||
label: ofName(
|
||||
field.displayName,
|
||||
newParams.secondaryFields?.length,
|
||||
newParams.orderBy.type === 'rare'
|
||||
),
|
||||
label: oldColumn.customLabel
|
||||
? oldColumn.label
|
||||
: ofName(
|
||||
field.displayName,
|
||||
newParams.secondaryFields?.length,
|
||||
newParams.orderBy.type === 'rare'
|
||||
),
|
||||
sourceField: field.name,
|
||||
params: newParams,
|
||||
};
|
||||
|
@ -401,11 +403,13 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn, 'field
|
|||
...column,
|
||||
dataType: newDataType,
|
||||
sourceField: fields[0],
|
||||
label: ofName(
|
||||
indexPattern.getFieldByName(fields[0])?.displayName,
|
||||
fields.length - 1,
|
||||
newParams.orderBy.type === 'rare'
|
||||
),
|
||||
label: column.customLabel
|
||||
? column.label
|
||||
: ofName(
|
||||
indexPattern.getFieldByName(fields[0])?.displayName,
|
||||
fields.length - 1,
|
||||
newParams.orderBy.type === 'rare'
|
||||
),
|
||||
params: {
|
||||
...newParams,
|
||||
secondaryFields,
|
||||
|
|
|
@ -1481,6 +1481,59 @@ describe('terms', () => {
|
|||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should preserve custom label when set by the user', () => {
|
||||
const updateLayerSpy = jest.fn();
|
||||
const existingFields = getExistingFields();
|
||||
const operationSupportMatrix = getDefaultOperationSupportMatrix('col1', existingFields);
|
||||
|
||||
layer.columns.col1 = {
|
||||
label: 'MyCustomLabel',
|
||||
customLabel: true,
|
||||
dataType: 'string',
|
||||
isBucketed: true,
|
||||
operationType: 'terms',
|
||||
params: {
|
||||
orderBy: { type: 'alphabetical' },
|
||||
size: 3,
|
||||
orderDirection: 'asc',
|
||||
secondaryFields: ['geo.src'],
|
||||
},
|
||||
sourceField: 'source',
|
||||
} as TermsIndexPatternColumn;
|
||||
let instance = mount(
|
||||
<InlineFieldInput
|
||||
{...defaultFieldInputProps}
|
||||
layer={layer}
|
||||
updateLayer={updateLayerSpy}
|
||||
columnId="col1"
|
||||
existingFields={existingFields}
|
||||
operationSupportMatrix={operationSupportMatrix}
|
||||
selectedColumn={layer.columns.col1 as TermsIndexPatternColumn}
|
||||
/>
|
||||
);
|
||||
// add a new field
|
||||
act(() => {
|
||||
instance.find('[data-test-subj="indexPattern-terms-add-field"]').first().simulate('click');
|
||||
});
|
||||
instance = instance.update();
|
||||
|
||||
act(() => {
|
||||
instance.find(EuiComboBox).last().prop('onChange')!([
|
||||
{ value: { type: 'field', field: 'bytes' }, label: 'bytes' },
|
||||
]);
|
||||
});
|
||||
|
||||
expect(updateLayerSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
columns: expect.objectContaining({
|
||||
col1: expect.objectContaining({
|
||||
label: 'MyCustomLabel',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('param editor', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue