zhaoyongjie commented on code in PR #20498: URL: https://github.com/apache/superset/pull/20498#discussion_r917209583
########## superset-frontend/src/explore/ExplorePage.tsx: ########## @@ -16,50 +16,58 @@ * specific language governing permissions and limitations * under the License. */ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { useDispatch } from 'react-redux'; +import { useLocation } from 'react-router-dom'; import { makeApi, t } from '@superset-ui/core'; import Loading from 'src/components/Loading'; +import { addDangerToast } from 'src/components/MessageToasts/actions'; +import { isNullish } from 'src/utils/common'; +import { getUrlParam } from 'src/utils/urlUtils'; +import { URL_PARAMS } from 'src/constants'; import { getParsedExploreURLParams } from './exploreUtils/getParsedExploreURLParams'; import { hydrateExplore } from './actions/hydrateExplore'; import ExploreViewContainer from './components/ExploreViewContainer'; import { ExploreResponsePayload } from './types'; import { fallbackExploreInitialData } from './fixtures'; -import { addDangerToast } from '../components/MessageToasts/actions'; -import { isNullish } from '../utils/common'; const loadErrorMessage = t('Failed to load chart data.'); -const fetchExploreData = () => { - const exploreUrlParams = getParsedExploreURLParams(); - return makeApi<{}, ExploreResponsePayload>({ +const fetchExploreData = (exploreUrlParams: URLSearchParams) => + makeApi<{}, ExploreResponsePayload>({ method: 'GET', endpoint: 'api/v1/explore/', })(exploreUrlParams); -}; const ExplorePage = () => { const [isLoaded, setIsLoaded] = useState(false); + const isExploreInitialized = useRef(false); const dispatch = useDispatch(); + const location = useLocation(); useEffect(() => { - fetchExploreData() - .then(({ result }) => { - if (isNullish(result.dataset?.id) && isNullish(result.dataset?.uid)) { + const exploreUrlParams = getParsedExploreURLParams(location); + const isSaveAction = !!getUrlParam(URL_PARAMS.saveAction); + if (!isExploreInitialized.current || isSaveAction) { + fetchExploreData(exploreUrlParams) + .then(({ result }) => { + if (isNullish(result.dataset?.id) && isNullish(result.dataset?.uid)) { + dispatch(hydrateExplore(fallbackExploreInitialData)); + dispatch(addDangerToast(loadErrorMessage)); + } else { + dispatch(hydrateExplore(result)); + } + }) Review Comment: The same logic, only optimized for readability. -- 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