alexandrusoare commented on code in PR #36540:
URL: https://github.com/apache/superset/pull/36540#discussion_r2618867533


##########
superset-frontend/src/SqlLab/components/QueryTable/index.tsx:
##########
@@ -82,6 +83,15 @@ const QueryTable = ({
 }: QueryTableProps) => {
   const theme = useTheme();
   const dispatch = useDispatch();
+  const [selectedQuery, setSelectedQuery] = useState<QueryResponse | null>(
+    null,
+  );
+  const selectedQueryRef = useRef<QueryResponse | null>(null);
+  const modalRef = useRef<{
+    close: () => void;

Review Comment:
   Why do we use ref for the modal state instead of a simple state?



##########
superset-frontend/src/SqlLab/components/QueryTable/index.tsx:
##########
@@ -365,6 +370,48 @@ const QueryTable = ({
 
   return (
     <div className="QueryTable">
+      <ModalTrigger
+        ref={modalRef}
+        triggerNode={null}
+        className="ResultsModal"
+        modalTitle={t('Data preview')}
+        beforeOpen={() => {
+          const query = selectedQueryRef.current;
+          if (query) {
+            const existingQuery = reduxQueries[query.id];
+            if (!existingQuery?.sql && query.sql) {
+              dispatch(startQuery({ ...query, sql: query.sql }, false));
+            }
+            openAsyncResults(query, displayLimit);
+          }
+        }}
+        onExit={() => {
+          const query = selectedQueryRef.current;
+          if (query) {
+            dispatch(clearQueryResults(query));
+            selectedQueryRef.current = null;
+            setSelectedQuery(null);
+          }
+        }}
+        modalBody={
+          selectedQuery ? (
+            <ModalResultSetWrapper>
+              <ResultSet
+                showSql
+                queryId={selectedQuery.id}
+                displayLimit={displayLimit}
+                defaultQueryLimit={1000}
+                useFixedHeight
+                {...(reduxQueries[selectedQuery.id]?.state ===
+                  QueryState.Success && reduxQueries[selectedQuery.id]?.results
+                  ? { height: Math.floor(window.innerHeight * 0.5) }
+                  : {})}

Review Comment:
   What do you think of having something like this instead? 
   ```
   const height =
     reduxQueries[selectedQuery.id]?.state === QueryState.Success &&
     reduxQueries[selectedQuery.id]?.results
       ? Math.floor(window.innerHeight * 0.5)
       : undefined;
   
   <ResultSet
     showSql
     queryId={selectedQuery.id}
     displayLimit={displayLimit}
     defaultQueryLimit={1000}
     useFixedHeight
     height={height}
   />
   ```
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to