improve custom label handling (#97219)

This commit is contained in:
Joe Reuter 2021-04-19 14:06:13 +02:00 committed by GitHub
parent a021946e85
commit ce6d2f5a50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View file

@ -542,7 +542,12 @@ export function DimensionEditor(props: DimensionEditorProps) {
[columnId]: {
...selectedColumn,
label: value,
customLabel: true,
customLabel:
operationDefinitionMap[selectedColumn.operationType].getDefaultLabel(
selectedColumn,
state.indexPatterns[state.layers[layerId].indexPatternId],
state.layers[layerId].columns
) !== value,
},
},
},

View file

@ -683,6 +683,44 @@ describe('IndexPatternDimensionEditorPanel', () => {
);
});
it('should remove customLabel flag if label is set to default', () => {
wrapper = mount(
<IndexPatternDimensionEditorComponent
{...defaultProps}
state={getStateWithColumns({
col1: {
...bytesColumn,
label: 'Custom label',
customLabel: true,
},
})}
/>
);
act(() => {
wrapper
.find('input[data-test-subj="indexPattern-label-edit"]')
.simulate('change', { target: { value: 'Maximum of bytes' } });
});
expect(setState).toHaveBeenCalledWith({
...state,
layers: {
first: {
...state.layers.first,
columns: {
...state.layers.first.columns,
col1: expect.objectContaining({
label: 'Maximum of bytes',
customLabel: false,
// Other parts of this don't matter for this test
}),
},
},
},
});
});
describe('transient invalid state', () => {
it('should set the state if selecting an operation incompatible with the current field', () => {
wrapper = mount(<IndexPatternDimensionEditorComponent {...defaultProps} />);