Skip to content

Commit 8a02f58

Browse files
committed
fix: [FIXUP]
1 parent 301a41a commit 8a02f58

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/charts/SupersetReport/SupersetReport.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ import { embedDashboard } from '@superset-ui/embedded-sdk';
77
import { PowerBIUtils } from '@cosmotech/azure';
88
import { useDashboardPlaceholder } from '../DashboardPlaceholder/useDashboardPlaceholder';
99

10+
export const SUPERSET_GUEST_TOKEN_STATUS = {
11+
IDLE: 'IDLE',
12+
LOADING: 'LOADING',
13+
ERROR: 'ERROR',
14+
SUCCESS: 'SUCCESS',
15+
};
16+
1017
export const SupersetReport = ({
1118
alwaysShowReports = false,
1219
disabled = false,
20+
isParentLoading = false,
1321
downloadLogsFile,
1422
guestToken,
15-
isLoading = false,
1623
noDashboardConfigured = false,
1724
labels,
1825
options,
@@ -22,21 +29,23 @@ export const SupersetReport = ({
2229
visibleScenarios,
2330
}) => {
2431
const containerRef = useRef(null);
25-
const tokenRef = useRef(guestToken);
32+
const tokenRef = useRef(null);
2633
const [isEmbedded, setIsEmbedded] = useState(false);
2734
const [dashboard, setDashboard] = useState(null);
2835

2936
const { getDashboardPlaceholder } = useDashboardPlaceholder();
3037

3138
useEffect(() => {
32-
tokenRef.current = guestToken;
33-
}, [guestToken]);
39+
if (guestToken?.status !== SUPERSET_GUEST_TOKEN_STATUS.SUCCESS) return;
40+
41+
tokenRef.current = guestToken?.value;
42+
}, [guestToken?.status, guestToken?.value]);
3443

3544
useEffect(() => {
3645
if (!report?.id || !options?.supersetUrl) return;
3746

3847
const loadSuperset = async () => {
39-
if (isEmbedded || guestToken == null || guestToken === '') return;
48+
if (isEmbedded || guestToken?.status !== SUPERSET_GUEST_TOKEN_STATUS.SUCCESS) return;
4049

4150
try {
4251
const embedded = await embedDashboard({
@@ -92,7 +101,11 @@ export const SupersetReport = ({
92101
const containerHeight = isReportVisible ? (report?.height ?? style?.height ?? '800px') : '100%';
93102
const containerWidth = isReportVisible ? (report?.width ?? style?.width ?? '100%') : '100%';
94103
const reportContainerDisplay = isReportVisible ? undefined : 'none';
95-
const showLoadingSpinner = placeholder == null && (isLoading || !isEmbedded);
104+
const showLoadingSpinner =
105+
!isParentLoading &&
106+
guestToken?.status !== SUPERSET_GUEST_TOKEN_STATUS.ERROR &&
107+
placeholder == null &&
108+
(!isEmbedded || guestToken?.status === SUPERSET_GUEST_TOKEN_STATUS.LOADING);
96109

97110
return (
98111
<Box sx={{ position: 'relative', width: containerWidth, height: containerHeight, overflow: 'hidden' }}>
@@ -115,9 +128,12 @@ export const SupersetReport = ({
115128
SupersetReport.propTypes = {
116129
alwaysShowReports: PropTypes.bool,
117130
disabled: PropTypes.bool,
131+
isParentLoading: PropTypes.bool,
118132
downloadLogsFile: PropTypes.func,
119-
guestToken: PropTypes.string.isRequired,
120-
isLoading: PropTypes.bool,
133+
// guestToken: object with shape {value, status}
134+
// - value: (string) token value
135+
// - status: (string) status of the token retrieval process ("IDLE", "LOADING", "ERROR", "SUCCESS")
136+
guestToken: PropTypes.shape({ value: PropTypes.string.isRequired, status: PropTypes.string.isRequired }).isRequired,
121137
labels: PropTypes.object,
122138
noDashboardConfigured: PropTypes.bool,
123139
options: PropTypes.shape({ supersetUrl: PropTypes.string.isRequired }).isRequired,

0 commit comments

Comments
 (0)