Skip to content

Commit

Permalink
chore: Add filter controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor-Avila committed Aug 21, 2023
1 parent c9d89cd commit f5fde47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -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",
}
21 changes: 18 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -81,6 +89,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
Expand All @@ -98,7 +113,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')
});
Expand Down

0 comments on commit f5fde47

Please sign in to comment.