diff --git a/package-lock.json b/package-lock.json index ac97897..10babb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@preset-sdk/embedded", - "version": "0.1.7", + "version": "0.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@preset-sdk/embedded", - "version": "0.1.7", + "version": "0.1.8", "license": "UNLICENSED", "dependencies": { "@superset-ui/switchboard": "^0.18.26-0" diff --git a/package.json b/package.json index fec21de..fff43ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@preset-sdk/embedded", - "version": "0.1.7", + "version": "0.1.8", "description": "Frontend SDK for embedding Preset data analytics into your own application", "access": "public", "keywords": [ diff --git a/src/const.ts b/src/const.ts index 5e18ce0..7c85b10 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1,2 +1,6 @@ export const IFRAME_COMMS_MESSAGE_TYPE = "__embedded_comms__"; +export const DASHBOARD_UI_FILTER_CONFIG_URL_PARAM_KEY: { [index: string]: any } = { + visible: "show_filters", + expanded: "expand_filters", +} diff --git a/src/index.ts b/src/index.ts index ec4e370..fadda32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,8 @@ import { Switchboard } from '@superset-ui/switchboard'; -import { IFRAME_COMMS_MESSAGE_TYPE } from './const'; +import { + DASHBOARD_UI_FILTER_CONFIG_URL_PARAM_KEY, + IFRAME_COMMS_MESSAGE_TYPE +} from './const'; import { getGuestTokenRefreshTiming } from './guestTokenRefresh'; import { applyReplaceChildrenPolyfill } from './polyfills'; @@ -14,6 +17,11 @@ export type UiConfigType = { hideTitle?: boolean hideTab?: boolean hideChartControls?: boolean + filters?: { + [key: string]: boolean | undefined + visible?: boolean + expanded?: boolean + } } export type EmbedDashboardParams = { @@ -25,7 +33,7 @@ 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, hideTab, hideChartControls **/ + /** The dashboard UI config: hideTitle, hideTab, hideChartControls, filters.visible, filters.expanded **/ dashboardUiConfig?: UiConfigType /** Enables extra logging */ debug?: boolean @@ -85,6 +93,13 @@ export async function embedDashboard({ return new Promise(resolve => { const iframe = document.createElement('iframe'); const dashboardConfig = dashboardUiConfig ? `?uiConfig=${calculateConfig()}` : "" + const filterConfig = dashboardUiConfig?.filters || {} + const filterConfigKeys = Object.keys(filterConfig) + const filterConfigUrlParams = filterConfigKeys.length > 0 + ? "&" + + filterConfigKeys + .map(key => DASHBOARD_UI_FILTER_CONFIG_URL_PARAM_KEY[key] + '=' + filterConfig[key]).join('&') + : "" // setup the iframe's sandbox configuration iframe.sandbox.add("allow-same-origin"); // needed for postMessage to work @@ -102,7 +117,7 @@ export async function embedDashboard({ resolve(switchboard); }); - iframe.src = `${supersetDomain}/embedded/${id}${dashboardConfig}`; + iframe.src = `${supersetDomain}/embedded/${id}${dashboardConfig}${filterConfigUrlParams}`; mountPoint?.replaceChildren(iframe); log('placed the iframe') });