You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2025/11/17 23:59:26 UTC

Re: [PR] fix(view-query): Add ownState parameter to ViewQueryModal for query consistency [superset]

Copilot commented on code in PR #35208:
URL: https://github.com/apache/superset/pull/35208#discussion_r2535869005


##########
superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx:
##########
@@ -140,6 +140,8 @@ export interface SliceHeaderControlsProps {
   supersetCanCSV?: boolean;
 
   crossFiltersEnabled?: boolean;
+
+  ownState?: object;

Review Comment:
   The type `object` is too generic for TypeScript. Use `JsonObject` instead (imported from `@superset-ui/core`) to maintain type consistency with other parts of the codebase where `ownState` is used (e.g., `Chart.tsx` line 78, `ExploreChartPanel/index.tsx` line 66). This provides better type safety and aligns with established patterns.



##########
superset-frontend/src/explore/components/controls/ViewQueryModal.tsx:
##########
@@ -76,7 +78,7 @@ const ViewQueryModal: FC<Props> = ({ latestQueryFormData }) => {
   };
   useEffect(() => {
     loadChartData('query');
-  }, [JSON.stringify(latestQueryFormData)]);
+  }, [JSON.stringify(latestQueryFormData), JSON.stringify(ownState)]);

Review Comment:
   Using `JSON.stringify()` in dependency arrays is an anti-pattern that creates new string references on every render, causing unnecessary re-executions. Additionally, `loadChartData` is defined inside the component but not included in the dependency array, which violates the exhaustive-deps rule.
   
   Consider using `useMemo` to memoize the stringified values, or better yet, restructure to avoid this pattern:
   
   ```typescript
   const loadChartData = useCallback((resultType: string) => {
     setIsLoading(true);
     getChartDataRequest({
       formData: latestQueryFormData,
       resultFormat: 'json',
       resultType,
       ownState: ownState || {},
     })
       // ... rest of the implementation
   }, [latestQueryFormData, ownState]);
   
   useEffect(() => {
     loadChartData('query');
   }, [loadChartData]);
   ```
   
   This approach properly tracks dependencies without the overhead of JSON stringification.



##########
superset-frontend/src/dashboard/components/SliceHeader/index.tsx:
##########
@@ -57,6 +57,7 @@ type SliceHeaderProps = SliceHeaderControlsProps & {
   filters: object;
   handleToggleFullSize: () => void;
   formData: object;
+  ownState?: object;

Review Comment:
   The type `object` is too generic for TypeScript. Use `JsonObject` instead (imported from `@superset-ui/core`) to maintain type consistency with other parts of the codebase where `ownState` is used. This provides better type safety and aligns with established patterns.



##########
superset-frontend/src/explore/components/controls/ViewQueryModal.tsx:
##########
@@ -31,6 +31,7 @@ import ViewQuery from 'src/explore/components/controls/ViewQuery';
 
 interface Props {
   latestQueryFormData: QueryFormData;
+  ownState?: object;

Review Comment:
   The type `object` is too generic for TypeScript. Use `JsonObject` instead (imported from `@superset-ui/core`) to maintain type consistency with other parts of the codebase where `ownState` is used (e.g., `Chart.tsx` line 78). This provides better type safety and aligns with established patterns.
   
   ```typescript
   import {
     styled,
     ensureIsArray,
     t,
     getClientErrorObject,
     QueryFormData,
     JsonObject,
   } from '@superset-ui/core';
   
   interface Props {
     latestQueryFormData: QueryFormData;
     ownState?: JsonObject;
   }
   ```
   ```suggestion
     ownState?: JsonObject;
   ```



##########
superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.jsx:
##########
@@ -497,7 +497,10 @@ export const useExploreAdditionalActionsMenu = (
           }
           modalTitle={t('View query')}
           modalBody={
-            <ViewQueryModal latestQueryFormData={latestQueryFormData} />
+            <ViewQueryModal
+              latestQueryFormData={latestQueryFormData}
+              ownState={ownState}
+            />

Review Comment:
   The `ownState` dependency is missing from the `useMemo` dependency array. Since `ownState` is now used in the `ViewQueryModal` component within this memoized menu, it should be included in the dependency array to ensure the menu is re-created when `ownState` changes. Add `ownState` to the dependency array at line 548.



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