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

feat(embedded): add optional dashboard ui configuration #19031

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion superset-embedded-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superset-ui/embedded-sdk",
"version": "0.1.0-alpha.3",
"version": "0.1.0-alpha.4",
"description": "SDK for embedding resources from Superset into your own application",
"access": "public",
"keywords": [
Expand Down
6 changes: 5 additions & 1 deletion superset-embedded-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type EmbedDashboardParams = {
mountPoint: HTMLElement
/** A function to fetch a guest token from the Host App's backend server */
fetchGuestToken: GuestTokenFetchFn
/** The dashboard UI config: hideTitle: 1; hideTab: 2; hideNav: 4; hideChartControls: 8; **/
uiConfig?: number
lilykuang marked this conversation as resolved.
Show resolved Hide resolved
/** Are we in debug mode? */
debug?: boolean
}
Expand All @@ -59,6 +61,7 @@ export async function embedDashboard({
supersetDomain,
mountPoint,
fetchGuestToken,
uiConfig,
debug = false
}: EmbedDashboardParams): Promise<EmbeddedDashboard> {
function log(...info: unknown[]) {
Expand All @@ -72,6 +75,7 @@ export async function embedDashboard({
async function mountIframe(): Promise<Switchboard> {
return new Promise(resolve => {
const iframe = document.createElement('iframe');
const dashboardConfig = uiConfig ? `?uiConfig=${uiConfig}` : ""

// setup the iframe's sandbox configuration
iframe.sandbox.add("allow-same-origin"); // needed for postMessage to work
Expand Down Expand Up @@ -103,7 +107,7 @@ export async function embedDashboard({
resolve(new Switchboard({ port: ourPort, name: 'superset-embedded-sdk', debug }));
});

iframe.src = `${supersetDomain}/dashboard/${id}/embedded`;
iframe.src = `${supersetDomain}/dashboard/${id}/embedded${dashboardConfig}`;
mountPoint.replaceChildren(iframe);
log('placed the iframe')
});
Expand Down