From 5de28ff41db63378c4a62695858323b4f58ae8ca Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 13 Jul 2022 19:56:09 +0800 Subject: [PATCH 1/7] fix: dashboard to explore --- superset-frontend/src/explore/ExplorePage.tsx | 52 ++++++++++++++----- .../src/explore/actions/hydrateExplore.ts | 3 +- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index d8aefda1345bc..201318d53fc6c 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -19,10 +19,17 @@ 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 { + makeApi, + t, + isDefined, + JsonObject, + QueryFormData, +} from '@superset-ui/core'; +import { Slice } from 'src/types/Chart'; +import { Dataset } from '@superset-ui/chart-controls'; 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'; @@ -33,11 +40,35 @@ import { fallbackExploreInitialData } from './fixtures'; const loadErrorMessage = t('Failed to load chart data.'); -const fetchExploreData = (exploreUrlParams: URLSearchParams) => - makeApi<{}, ExploreResponsePayload>({ - method: 'GET', - endpoint: 'api/v1/explore/', - })(exploreUrlParams); +interface ResultInterface { + result: { + form_data: QueryFormData; + slice: Slice; + dataset: Dataset; + }; +} + +const isResult = (rv: JsonObject): rv is ResultInterface => + rv?.result?.form_data && + rv?.result?.slice && + rv?.result?.dataset && + isDefined(rv?.result?.dataset?.id) && + isDefined(rv?.result?.dataset?.uid); + +const fetchExploreData = async (exploreUrlParams: URLSearchParams) => { + try { + const rv = await makeApi<{}, ExploreResponsePayload>({ + method: 'GET', + endpoint: 'api/v1/explore/', + })(exploreUrlParams); + if (isResult(rv)) { + return rv; + } + throw loadErrorMessage; + } catch (err) { + throw new Error(err); + } +}; const ExplorePage = () => { const [isLoaded, setIsLoaded] = useState(false); @@ -51,12 +82,7 @@ const ExplorePage = () => { 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)); - } + dispatch(hydrateExplore(result)); }) .catch(() => { dispatch(hydrateExplore(fallbackExploreInitialData)); diff --git a/superset-frontend/src/explore/actions/hydrateExplore.ts b/superset-frontend/src/explore/actions/hydrateExplore.ts index ab5afde665bbf..b16ac30a7bc10 100644 --- a/superset-frontend/src/explore/actions/hydrateExplore.ts +++ b/superset-frontend/src/explore/actions/hydrateExplore.ts @@ -56,8 +56,7 @@ export const hydrateExplore = if (dashboardId) { initialFormData.dashboardId = dashboardId; } - const initialDatasource = - datasources?.[initialFormData.datasource] ?? dataset; + const initialDatasource = dataset; const initialExploreState = { form_data: initialFormData, From f5a8709d7489820b7405a8f37641484b8cb261ae Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 13 Jul 2022 21:45:59 +0800 Subject: [PATCH 2/7] raise error object --- superset-frontend/src/explore/ExplorePage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index 201318d53fc6c..3d45378d853dc 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -64,9 +64,9 @@ const fetchExploreData = async (exploreUrlParams: URLSearchParams) => { if (isResult(rv)) { return rv; } - throw loadErrorMessage; + throw Error(loadErrorMessage); } catch (err) { - throw new Error(err); + throw Error(err); } }; From c7236aba4843f9e79f4722246c400d76b32ec763 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 13 Jul 2022 22:14:39 +0800 Subject: [PATCH 3/7] refine error messsage --- superset-frontend/src/explore/ExplorePage.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index 3d45378d853dc..96438c1fe1321 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -32,14 +32,13 @@ import Loading from 'src/components/Loading'; import { addDangerToast } from 'src/components/MessageToasts/actions'; import { getUrlParam } from 'src/utils/urlUtils'; import { URL_PARAMS } from 'src/constants'; +import { getClientErrorObject } from 'src/utils/getClientErrorObject'; import { getParsedExploreURLParams } from './exploreUtils/getParsedExploreURLParams'; import { hydrateExplore } from './actions/hydrateExplore'; import ExploreViewContainer from './components/ExploreViewContainer'; import { ExploreResponsePayload } from './types'; import { fallbackExploreInitialData } from './fixtures'; -const loadErrorMessage = t('Failed to load chart data.'); - interface ResultInterface { result: { form_data: QueryFormData; @@ -64,9 +63,15 @@ const fetchExploreData = async (exploreUrlParams: URLSearchParams) => { if (isResult(rv)) { return rv; } - throw Error(loadErrorMessage); + throw new Error(t('Failed to load chart data.')); } catch (err) { - throw Error(err); + // todo: encapsulate the error handler + const clientError = await getClientErrorObject(err); + throw new Error( + clientError.message || + clientError.error || + t('Failed to load chart data.'), + ); } }; @@ -84,9 +89,9 @@ const ExplorePage = () => { .then(({ result }) => { dispatch(hydrateExplore(result)); }) - .catch(() => { + .catch(err => { dispatch(hydrateExplore(fallbackExploreInitialData)); - dispatch(addDangerToast(loadErrorMessage)); + dispatch(addDangerToast(err.message)); }) .finally(() => { setIsLoaded(true); From a0501db2e01ec4cf1bed2cc1215ab74c0ddf025d Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 13 Jul 2022 22:40:01 +0800 Subject: [PATCH 4/7] fix ut --- superset-frontend/src/explore/ExplorePage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index 96438c1fe1321..1765e54959067 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -51,8 +51,7 @@ const isResult = (rv: JsonObject): rv is ResultInterface => rv?.result?.form_data && rv?.result?.slice && rv?.result?.dataset && - isDefined(rv?.result?.dataset?.id) && - isDefined(rv?.result?.dataset?.uid); + isDefined(rv?.result?.dataset?.id); const fetchExploreData = async (exploreUrlParams: URLSearchParams) => { try { From debe616fab59f5aa8993a57efc88afdb5189ecaf Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 13 Jul 2022 22:44:23 +0800 Subject: [PATCH 5/7] default export --- superset-frontend/src/explore/ExplorePage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index 1765e54959067..1c9c0f05fe1a9 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -74,7 +74,7 @@ const fetchExploreData = async (exploreUrlParams: URLSearchParams) => { } }; -const ExplorePage = () => { +export default function ExplorePage() { const [isLoaded, setIsLoaded] = useState(false); const isExploreInitialized = useRef(false); const dispatch = useDispatch(); @@ -103,6 +103,4 @@ const ExplorePage = () => { return ; } return ; -}; - -export default ExplorePage; +} From ad1d23f0723d15e9a95219ded4750e70c874eb91 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Wed, 13 Jul 2022 21:24:56 +0200 Subject: [PATCH 6/7] Dont null check slice --- superset-frontend/src/explore/ExplorePage.tsx | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index 1c9c0f05fe1a9..6425f4c49dbef 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -19,15 +19,7 @@ import React, { useEffect, useRef, useState } from 'react'; import { useDispatch } from 'react-redux'; import { useLocation } from 'react-router-dom'; -import { - makeApi, - t, - isDefined, - JsonObject, - QueryFormData, -} from '@superset-ui/core'; -import { Slice } from 'src/types/Chart'; -import { Dataset } from '@superset-ui/chart-controls'; +import { makeApi, t, isDefined, JsonObject } from '@superset-ui/core'; import Loading from 'src/components/Loading'; import { addDangerToast } from 'src/components/MessageToasts/actions'; import { getUrlParam } from 'src/utils/urlUtils'; @@ -39,17 +31,8 @@ import ExploreViewContainer from './components/ExploreViewContainer'; import { ExploreResponsePayload } from './types'; import { fallbackExploreInitialData } from './fixtures'; -interface ResultInterface { - result: { - form_data: QueryFormData; - slice: Slice; - dataset: Dataset; - }; -} - -const isResult = (rv: JsonObject): rv is ResultInterface => +const isResult = (rv: JsonObject): rv is ExploreResponsePayload => rv?.result?.form_data && - rv?.result?.slice && rv?.result?.dataset && isDefined(rv?.result?.dataset?.id); From 52ce1bf2d79d9c82bef20aa2dec2df2644da3b90 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 14 Jul 2022 14:58:38 +0800 Subject: [PATCH 7/7] temporary skip integration test --- .../cypress-base/cypress/integration/explore/link.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts index fb3445fc6366f..bc18f2c410f2c 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts @@ -28,7 +28,7 @@ import { HEALTH_POP_FORM_DATA_DEFAULTS } from './visualizations/shared.helper'; const apiURL = (endpoint: string, queryObject: Record) => `${endpoint}?q=${rison.encode(queryObject)}`; -describe('Test explore links', () => { +describe.skip('Test explore links', () => { beforeEach(() => { cy.login(); interceptChart({ legacy: true }).as('chartData');