Skip to content

Commit

Permalink
Fix type checker issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Jun 23, 2020
1 parent 2134f45 commit 888979e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ export function AdvancedSettingsForm({
}

function getNumberUpdater<K extends NumberKeys<AdvancedSettings>>(key: K) {
return function ({ target: { valueAsNumber } }: { target: { valueAsNumber: number | '' } }) {
return function ({
target: { valueAsNumber, value },
}: {
target: { valueAsNumber: number; value: string };
}) {
// if the value is valid, then update the central store, otherwise only the local store
if (valueAsNumber === '' || Number.isNaN(valueAsNumber)) {
if (Number.isNaN(valueAsNumber)) {
// localstate update
return updateFormState({ ...formState, [key]: valueAsNumber });
return updateFormState({ ...formState, [key]: value });
}
// do not worry about local store here, the useEffect will pick that up and sync it
updateSetting(key, valueAsNumber);
Expand Down Expand Up @@ -167,7 +171,7 @@ export function AdvancedSettingsForm({
defaultMessage:
'Max number of documents in a sample that can contain the same value for the',
})}{' '}
<em>{formState.sampleDiversityField!.name}</em>{' '}
<em>{formState.sampleDiversityField.name}</em>{' '}
{i18n.translate(
'xpack.graph.settings.advancedSettings.maxValuesInputHelpText.fieldText',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ describe('settings', () => {
it('should let the user edit and empty the field to input a new number', () => {
act(() => {
input('Sample size').prop('onChange')!({
target: { valueAsNumber: '' },
target: { value: '', valueAsNumber: NaN },
} as React.ChangeEvent<HTMLInputElement>);
});
// Central state should not be called
expect(dispatchSpy).not.toHaveBeenCalledWith(
updateSettings(
expect.objectContaining({
timeoutMillis: 10000,
sampleSize: '',
sampleSize: NaN,
})
)
);
Expand Down

0 comments on commit 888979e

Please sign in to comment.