Joaquim Grilo
06/26/2025, 1:10 PMJoaquim Grilo
06/26/2025, 1:11 PMDustin Chilson
06/26/2025, 1:12 PMJoaquim Grilo
06/26/2025, 1:12 PMMauricio Cabezas
06/26/2025, 1:12 PMAnant Dalela
06/26/2025, 1:19 PMAnant Dalela
06/26/2025, 1:21 PMFilip Charikov
06/26/2025, 1:46 PMMax Donsky
06/26/2025, 1:47 PMJoaquim Grilo
06/26/2025, 1:52 PMJoaquim Grilo
06/26/2025, 1:52 PMJakub Kopecky
06/26/2025, 2:42 PMJoaquim Grilo
06/26/2025, 2:50 PMJakub Kopecky
06/26/2025, 2:55 PMMauricio Cabezas
06/26/2025, 3:09 PMJoaquim Grilo
06/26/2025, 3:12 PMMauricio Cabezas
06/26/2025, 3:18 PMJoaquim Grilo
06/26/2025, 3:20 PMJoaquim Grilo
06/26/2025, 3:59 PMMauricio Cabezas
06/26/2025, 4:07 PMJoaquim Grilo
06/26/2025, 5:18 PMJoaquim Grilo
06/26/2025, 5:39 PMexport class DashboardEmbedComponent implements OnInit {
dashboardId: string = '';
dashboardFilters = [];
contact_support = `Dashboard is not configured for this customer yet. Please <a href='<https://help.xxx.io>'>contact support</a> if you have questions.`;
gdDashboardLoading$ = new BehaviorSubject<boolean>(true);
dashboardConfigured = signal(false);
spinnerClasses = signal('contained');
constructor(
private userSvc: UserService,
private renderer: Renderer2,
private globalDashboardSvc: GlobalDashboardService
) {
}
onDashboardLoaded(e: Event) {
const detail = (e as CustomEvent).detail;
const filters = detail?.dashboard?.filterContext?.filters;
if (Array.isArray(filters)) {
this.dashboardFilters.push(...filters);
}
}
onDashboardFilterChange(e: Event) {
const detail = (e as CustomEvent).detail;
const filters = detail?.dashboard?.filterContext?.filters;
if (Array.isArray(filters)) {
this.dashboardFilters.push(...filters);
}
}
ngOnInit(): void {
this.globalDashboardSvc.activeDashboardSubject$
.pipe(
distinctUntilChanged((prevDashboard, currDashboard) => JSON.stringify(prevDashboard) === JSON.stringify(currDashboard)),
tap(dashboard => {
if(!dashboard) {
this.dashboardConfigured.set(false);
this.gdDashboardLoading$.next(false);
}
}),
filter(dashboard => !!dashboard),
untilDestroyed(this),
)
.subscribe(dashboard => {
this.dashboardId = dashboard?.dashId;
this.authenticateAndInjectGdScript(dashboard?.workspaceId);
})
this.globalDashboardSvc.activeCustomer$.pipe(
filter(customer => !!customer),
untilDestroyed(this),
).subscribe(customer => {
if(customer?.enableLegacyDashboard) {
this.gdDashboardLoading$.next(false);
this.dashboardConfigured.set(false);
}
})
}
cleanUpGdElements() {
// Clean up existing elements
document.getElementById('customDashScript')?.remove();
document.getElementById('gdElement')?.remove();
}
authenticateAndInjectGdScript(workspaceId: string) {
this.userSvc.getStoredOrNewToken$()
.pipe(
distinctUntilChanged(),
untilDestroyed(this),
)
.subscribe(token => {
// Create and inject new script
const script = this.renderer.createElement('script');
const head = this.renderer.selectRootElement('head', true);
const gdElement = document.createElement('gd-dashboard');
script.type = 'module';
script.id = 'customDashScript';
// Create the script content with imports and context setup
script.textContent = `
import { setContext } from "<https://xxx.cloud.gooddata.com/components/${workspaceId}.js>";
import factory, { TigerTokenAuthProvider } from "<https://xxx.cloud.gooddata.com/components/tigerBackend.js>";
try {
setContext({
backend: factory()
.onHostname("<https://xxx.cloud.gooddata.com>")
.withAuthentication(new TigerTokenAuthProvider("${token}")),
workspaceId: "${workspaceId}",
});
} catch(e) {
// console.log('Context set');
}
`;
// Append script to head
this.renderer.appendChild(head, script);
gdElement.classList.add('dashboard');
gdElement.id = 'gdElement'
gdElement.setAttribute('dashboard', this.dashboardId);
gdElement.addEventListener(INITIALIZED, this.onDashboardLoaded.bind(this));
gdElement.addEventListener(FILTER_CHANGED, this.onDashboardFilterChange.bind(this));
if (document.getElementById('dashboardContainer')) {
document.getElementById('dashboardContainer').innerHTML = '';
document.getElementById('dashboardContainer').appendChild(gdElement);
setTimeout(() => {
this.gdDashboardLoading$.next(false);
this.dashboardConfigured.set(true);
}, 1000);
} else {
this.gdDashboardLoading$.next(false);
this.dashboardConfigured.set(false);
}
});
}
}
Joaquim Grilo
06/26/2025, 5:39 PMJoaquim Grilo
06/26/2025, 5:39 PMMauricio Cabezas
06/26/2025, 6:12 PMMatt MacGillivray
06/26/2025, 6:26 PMJoaquim Grilo
06/26/2025, 6:39 PMMauricio Cabezas
06/26/2025, 6:45 PMJoaquim Grilo
06/26/2025, 7:00 PMMatt MacGillivray
06/27/2025, 1:52 PM