michael-s-molina commented on code in PR #35077:
URL: https://github.com/apache/superset/pull/35077#discussion_r2337577433


##########
superset-frontend/src/core/sqlLab.ts:
##########
@@ -66,34 +213,168 @@ const predicate = (actionType: string): 
AnyListenerPredicate<RootState> => {
 };
 
 export const onDidQueryRun: typeof sqlLabType.onDidQueryRun = (
-  listener: (editor: sqlLabType.Editor) => void,
+  listener: (editor: sqlLabType.QueryRequestContext) => void,
+  thisArgs?: any,
+): Disposable =>
+  createActionListener(
+    predicate(START_QUERY),
+    listener,
+    (action: ReturnType<typeof startQuery>) => {
+      const { query } = action;
+      const {
+        id,
+        dbId,
+        catalog,
+        schema,
+        sql,
+        startDttm,
+        ctas_method: ctasMethod,
+        runAsync,
+        tempTable,
+        templateParams,
+      } = query;
+      const editor = new Editor(sql, dbId, catalog, schema);
+      const panels: Panel[] = []; // TODO: Populate panels
+      const tab = new Tab(query.sqlEditorId, query.tab, editor, panels);
+      return new QueryRequestContext(id, editor, tab, runAsync, startDttm, {
+        ctasMethod,
+        tempTable,
+        templateParams,
+      });
+    },
+    thisArgs,
+  );
+
+export const onDidQuerySuccess: typeof sqlLabType.onDidQuerySuccess = (
+  listener: (query: sqlLabType.QueryResultContext) => void,
   thisArgs?: any,
 ): Disposable =>
   createActionListener(
     predicate(QUERY_SUCCESS),
     listener,
     (action: ReturnType<typeof querySuccess>) => {
+      const { query, results } = action;
+      const {
+        id,
+        dbId,
+        catalog,
+        schema,
+        sql,
+        startDttm,
+        ctas_method: ctasMethod,
+        runAsync,
+        templateParams,
+      } = query;
+      const {
+        query_id: queryId,
+        columns,
+        data,
+        query: { endDttm, executedSql, tempTable, limit, limitingFactor },
+      } = results;
+      const editor = new Editor(sql, dbId, catalog, schema);
+      const panels: Panel[] = []; // TODO: Populate panels
+      const tab = new Tab(query.sqlEditorId, query.tab, editor, panels);
+      return new QueryResultContext(
+        id,
+        queryId,
+        executedSql ?? sql,
+        columns,
+        data,
+        editor,
+        tab,
+        runAsync,
+        startDttm,
+        endDttm,
+        {
+          ctasMethod,
+          tempTable,
+          templateParams,
+          limit,
+          limitingFactor,
+        },
+      );
+    },
+    thisArgs,
+  );
+
+export const onDidQueryStop: typeof sqlLabType.onDidQueryStop = (
+  listener: (query: sqlLabType.QueryRequestContext) => void,
+  thisArgs?: any,
+): Disposable =>
+  createActionListener(
+    predicate(STOP_QUERY),
+    listener,
+    (action: ReturnType<typeof stopQuery>) => {
       const { query } = action;
-      const { dbId, catalog, schema, sql } = query;
-      return new Editor(sql, dbId, catalog, schema);
+      const {
+        id,
+        dbId,
+        catalog,
+        schema,
+        sql,
+        startDttm,
+        ctas_method: ctasMethod,
+        runAsync,
+        tempTable,
+        templateParams,
+      } = query;
+      const editor = new Editor(sql, dbId, catalog, schema);
+      const panels: Panel[] = []; // TODO: Populate panels
+      const tab = new Tab(query.sqlEditorId, query.tab, editor, panels);
+      return new QueryRequestContext(id, editor, tab, runAsync, startDttm, {
+        ctasMethod,
+        tempTable,
+        templateParams,
+      });
     },
     thisArgs,
   );
 
 export const onDidQueryFail: typeof sqlLabType.onDidQueryFail = (
-  listener: (e: string) => void,
+  listener: (query: sqlLabType.QueryErrorResultContext) => void,
   thisArgs?: any,
 ): Disposable =>
   createActionListener(
-    predicate(QUERY_FAILED),
+    action => action.type === QUERY_FAILED,

Review Comment:
   You're totally correct. We need a better way to manage this.



-- 
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-unsubscr...@superset.apache.org

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


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

Reply via email to