Skip to content

Commit

Permalink
[DataViewField] Fix removal of a custom label from a runtime field (e…
Browse files Browse the repository at this point in the history
…lastic#168603)

- Closes elastic#168585

## Summary

This PR fixes an issue with removing a custom label from a runtime
field.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
jughosta authored Oct 12, 2023
1 parent 4302059 commit fa8d953
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/plugins/data_views/common/data_views/data_view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,20 @@ describe('IndexPattern', () => {
expect(indexPattern.toSpec()!.fields!.new_field).toBeUndefined();
});

test('add and remove a custom label from a runtime field', () => {
const newField = 'new_field_test';
indexPattern.addRuntimeField(newField, {
...runtimeWithAttrs,
customLabel: 'test1',
});
expect(indexPattern.getFieldByName(newField)?.customLabel).toEqual('test1');
indexPattern.setFieldCustomLabel(newField, 'test2');
expect(indexPattern.getFieldByName(newField)?.customLabel).toEqual('test2');
indexPattern.setFieldCustomLabel(newField, undefined);
expect(indexPattern.getFieldByName(newField)?.customLabel).toBeUndefined();
indexPattern.removeRuntimeField(newField);
});

test('add and remove composite runtime field as new fields', () => {
const fieldCount = indexPattern.fields.length;
indexPattern.addRuntimeField('new_field', runtimeCompositeWithAttrs);
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/data_views/common/data_views/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,7 @@ export class DataView implements DataViewBase {
}

// Apply configuration to the field
if (config.customLabel || config.customLabel === null) {
this.setFieldCustomLabel(fieldName, config.customLabel);
}
this.setFieldCustomLabel(fieldName, config.customLabel);

if (config.popularity || config.popularity === null) {
this.setFieldCount(fieldName, config.popularity);
Expand Down

0 comments on commit fa8d953

Please sign in to comment.