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