You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by yj...@apache.org on 2020/10/29 23:14:05 UTC

[incubator-superset] branch master updated: feat: disable save button when saving datasource (#11493)

This is an automated email from the ASF dual-hosted git repository.

yjc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 9369369  feat: disable save button when saving datasource (#11493)
9369369 is described below

commit 93693690a31f37c5ac1aae95548d89e715c6ea34
Author: Jesse Yang <je...@airbnb.com>
AuthorDate: Thu Oct 29 16:13:47 2020 -0700

    feat: disable save button when saving datasource (#11493)
---
 superset-frontend/src/datasource/DatasourceModal.tsx | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/superset-frontend/src/datasource/DatasourceModal.tsx b/superset-frontend/src/datasource/DatasourceModal.tsx
index 2bd6bae..ed62567 100644
--- a/superset-frontend/src/datasource/DatasourceModal.tsx
+++ b/superset-frontend/src/datasource/DatasourceModal.tsx
@@ -82,6 +82,7 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
 }) => {
   const [currentDatasource, setCurrentDatasource] = useState(datasource);
   const [errors, setErrors] = useState<any[]>([]);
+  const [isSaving, setIsSaving] = useState(false);
   const dialog = useRef<any>(null);
 
   const onConfirmSave = () => {
@@ -90,6 +91,9 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
       currentDatasource.schema ||
       currentDatasource.databaseSelector?.schema ||
       currentDatasource.tableSelector?.schema;
+
+    setIsSaving(true);
+
     SupersetClient.post({
       endpoint: '/datasource/save/',
       postPayload: {
@@ -111,7 +115,8 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
         onDatasourceSave(json);
         onHide();
       })
-      .catch(response =>
+      .catch(response => {
+        setIsSaving(false);
         getClientErrorObject(response).then(({ error }) => {
           dialog.current.show({
             title: 'Error',
@@ -120,8 +125,8 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
             actions: [Dialog.DefaultAction('Ok', () => {}, 'btn-danger')],
             body: error || t('An error has occurred'),
           });
-        }),
-      );
+        });
+      });
   };
 
   const onDatasourceChange = (data: Record<string, any>, err: Array<any>) => {
@@ -196,7 +201,7 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
             className="m-r-5"
             data-test="datasource-modal-save"
             onClick={onClickSave}
-            disabled={errors.length > 0}
+            disabled={isSaving || errors.length > 0}
           >
             {t('Save')}
           </Button>