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 2022/08/25 14:43:33 UTC

[GitHub] [superset] AAfghahi commented on a diff in pull request #21075: feat: add tableselector to dataset creation page

AAfghahi commented on code in PR #21075:
URL: https://github.com/apache/superset/pull/21075#discussion_r955056673


##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx:
##########
@@ -16,18 +16,204 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import React from 'react';
-import { t } from '@superset-ui/core';
+import React, { useEffect, useState, useMemo } from 'react';
+import { SupersetClient, t, styled, FAST_DEBOUNCE } from '@superset-ui/core';
+import { Input } from 'src/components/Input';
+import { Form } from 'src/components/Form';
+import { TableOption, Table } from 'src/components/TableSelector';
+import RefreshLabel from 'src/components/RefreshLabel';
+import Loading from 'src/components/Loading';
+import DatabaseSelector from 'src/components/DatabaseSelector';
+import { debounce } from 'lodash';
 import { EmptyStateMedium } from 'src/components/EmptyState';
+import { DatasetActionType } from '../types';
+
+interface LeftPanelProps {
+  setDataset: (db: any) => void;
+  schema?: string | undefined | null;
+  dbId?: string;
+}
+
+const LeftPanelStyle = styled.div`
+  ${({ theme }) => `
+  max-width: 350px;
+  padding: ${theme.gridUnit * 4}px;
+  height: 100%;
+  background-color: ${theme.colors.grayscale.light5}; 
+  .refresh {
+    position: absolute;
+    top: 290px;
+    left: 67px;
+    span[role="button"]{
+      font-size: ${theme.gridUnit * 4.25}px;
+    }
+  }
+  .section-title {
+    margin-top: 44px;
+    margin-bottom: 44px;
+    font-weight: ${theme.typography.weights.bold};
+  }
+  .options-list {
+    overflow: auto;
+    max-height: 700px;
+    .options {
+      padding: ${theme.gridUnit * 1.75}px;
+      border-radius: ${theme.borderRadius}px;
+    }
+  }
+  form > span {
+    position: absolute;
+    top: 410px;
+    left: 171px;
+    font-size: 17px;   
+  }
+  .table-form {
+    margin-bottom: ${theme.gridUnit * 8}px;
+  }
+  .loading {
+    position: absolute;
+    bottom: 380px;
+    img {
+      position: absolute;
+      top: -53px;
+      right: -15px;
+      width: 71px;
+    }
+  }
+  }
+`}
+`;
+
+export default function LeftPanel({
+  setDataset,
+  schema,
+  dbId,
+}: LeftPanelProps) {
+  const [tableOptions, setTableOptions] = useState<Array<TableOption>>([]);
+  const [resetTables, setResetTables] = useState(false);
+  const [loadTables, setLoadTables] = useState(false);
+  const [searchVal, setSearchVal] = useState('');
+  const [refresh, setRefresh] = useState(false);
+
+  const setDatabase = (db: any) => {
+    setDataset({ type: DatasetActionType.selectDatabase, payload: db });
+    setResetTables(true);
+  };
+
+  const getTablesList = (url: string) => {
+    SupersetClient.get({ url })
+      .then(({ json }) => {
+        const options: TableOption[] = json.options.map((table: Table) => {
+          const option: TableOption = {
+            value: table.value,
+            label: <TableOption table={table} />,
+            text: table.label,
+          };
+
+          return option;
+        });
+
+        setTableOptions(options);
+        setLoadTables(false);
+        setResetTables(false);
+        setRefresh(false);
+      })
+      .catch(e => {
+        console.log('error', e);
+      });
+  };
+
+  const setSchema = (schema: any) => {
+    if (schema) {
+      setDataset({ type: DatasetActionType.selectSchema, payload: schema });
+      setLoadTables(true);
+    }
+    setResetTables(true);
+  };
+
+  const encodedSchema = encodeURIComponent(schema as string);
+
+  useEffect(() => {
+    if (loadTables) {
+      const endpoint = encodeURI(
+        `/superset/tables/${dbId}/${encodedSchema}/undefined/${refresh}/`,
+      );
+      getTablesList(endpoint);
+    }
+  }, [loadTables]);
+
+  useEffect(() => {
+    if (resetTables) {
+      setTableOptions([]);
+      setResetTables(false);
+    }
+  }, [resetTables]);
+
+  const search = useMemo(

Review Comment:
   this looks really nice!



##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx:
##########
@@ -16,18 +16,204 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import React from 'react';
-import { t } from '@superset-ui/core';
+import React, { useEffect, useState, useMemo } from 'react';
+import { SupersetClient, t, styled, FAST_DEBOUNCE } from '@superset-ui/core';
+import { Input } from 'src/components/Input';
+import { Form } from 'src/components/Form';
+import { TableOption, Table } from 'src/components/TableSelector';
+import RefreshLabel from 'src/components/RefreshLabel';
+import Loading from 'src/components/Loading';
+import DatabaseSelector from 'src/components/DatabaseSelector';
+import { debounce } from 'lodash';
 import { EmptyStateMedium } from 'src/components/EmptyState';
+import { DatasetActionType } from '../types';
+
+interface LeftPanelProps {
+  setDataset: (db: any) => void;
+  schema?: string | undefined | null;
+  dbId?: string;
+}
+
+const LeftPanelStyle = styled.div`
+  ${({ theme }) => `
+  max-width: 350px;
+  padding: ${theme.gridUnit * 4}px;
+  height: 100%;
+  background-color: ${theme.colors.grayscale.light5}; 
+  .refresh {
+    position: absolute;
+    top: 290px;
+    left: 67px;
+    span[role="button"]{
+      font-size: ${theme.gridUnit * 4.25}px;
+    }
+  }
+  .section-title {
+    margin-top: 44px;
+    margin-bottom: 44px;
+    font-weight: ${theme.typography.weights.bold};
+  }
+  .options-list {
+    overflow: auto;
+    max-height: 700px;
+    .options {
+      padding: ${theme.gridUnit * 1.75}px;
+      border-radius: ${theme.borderRadius}px;
+    }
+  }
+  form > span {
+    position: absolute;
+    top: 410px;
+    left: 171px;
+    font-size: 17px;   
+  }
+  .table-form {
+    margin-bottom: ${theme.gridUnit * 8}px;
+  }
+  .loading {
+    position: absolute;
+    bottom: 380px;
+    img {
+      position: absolute;
+      top: -53px;
+      right: -15px;
+      width: 71px;
+    }
+  }
+  }
+`}
+`;
+
+export default function LeftPanel({
+  setDataset,
+  schema,
+  dbId,
+}: LeftPanelProps) {
+  const [tableOptions, setTableOptions] = useState<Array<TableOption>>([]);
+  const [resetTables, setResetTables] = useState(false);
+  const [loadTables, setLoadTables] = useState(false);
+  const [searchVal, setSearchVal] = useState('');
+  const [refresh, setRefresh] = useState(false);
+
+  const setDatabase = (db: any) => {
+    setDataset({ type: DatasetActionType.selectDatabase, payload: db });
+    setResetTables(true);
+  };
+
+  const getTablesList = (url: string) => {
+    SupersetClient.get({ url })
+      .then(({ json }) => {
+        const options: TableOption[] = json.options.map((table: Table) => {
+          const option: TableOption = {
+            value: table.value,
+            label: <TableOption table={table} />,
+            text: table.label,
+          };
+
+          return option;
+        });
+
+        setTableOptions(options);
+        setLoadTables(false);
+        setResetTables(false);
+        setRefresh(false);
+      })
+      .catch(e => {
+        console.log('error', e);
+      });
+  };
+
+  const setSchema = (schema: any) => {
+    if (schema) {
+      setDataset({ type: DatasetActionType.selectSchema, payload: schema });
+      setLoadTables(true);
+    }
+    setResetTables(true);
+  };
+
+  const encodedSchema = encodeURIComponent(schema as string);
+
+  useEffect(() => {
+    if (loadTables) {
+      const endpoint = encodeURI(
+        `/superset/tables/${dbId}/${encodedSchema}/undefined/${refresh}/`,
+      );
+      getTablesList(endpoint);
+    }
+  }, [loadTables]);
+
+  useEffect(() => {
+    if (resetTables) {
+      setTableOptions([]);
+      setResetTables(false);
+    }
+  }, [resetTables]);
+
+  const search = useMemo(
+    () =>
+      debounce((value: string) => {
+        const encodeTableName =
+          value === '' ? undefined : encodeURIComponent(value);
+        const endpoint = encodeURI(
+          `/superset/tables/${dbId}/${encodedSchema}/${encodeTableName}/`,
+        );
+        getTablesList(endpoint);
+      }, FAST_DEBOUNCE),
+    [dbId, encodedSchema],
+  );
 
-export default function LeftPanel() {
   return (
-    <>
-      <EmptyStateMedium
-        image="empty-table.svg"
-        title={t('No database tables found')}
-        description={t('Try selecting a different schema')}
+    <LeftPanelStyle>
+      <p className="section-title db-schema"> Select Database & Schema</p>
+      <DatabaseSelector
+        handleError={() => null}

Review Comment:
   is this how the error is handled in the other DatabaseSelector?



##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx:
##########
@@ -16,18 +16,204 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import React from 'react';
-import { t } from '@superset-ui/core';
+import React, { useEffect, useState, useMemo } from 'react';
+import { SupersetClient, t, styled, FAST_DEBOUNCE } from '@superset-ui/core';
+import { Input } from 'src/components/Input';
+import { Form } from 'src/components/Form';
+import { TableOption, Table } from 'src/components/TableSelector';
+import RefreshLabel from 'src/components/RefreshLabel';
+import Loading from 'src/components/Loading';
+import DatabaseSelector from 'src/components/DatabaseSelector';
+import { debounce } from 'lodash';
 import { EmptyStateMedium } from 'src/components/EmptyState';
+import { DatasetActionType } from '../types';
+
+interface LeftPanelProps {
+  setDataset: (db: any) => void;

Review Comment:
   yeah I think that we have a DatasetObject as an interface 



##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/index.tsx:
##########
@@ -63,14 +64,22 @@ export function datasetReducer(
 export default function AddDataset() {
   // this is commented out for now, but can be commented in as the component

Review Comment:
   we can delete this comment now that we are actually using the reducer :) 



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

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