You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by su...@apache.org on 2020/11/25 19:13:24 UTC
[incubator-superset] 01/02: separate form validation
This is an automated email from the ASF dual-hosted git repository.
suddjian pushed a commit to branch native-filters-fast-follow
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 92ee1aa80729c83b1d05f18046d8f1decbac084c
Author: David Aaron Suddjian <aa...@gmail.com>
AuthorDate: Wed Nov 25 11:12:08 2020 -0800
separate form validation
---
.../components/nativeFilters/FilterConfigModal.tsx | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterConfigModal.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterConfigModal.tsx
index 0f50c84..167a21f 100644
--- a/superset-frontend/src/dashboard/components/nativeFilters/FilterConfigModal.tsx
+++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterConfigModal.tsx
@@ -153,14 +153,13 @@ export function FilterConfigModal({
);
}
- const onOk = useCallback(async () => {
- let values: NativeFiltersForm | null = null;
+ const validateForm = useCallback(async () => {
try {
- values = (await form.validateFields()) as NativeFiltersForm;
+ return (await form.validateFields()) as NativeFiltersForm;
} catch (error) {
console.warn('Filter Configuration Failed:', error);
- if (!error.errorFields || !error.errorFields.length) return; // not a validation error
+ if (!error.errorFields || !error.errorFields.length) return null; // not a validation error
// the name is in array format since the fields are nested
type ErrorFields = { name: ['filters', string, string] }[];
@@ -170,8 +169,12 @@ export function FilterConfigModal({
// switch to the first tab that had a validation error
setCurrentFilterId(errorFields[0].name[1]);
}
+ return null;
}
+ }, [form, currentFilterId]);
+ const onOk = useCallback(async () => {
+ const values: NativeFiltersForm | null = await validateForm();
if (values == null) return;
const newFilterConfig: FilterConfiguration = filterIds
@@ -207,13 +210,12 @@ export function FilterConfigModal({
await save(newFilterConfig);
resetForm();
}, [
- form,
save,
resetForm,
filterIds,
- currentFilterId,
removedFilters,
filterConfigMap,
+ validateForm,
]);
return (