Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: embedded dashboards configuration error ui #3247

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
11 changes: 9 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2025-03-18T14:27:12.993Z\n"
"PO-Revision-Date: 2025-03-18T14:27:12.995Z\n"
"POT-Creation-Date: 2025-03-25T09:19:02.226Z\n"
"PO-Revision-Date: 2025-03-25T09:19:02.226Z\n"

msgid "Untitled dashboard"
msgstr "Untitled dashboard"
Expand Down Expand Up @@ -742,6 +742,13 @@ msgid_plural "{{count}} filters active"
msgstr[0] "{{count}} filter active"
msgstr[1] "{{count}} filters active"

msgid ""
"There was a problem loading the embedded dashboard content from an external "
"service"
msgstr ""
"There was a problem loading the embedded dashboard content from an external "
"service"

msgid "Fetching external dashboard"
msgstr "Fetching external dashboard"

Expand Down
17 changes: 14 additions & 3 deletions src/components/SystemSettingsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ const SystemSettingsProvider = ({ children }) => {
...renameSystemSettings(systemSettings),
}
if (resolvedSystemSettings.embeddedDashboardsEnabled) {
resolvedSystemSettings.supersetBaseUrl =
await fetchSupersetBaseUrl()
try {
resolvedSystemSettings.supersetBaseUrl =
await fetchSupersetBaseUrl()
} catch {
resolvedSystemSettings.supersetBaseUrl = null
}
}

setSettings(resolvedSystemSettings)
Expand Down Expand Up @@ -64,7 +68,14 @@ export const useIsSupersetSupported = () => {
const {
systemSettings: { embeddedDashboardsEnabled, supersetBaseUrl },
} = useSystemSettings()
return embeddedDashboardsEnabled && !!supersetBaseUrl

return (
embeddedDashboardsEnabled &&
// A populated string if a response was received from the Superset Gateway
((typeof supersetBaseUrl === 'string' && supersetBaseUrl.length > 0) ||
// Or `null` if it was not possible to retreive the baseUrl
supersetBaseUrl === null)
)
}
export const useSupersetBaseUrl = () => {
const {
Expand Down
35 changes: 31 additions & 4 deletions src/pages/view/SupersetDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,26 @@ const reducer = (state, action) => {
}
}

class SupersetGatewayUnavailableError extends Error {
constructor() {
super(
i18n.t(
'There was a problem loading the embedded dashboard content from an external service'
)
)
}
}

export const SupersetDashboard = () => {
const isMountedRef = useRef(false)
const [{ loading, error, success }, dispatch] = useReducer(
reducer,
initialLoadState
)
// For errors with an error code a retry will fail
const allowRetry = error && !error.errorCode
const allowRetry =
error &&
!(error.errorCode || error instanceof SupersetGatewayUnavailableError)
const ref = useRef(null)
const selectedId = useSelector(sGetSelectedId)
const embedData = useSelector(msGetSelectedSupersetEmbedData)
Expand Down Expand Up @@ -74,14 +87,28 @@ export const SupersetDashboard = () => {
}, [embedData, postSupersetGuestToken, supersetDomain])

useEffect(() => {
if (loading || success || error) {
if (loading || success || error || !supersetDomain) {
return
}
loadSupersetDashboard()
}, [loading, error, success, loadSupersetDashboard])
}, [loading, error, success, loadSupersetDashboard, supersetDomain])

useEffect(() => {
if (!supersetDomain) {
dispatch({
type: LOAD_ERROR,
payload: new SupersetGatewayUnavailableError(),
})
}
}, [supersetDomain])

useEffect(() => {
dispatch({ type: LOAD_RESET })
if (isMountedRef.current) {
dispatch({ type: LOAD_RESET })
} else {
// Prevent calling load reset when component mounts
isMountedRef.current = true
}
}, [embedData])

return (
Expand Down
15 changes: 0 additions & 15 deletions src/reducers/selected.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ export const sGetSelectedId = (state) => sGetSelected(state).id

export const sGetSelectedIsEmbedded = (state) => !!sGetSelected(state).embedded

export const sGetSelectedSupersetEmbedData = (state) => {
const embedData = sGetSelected(state).embedded
return {
id: embedData.id,
dashboardUiConfig: {
hideTitle: true,
hideTab: true,
hideChartControls: embedData.options.hideChartControls,
filters: {
visible: true,
expanded: embedData.options.filters.expanded,
},
},
}
}
export const msGetSelectedSupersetEmbedData = createSelector(
[
(state) => state.selected.embedded?.id,
Expand Down
Loading