Skip to content

Commit

Permalink
feat: add possibility to use async onSave method (#1079)
Browse files Browse the repository at this point in the history
support of async onSave for custom hooks
https://splunk.atlassian.net/browse/ADDON-62206
  • Loading branch information
soleksy-splunk authored Feb 19, 2024
1 parent 5467ed9 commit 7dd6640
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ui/src/components/BaseFormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
}
};

handleSubmit = (event: React.MouseEvent | React.FormEvent) => {
handleSubmit = async (event: React.MouseEvent | React.FormEvent) => {
event.preventDefault();
this.clearErrorMsg();
this.props.handleFormSubmit(/* isSubmitting */ true, /* closeEntity */ false);
Expand All @@ -536,7 +536,8 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
});

if (this.hook && typeof this.hook.onSave === 'function') {
const validationPass = this.hook.onSave(this.datadict);
const validationPass = await this.hook.onSave(this.datadict);

if (!validationPass) {
this.props.handleFormSubmit(/* isSubmitting */ false, /* closeEntity */ false);
return;
Expand Down Expand Up @@ -1251,6 +1252,7 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
}
this.flag = false;
}

return (
<div>
<form
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/EntityModal/EntityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class EntityModal extends Component<EntityModalProps, EntityModalState> {
this.props.handleRequestClose();
};

handleSubmit: ButtonClickHandler = (e) => {
const result = this.form.current?.handleSubmit(e);
handleSubmit: ButtonClickHandler = async (e) => {
const result = await this.form.current?.handleSubmit(e);
if (result) {
this.handleRequestClose();
}
Expand Down

0 comments on commit 7dd6640

Please sign in to comment.