Skip to content

Commit

Permalink
fix: delay loading of unfocused dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Aug 30, 2024
1 parent 9ed870b commit 9aa5d25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions platform_plugin_aspects/static/js/embed_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ async function fetchGuestToken() {
return data.guestToken;
}

function embedDashboard(dashboard_uuid, superset_url, xblock_id) {
xblock_id = xblock_id || "";

function _embedDashboard(dashboard_uuid, superset_url, xblock_id){
window.supersetEmbeddedSdk
.embedDashboard({
id: dashboard_uuid, // given by the Superset embedding UI
Expand All @@ -70,10 +68,26 @@ function embedDashboard(dashboard_uuid, superset_url, xblock_id) {
when the dashboard is loaded
*/
});
}

function embedDashboard(dashboard, superset_url, xblock_id, index) {
xblock_id = xblock_id || "";
let radio = document.querySelector(`#tab-${index+1}`)
if (index == 0){
dashboard.loaded = true;
_embedDashboard(dashboard.uuid, superset_url, xblock_id)
}
radio.addEventListener("change", () => {
if (dashboard.loaded){
return
}
dashboard.loaded = true;
_embedDashboard(dashboard.uuid, superset_url, xblock_id)
});
};

if (window.superset_dashboards !== undefined) {
window.superset_dashboards.forEach(function(dashboard) {
embedDashboard(dashboard.uuid, window.superset_url, dashboard.uuid);
window.superset_dashboards.forEach(function(dashboard, i) {
embedDashboard(dashboard, window.superset_url, dashboard.uuid, i);
});
}
2 changes: 1 addition & 1 deletion platform_plugin_aspects/static/js/superset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function SupersetXBlock(runtime, element, context) {
window.from_xblock = true;

function initSuperset(supersetEmbeddedSdk) {
embedDashboard(dashboard_uuid, superset_url, xblock_id);
_embedDashboard(dashboard_uuid, superset_url, xblock_id);
}

if (typeof require === "function") {
Expand Down

0 comments on commit 9aa5d25

Please sign in to comment.