[Bug][Investigations] - Limit sample size range input to integers (#185998)

## Summary

Currently you can enter a decimal value in the sample size range
selector which causes an error in the discover experience. This ticket
resolves that issue by limiting the actual parsed value to an integer.

Original bug: https://github.com/elastic/kibana/issues/184708
This commit is contained in:
Michael Olorunnisola 2024-06-13 14:41:53 -04:00 committed by GitHub
parent 0082f4522d
commit 8c7a36f34b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View file

@ -140,6 +140,42 @@ describe('UnifiedDataTableAdditionalDisplaySettings', function () {
expect(onChangeSampleSizeMock).not.toHaveBeenCalled();
});
it('should only render integers when a decimal value is provided', async () => {
const invalidDecimalValue = 6.11;
const validIntegerValue = 6;
const onChangeSampleSizeMock = jest.fn();
const component = mountWithIntl(
<UnifiedDataTableAdditionalDisplaySettings
maxAllowedSampleSize={500}
sampleSize={50}
onChangeSampleSize={onChangeSampleSizeMock}
rowHeight={RowHeightMode.custom}
rowHeightLines={10}
headerRowHeight={RowHeightMode.custom}
headerRowHeightLines={5}
/>
);
const input = findTestSubject(component, 'unifiedDataTableSampleSizeInput').last();
expect(input.prop('value')).toBe(50);
await act(async () => {
input.simulate('change', {
target: {
value: invalidDecimalValue,
},
});
});
await new Promise((resolve) => setTimeout(resolve, 0));
component.update();
expect(
findTestSubject(component, 'unifiedDataTableSampleSizeInput').last().prop('value')
).toBe(validIntegerValue);
});
});
describe('rowHeight', () => {

View file

@ -70,7 +70,7 @@ export const UnifiedDataTableAdditionalDisplaySettings: React.FC<
return;
}
const newSampleSize = Number(event.target.value);
const newSampleSize = parseInt(event.target.value, 10) ?? RANGE_MIN_SAMPLE_SIZE;
if (newSampleSize >= MIN_ALLOWED_SAMPLE_SIZE) {
setActiveSampleSize(newSampleSize);