You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/10/28 21:51:12 UTC

[GitHub] [incubator-superset] nytai commented on a change in pull request #11390: refactor: Replace react-bootstrap Modals with Antd in Datasource

nytai commented on a change in pull request #11390:
URL: https://github.com/apache/incubator-superset/pull/11390#discussion_r513783528



##########
File path: superset-frontend/src/datasource/ChangeDatasourceModal.tsx
##########
@@ -59,62 +65,68 @@ const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({
   const [loading, setLoading] = useState(true);
   let searchRef = useRef<HTMLInputElement>(null);
 
-  const selectDatasource = (datasource: any) => {
-    SupersetClient.get({
-      endpoint: `/datasource/get/${datasource.type}/${datasource.id}`,
-    })
-      .then(({ json }) => {
-        onDatasourceSave(json);
-        onChange(datasource.uid);
-      })
-      .catch(response => {
-        getClientErrorObject(response).then(
-          ({ error, message }: { error: any; message: string }) => {
-            const errorMessage = error
-              ? error.error || error.statusText || error
-              : message;
-            addDangerToast(errorMessage);
-          },
-        );
-      });
-    onHide();
-  };
-
-  const onEnterModal = () => {
-    if (searchRef && searchRef.current) {
-      searchRef.current.focus();
-    }
-    if (!datasources) {
+  useEffect(() => {
+    const selectDatasource = (datasource: any) => {
       SupersetClient.get({
-        endpoint: '/superset/datasources/',
+        endpoint: `/datasource/get/${datasource.type}/${datasource.id}`,
       })
         .then(({ json }) => {
-          const data = json.map((ds: any) => ({
-            rawName: ds.name,
-            connection: ds.connection,
-            schema: ds.schema,
-            name: (
-              <a
-                href="#"
-                onClick={() => selectDatasource(ds)}
-                className="datasource-link"
-              >
-                {ds.name}
-              </a>
-            ),
-            type: ds.type,
-          }));
-          setLoading(false);
-          setDatasources(data);
+          onDatasourceSave(json);
+          onChange(datasource.uid);
         })
         .catch(response => {
-          setLoading(false);
-          getClientErrorObject(response).then(({ error }: any) => {
-            addDangerToast(error.error || error.statusText || error);
-          });
+          getClientErrorObject(response).then(
+            ({ error, message }: { error: any; message: string }) => {

Review comment:
       That type is incorrect, it can be an object or a string or anything else the api decides to send




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org