Skip to content

Commit

Permalink
🎨 [#4693] Remove support for sync onChangeCheck functions
Browse files Browse the repository at this point in the history
This was a leftover in case window.confirm is/was used - this has all
been replaced with the custom confirmation hook and modal which must
always be async.

Discussed via Slack.
  • Loading branch information
sergei-maertens committed Nov 22, 2024
1 parent 7a0cdc9 commit 212e7c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import ReactSelect from 'components/admin/forms/ReactSelect';
import {get} from 'utils/fetch';
import {isAsync} from 'utils/functions';

import {useSynchronizeSelect} from './hooks';

Expand Down Expand Up @@ -67,20 +66,6 @@ const ObjectTypeSelect = ({
setFieldValue(versionFieldName, undefined); // clears the value
}, [loading, value]);

let handleOnChange;
if (isAsync(onChangeCheck)) {
// onChange handler should be async for the new confirmation modal
handleOnChange = async selectedOption => {
const okToProceed = onChangeCheck === undefined || (await onChangeCheck());
if (okToProceed) setValue(selectedOption.value);
};
} else {
handleOnChange = selectedOption => {
const okToProceed = onChangeCheck === undefined || onChangeCheck();
if (okToProceed) setValue(selectedOption.value);
};
}

return (
<FormRow>
<Field name={name} required label={label} helpText={helpText} noManageChildProps>
Expand All @@ -90,7 +75,10 @@ const ObjectTypeSelect = ({
isLoading={loading}
isDisabled={!objectsApiGroup}
required
onChange={handleOnChange}
onChange={async selectedOption => {
const okToProceed = onChangeCheck === undefined || (await onChangeCheck());
if (okToProceed) setValue(selectedOption.value);
}}
/>
</Field>
</FormRow>
Expand All @@ -104,7 +92,7 @@ ObjectTypeSelect.propTypes = {
name: PropTypes.string,
/**
* Optional callback to confirm the change. Return `true` to continue with the change,
* return `false` to abort it.
* return `false` to abort it. The callback function must be async.
*/
onChangeCheck: PropTypes.func,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {useUpdateEffect} from 'react-use';
import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import ReactSelect from 'components/admin/forms/ReactSelect';
import {isAsync} from 'utils/functions';

const ObjectsAPIGroup = ({
apiGroupChoices,
Expand Down Expand Up @@ -36,28 +35,6 @@ const ObjectsAPIGroup = ({
value: option.value === null ? '' : option.value,
}));

let handleOnChange;
if (isAsync(onChangeCheck)) {
// onChange handler should be async for the new confirmation modal
handleOnChange = async selectedOption => {
const okToProceed = onChangeCheck === undefined || (await onChangeCheck());
if (okToProceed) {
// normalize empty string back to null
const newValue = selectedOption ? selectedOption.value : null;
setValue(newValue);
}
};
} else {
handleOnChange = selectedOption => {
const okToProceed = onChangeCheck === undefined || onChangeCheck();
if (okToProceed) {
// normalize empty string back to null
const newValue = selectedOption ? selectedOption.value : null;
setValue(newValue);
}
};
}

return (
<FormRow>
<Field
Expand All @@ -82,7 +59,14 @@ const ObjectsAPIGroup = ({
options={normalizedOptions}
value={normalizedOptions.find(option => option.value === normalizedValue)}
required={required}
onChange={handleOnChange}
onChange={async selectedOption => {
const okToProceed = onChangeCheck === undefined || (await onChangeCheck());
if (okToProceed) {
// normalize empty string back to null
const newValue = selectedOption ? selectedOption.value : null;
setValue(newValue);
}
}}
isClearable={isClearable}
/>
</Field>
Expand Down
5 changes: 0 additions & 5 deletions src/openforms/js/utils/functions.js

This file was deleted.

0 comments on commit 212e7c2

Please sign in to comment.