Skip to content

Commit 9ae59e8

Browse files
committed
fix: [PROD-14867] handle refresh for superset guest tokens
fix: [PROD-14867] handle refresh for superset guest tokens
1 parent 9676e10 commit 9ae59e8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/charts/SupersetEmbed/SupersetEmbed.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ export const SupersetEmbed = ({
1313
options,
1414
}) => {
1515
const containerRef = useRef(null);
16+
const tokenRef = useRef(guestToken);
1617
const [isEmbedded, setIsEmbedded] = useState(false);
18+
const [dashboard, setDashboard] = useState(null);
1719

1820
useEffect(() => {
19-
const loadSuperset = async () => {
20-
if (!guestToken || !report?.id || !options?.supersetUrl) return;
21+
tokenRef.current = guestToken;
22+
}, [guestToken]);
23+
24+
useEffect(() => {
25+
if (!report?.id || !options?.supersetUrl) return;
2126

27+
const loadSuperset = async () => {
2228
try {
23-
setIsEmbedded(false);
24-
await embedDashboard({
29+
const embedded = await embedDashboard({
2530
id: report.id,
2631
supersetDomain: options.supersetUrl,
2732
mountPoint: containerRef.current,
28-
fetchGuestToken: async () => guestToken,
33+
fetchGuestToken: async () => tokenRef.current,
2934
dashboardUiConfig: report?.uiConfig || {},
3035
});
36+
setDashboard(embedded);
3137
setIsEmbedded(true);
3238
} catch (error) {
3339
console.error('Superset embedding failed:', error);
@@ -40,7 +46,12 @@ export const SupersetEmbed = ({
4046
containerRef.current.children[0].style.width = '100%';
4147
containerRef.current.children[0].style.height = '100%';
4248
}
43-
}, [guestToken, report, options]);
49+
50+
return () => {
51+
if (dashboard?.destroy) dashboard.destroy();
52+
};
53+
// eslint-disable-next-line react-hooks/exhaustive-deps
54+
}, [report.id, options.supersetUrl]);
4455

4556
return (
4657
<Box

0 commit comments

Comments
 (0)