disable missing switch for non-string fields (#102865)

This commit is contained in:
Joe Reuter 2021-06-23 13:47:19 +02:00 committed by GitHub
parent 498df213fa
commit 2ab5d6bc46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View file

@ -497,7 +497,10 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn, 'field
defaultMessage: 'Include documents without this field',
})}
compressed
disabled={!currentColumn.params.otherBucket}
disabled={
!currentColumn.params.otherBucket ||
indexPattern.getFieldByName(currentColumn.sourceField)?.type !== 'string'
}
data-test-subj="indexPattern-terms-missing-bucket"
checked={Boolean(currentColumn.params.missingBucket)}
onChange={(e: EuiSwitchEvent) =>

View file

@ -60,7 +60,7 @@ describe('terms', () => {
size: 3,
orderDirection: 'asc',
},
sourceField: 'category',
sourceField: 'source',
},
col2: {
label: 'Count',
@ -88,7 +88,7 @@ describe('terms', () => {
expect.objectContaining({
arguments: expect.objectContaining({
orderBy: ['_key'],
field: ['category'],
field: ['source'],
size: [3],
otherBucket: [true],
}),
@ -770,6 +770,34 @@ describe('terms', () => {
expect(select.prop('disabled')).toEqual(false);
});
it('should disable missing bucket setting if field is not a string', () => {
const updateLayerSpy = jest.fn();
const instance = shallow(
<InlineOptions
{...defaultProps}
layer={layer}
updateLayer={updateLayerSpy}
columnId="col1"
currentColumn={
{
...layer.columns.col1,
sourceField: 'bytes',
params: {
...layer.columns.col1.params,
otherBucket: true,
},
} as TermsIndexPatternColumn
}
/>
);
const select = instance
.find('[data-test-subj="indexPattern-terms-missing-bucket"]')
.find(EuiSwitch);
expect(select.prop('disabled')).toEqual(true);
});
it('should update state when clicking other bucket toggle', () => {
const updateLayerSpy = jest.fn();
const instance = shallow(