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 2022/07/12 06:40:56 UTC

[GitHub] [superset] zhaoyongjie commented on a diff in pull request #20668: feat: Reuse Dashboard redux data in Explore

zhaoyongjie commented on code in PR #20668:
URL: https://github.com/apache/superset/pull/20668#discussion_r918600221


##########
superset-frontend/src/explore/ExplorePage.tsx:
##########
@@ -38,12 +45,58 @@ const fetchExploreData = () => {
   })(exploreUrlParams);
 };
 
+const useExploreInitialData = (
+  shouldUseDashboardData: boolean,
+  sliceId: string | null,
+) => {
+  const slice = useSelector<RootState, Slice | null>(({ sliceEntities }) =>
+    isDefined(sliceId) ? sliceEntities?.slices?.[sliceId] : null,
+  );
+  const formData = slice?.form_data;
+  const { id: datasourceId, type: datasourceType } = useSelector<
+    RootState,
+    { id: number | undefined; type: string | undefined }
+  >(({ datasources }) =>
+    formData?.datasource
+      ? pick(datasources[formData.datasource], ['id', 'type'])
+      : { id: undefined, type: undefined },
+  );
+  return useCallback(() => {
+    if (
+      !shouldUseDashboardData ||
+      !isDefined(slice) ||
+      !isDefined(formData) ||
+      !isDefined(datasourceId) ||
+      !isDefined(datasourceType)
+    ) {
+      return fetchExploreData();
+    }
+    return SupersetClient.get({
+      endpoint: `/datasource/get/${datasourceType}/${datasourceId}/`,

Review Comment:
   there is a new endpoint for the dataset GET method is `/api/v1/dataset/<datasource PK(a.k.a datasource id without type>`. I added it at [here](https://github.com/apache/superset/pull/20677/files#diff-cc681838b8b8b6cb3d1a5dbf02c118d5f3353db8023f49c55f7a673e879be030)
   



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