-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Rule form validation on submit (#264)
* WIP: Formik validation for rule editor Signed-off-by: Aleksandar Djindjic <[email protected]> * add more fields Signed-off-by: Aleksandar Djindjic <[email protected]> * handing submition to the backend in RuleEditor Signed-off-by: Aleksandar Djindjic <[email protected]> * update yaml rule editor snapshot Signed-off-by: Aleksandar Djindjic <[email protected]> * fix cypress testing fails Signed-off-by: Aleksandar Djindjic <[email protected]> * fix cypress test Signed-off-by: Aleksandar Djindjic <[email protected]> * update snapshot Signed-off-by: Aleksandar Djindjic <[email protected]> * useCallback optimization Signed-off-by: Aleksandar Djindjic <[email protected]> Signed-off-by: Aleksandar Djindjic <[email protected]>
- Loading branch information
Showing
11 changed files
with
562 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,5 +65,8 @@ | |
}, | ||
"engines": { | ||
"yarn": "^1.21.1" | ||
}, | ||
"dependencies": { | ||
"formik": "^2.2.9" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
public/pages/Rules/components/RuleEditor/FormSubmitionErrorToastNotification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { useEffect, useState } from 'react'; | ||
import { useFormikContext } from 'formik'; | ||
import { NotificationsStart } from 'opensearch-dashboards/public'; | ||
import { errorNotificationToast } from '../../../../utils/helpers'; | ||
|
||
export const FormSubmitionErrorToastNotification = ({ | ||
notifications, | ||
}: { | ||
notifications?: NotificationsStart; | ||
}) => { | ||
const { submitCount, isValid } = useFormikContext(); | ||
const [prevSubmitCount, setPrevSubmitCount] = useState(submitCount); | ||
|
||
useEffect(() => { | ||
if (isValid) return; | ||
|
||
if (submitCount === prevSubmitCount) return; | ||
|
||
setPrevSubmitCount(submitCount); | ||
|
||
errorNotificationToast( | ||
notifications!, | ||
'create', | ||
'rule', | ||
'Some fields are invalid. Fix all highlighted error(s) before continuing.' | ||
); | ||
}, [submitCount, isValid]); | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.