You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/08/22 18:00:14 UTC

[superset] 10/19: Fix double requests on modal open, controls disappearing on filter update.

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

diegopucci pushed a commit to branch chore/e2e-tests-drilltodetail-modal
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 8a9d4480148aa4bd34e1ab4cfc090006f0951c1f
Author: Cody Leff <co...@preset.io>
AuthorDate: Wed Aug 10 14:01:07 2022 -0600

    Fix double requests on modal open, controls disappearing on filter update.
---
 .../components/DrillDetailPane/DrillDetailPane.tsx | 64 ++++++++++++----------
 .../components/DrillDetailPane/TableControls.tsx   |  5 +-
 2 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/DrillDetailPane/DrillDetailPane.tsx b/superset-frontend/src/dashboard/components/DrillDetailPane/DrillDetailPane.tsx
index 070c997efa..b92b87a170 100644
--- a/superset-frontend/src/dashboard/components/DrillDetailPane/DrillDetailPane.tsx
+++ b/superset-frontend/src/dashboard/components/DrillDetailPane/DrillDetailPane.tsx
@@ -116,7 +116,7 @@ export default function DrillDetailPane({
   //  Download page of results & trim cache if page not in cache
   const cachePageLimit = Math.ceil(SAMPLES_ROW_LIMIT / PAGE_SIZE);
   useEffect(() => {
-    if (!resultsPages.has(pageIndex)) {
+    if (!isLoading && !resultsPages.has(pageIndex)) {
       setIsLoading(true);
       const jsonPayload = getDrillPayload(formData, filters);
       getDatasourceSamples(
@@ -157,6 +157,7 @@ export default function DrillDetailPane({
     datasourceType,
     filters,
     formData,
+    isLoading,
     pageIndex,
     resultsPages,
   ]);
@@ -185,9 +186,11 @@ export default function DrillDetailPane({
     setResultsPages(new Map());
   }, []);
 
-  //  Render error if page download failed
+  let tableContent = null;
+
   if (responseError) {
-    return (
+    //  Render error if page download failed
+    tableContent = (
       <div
         css={css`
           height: ${theme.gridUnit * 128}px;
@@ -202,11 +205,9 @@ export default function DrillDetailPane({
         </pre>
       </div>
     );
-  }
-
-  //  Render loading if first page hasn't loaded
-  if (!resultsPages.size) {
-    return (
+  } else if (!resultsPages.size) {
+    //  Render loading if first page hasn't loaded
+    tableContent = (
       <div
         css={css`
           height: ${theme.gridUnit * 128}px;
@@ -215,12 +216,10 @@ export default function DrillDetailPane({
         <Loading />
       </div>
     );
-  }
-
-  //  Render empty state if no results are returned for page
-  if (resultsPage?.total === 0) {
+  } else if (resultsPage?.total === 0) {
+    //  Render empty state if no results are returned for page
     const title = t('No rows were returned for this dataset');
-    return (
+    tableContent = (
       <div
         css={css`
           height: ${theme.gridUnit * 128}px;
@@ -229,23 +228,9 @@ export default function DrillDetailPane({
         <EmptyStateMedium image="document.svg" title={title} />
       </div>
     );
-  }
-
-  //  Render chart if at least one page has successfully loaded
-  return (
-    <div
-      css={css`
-        display: flex;
-        flex-direction: column;
-        height: ${theme.gridUnit * 128}px;
-      `}
-    >
-      <TableControls
-        filters={filters}
-        setFilters={setFilters}
-        totalCount={resultsPage?.total}
-        onReload={handleReload}
-      />
+  } else {
+    //  Render table if at least one page has successfully loaded
+    tableContent = (
       <TableView
         columns={sortDisabledColumns}
         data={resultsPage?.data || []}
@@ -266,6 +251,25 @@ export default function DrillDetailPane({
           overflow: scroll;
         `}
       />
+    );
+  }
+
+  return (
+    <div
+      css={css`
+        display: flex;
+        flex-direction: column;
+        height: ${theme.gridUnit * 128}px;
+      `}
+    >
+      <TableControls
+        filters={filters}
+        setFilters={setFilters}
+        totalCount={resultsPage?.total}
+        loading={isLoading}
+        onReload={handleReload}
+      />
+      {tableContent}
     </div>
   );
 }
diff --git a/superset-frontend/src/dashboard/components/DrillDetailPane/TableControls.tsx b/superset-frontend/src/dashboard/components/DrillDetailPane/TableControls.tsx
index 0be301de46..96badcc157 100644
--- a/superset-frontend/src/dashboard/components/DrillDetailPane/TableControls.tsx
+++ b/superset-frontend/src/dashboard/components/DrillDetailPane/TableControls.tsx
@@ -33,12 +33,13 @@ export default function TableControls({
   filters,
   setFilters,
   totalCount,
+  loading,
   onReload,
 }: {
   filters: BinaryQueryObjectFilterClause[];
   setFilters: (filters: BinaryQueryObjectFilterClause[]) => void;
   totalCount?: number;
-  loading?: boolean;
+  loading: boolean;
   onReload: () => void;
 }) {
   const theme = useTheme();
@@ -120,7 +121,7 @@ export default function TableControls({
           height: min-content;
         `}
       >
-        <RowCountLabel rowcount={totalCount} />
+        <RowCountLabel loading={loading && !totalCount} rowcount={totalCount} />
         <Icons.ReloadOutlined
           iconColor={theme.colors.grayscale.light1}
           iconSize="l"