Skip to content

Commit 4e82502

Browse files
authored
chore: Add features from OSS (#30)
* chore: Add features from OSS * Bumping version for upgrade
1 parent c3bc3b6 commit 4e82502

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@preset-sdk/embedded",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"description": "Frontend SDK for embedding Preset data analytics into your own application",
55
"access": "public",
66
"keywords": [

src/index.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type EmbedDashboardParams = {
3131
/** The id provided by the embed configuration UI in Superset */
3232
id: string
3333
/** The domain where Superset can be located, with protocol, such as: https://abc123.us1a.preset.io */
34-
supersetDomain: string // todo remove this option? after migrating to the preset frontend sdk
34+
supersetDomain: string
3535
/** The html element within which to mount the iframe */
3636
mountPoint: HTMLElement
3737
/** A function to fetch a guest token from the Host App's backend server */
@@ -40,6 +40,12 @@ export type EmbedDashboardParams = {
4040
dashboardUiConfig?: UiConfigType
4141
/** Enables extra logging */
4242
debug?: boolean
43+
/** The iframe title attribute */
44+
iframeTitle?: string
45+
/** additional iframe sandbox attributes ex (allow-top-navigation, allow-popups-to-escape-sandbox) **/
46+
iframeSandboxExtras?: string[]
47+
/** force a specific refererPolicy to be used in the iframe request **/
48+
referrerPolicy?: ReferrerPolicy
4349
}
4450

4551
export type Size = {
@@ -60,7 +66,10 @@ export async function embedDashboard({
6066
mountPoint,
6167
fetchGuestToken,
6268
dashboardUiConfig,
63-
debug = false
69+
debug = false,
70+
iframeTitle = "Embedded Dashboard",
71+
iframeSandboxExtras = [],
72+
referrerPolicy,
6473
}: EmbedDashboardParams): Promise<EmbeddedDashboard> {
6574
function log(...info: unknown[]) {
6675
if (debug) {
@@ -112,7 +121,15 @@ export async function embedDashboard({
112121
iframe.sandbox.add("allow-downloads"); // for downloading charts as image
113122
iframe.sandbox.add("allow-top-navigation"); // for links to open
114123
iframe.sandbox.add("allow-forms"); // for forms to submit
115-
iframe.sandbox.add("allow-popups"); // for exporting charts as csv
124+
iframe.sandbox.add("allow-popups"); // for exporting charts as csv
125+
// additional sandbox props
126+
iframeSandboxExtras.forEach((key: string) => {
127+
iframe.sandbox.add(key);
128+
});
129+
// force a specific refererPolicy to be used in the iframe request
130+
if(referrerPolicy) {
131+
iframe.referrerPolicy = referrerPolicy;
132+
}
116133

117134
// add the event listener before setting src, to be 100% sure that we capture the load event
118135
iframe.addEventListener('load', () => {
@@ -122,6 +139,7 @@ export async function embedDashboard({
122139
});
123140

124141
iframe.src = `${supersetDomain}/embedded/${id}${urlParamsString}`;
142+
iframe.title = iframeTitle;
125143
mountPoint?.replaceChildren(iframe);
126144
log('placed the iframe')
127145
});

0 commit comments

Comments
 (0)