Skip to content

Commit

Permalink
disable missing switch for non-string fields (#102865) (#103073)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
  • Loading branch information
kibanamachine and flash1293 authored Jun 23, 2021
1 parent 03b8800 commit e583c6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('terms', () => {
size: 3,
orderDirection: 'asc',
},
sourceField: 'category',
sourceField: 'source',
},
col2: {
label: 'Count',
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('terms', () => {
expect.objectContaining({
arguments: expect.objectContaining({
orderBy: ['_key'],
field: ['category'],
field: ['source'],
size: [3],
otherBucket: [true],
}),
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e583c6d

Please sign in to comment.