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 08:40:17 UTC

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

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


##########
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:
   I actually used `GET /v1/dataset` endpoint at first, but then changed it to `GET /datasource/get/`. As far as I know, Explore now supports (or will soon support?) other sources than datasets, such as SQL queries. Tagging @hughhhh for transparency.
   Also, the `/v1/explore/` endpoint uses `DatasourceDAO` to get datasource and the response from `/v1/dataset` endpoint is missing some fields compared to datasource from `/v1/explore`, which caused some components in Explore to crash



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