Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Disable missing switch for non-string fields #102865

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,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