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 2021/06/15 19:09:11 UTC

[GitHub] [superset] etr2460 commented on a change in pull request #15109: fix: SQL Lab show "Refetch Results" button while fetching new query results

etr2460 commented on a change in pull request #15109:
URL: https://github.com/apache/superset/pull/15109#discussion_r652067785



##########
File path: superset-frontend/src/SqlLab/reducers/sqlLab.js
##########
@@ -517,7 +517,23 @@ export default function sqlLabReducer(state = {}, action) {
           if (changedQuery.changedOn > queriesLastUpdate) {
             queriesLastUpdate = changedQuery.changedOn;
           }
-          newQueries[id] = { ...state.queries[id], ...changedQuery };
+          const prevState = state.queries[id].state;
+          const currentState = changedQuery.state;
+          let updatedState = {
+            ...changedQuery,
+          };
+          if (currentState === 'success') {
+            // race condition:
+            // because of asyc behavior, sql lab may still poll a couple of seconds

Review comment:
       sp nit: `async` 

##########
File path: superset-frontend/src/SqlLab/reducers/sqlLab.js
##########
@@ -517,7 +517,23 @@ export default function sqlLabReducer(state = {}, action) {
           if (changedQuery.changedOn > queriesLastUpdate) {
             queriesLastUpdate = changedQuery.changedOn;
           }
-          newQueries[id] = { ...state.queries[id], ...changedQuery };
+          const prevState = state.queries[id].state;
+          const currentState = changedQuery.state;
+          let updatedState = {
+            ...changedQuery,
+          };
+          if (currentState === 'success') {
+            // race condition:
+            // because of asyc behavior, sql lab may still poll a couple of seconds
+            // when it started fetching or finished rendering results
+            if (['fetching', 'success'].includes(prevState)) {
+              updatedState = {
+                ...updatedState,
+                state: prevState,
+              };
+            }
+          }
+          newQueries[id] = { ...state.queries[id], ...updatedState };

Review comment:
       perhaps something like this is cleaner?
   
   ```suggestion
             newQueries[id] = {
               ...state.queries[id],
               ...changedQuery,
               // race condition:
               // because of async behavior, sql lab may still poll a couple of seconds
               // when it started fetching or finished rendering results
               state: currentState === 'success' && ['fetching', 'success'].includes(prevState) ? prevState : currentState
             };
   ```




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