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(embedding-sdk): emit data-mask events through embedded sdk to iframe parent #31331

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions RESOURCES/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ independently. This new framework will also allow for non-boolean configurations
- DRUID_JOINS
- EMBEDDABLE_CHARTS
- EMBEDDED_SUPERSET
- EMBEDDED_SUPERSET_EMIT_DATA_MASKS
- ENABLE_TEMPLATE_PROCESSING
- ESCAPE_MARKDOWN_HTML
- LISTVIEWS_DEFAULT_CARD_VIEW
Expand Down
19 changes: 13 additions & 6 deletions superset-embedded-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ export type Size = {
}

export type EmbeddedDashboard = {
getScrollSize: () => Promise<Size>
unmount: () => void
getDashboardPermalink: (anchor: string) => Promise<string>
getActiveTabs: () => Promise<string[]>
}
getScrollSize: () => Promise<Size>;
unmount: () => void;
getDashboardPermalink: (anchor: string) => Promise<string>;
getActiveTabs: () => Promise<string[]>;
getDataMasks: (callbackFn: (dataMasks: any[]) => void) => void;
MohamedHalat marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Embeds a Superset dashboard into the page using an iframe.
Expand Down Expand Up @@ -197,12 +198,18 @@ export async function embedDashboard({
const getScrollSize = () => ourPort.get<Size>('getScrollSize');
const getDashboardPermalink = (anchor: string) =>
ourPort.get<string>('getDashboardPermalink', { anchor });
const getActiveTabs = () => ourPort.get<string[]>('getActiveTabs')
const getActiveTabs = () => ourPort.get<string[]>('getActiveTabs');
const getDataMasks = (callbackFn: (dataMasks: any[]) => void) => {
ourPort.start();
ourPort.defineMethod("getDataMasks", callbackFn);
};


return {
getScrollSize,
unmount,
getDashboardPermalink,
getActiveTabs,
getDataMasks,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum FeatureFlag {
DynamicPlugins = 'DYNAMIC_PLUGINS',
EmbeddableCharts = 'EMBEDDABLE_CHARTS',
EmbeddedSuperset = 'EMBEDDED_SUPERSET',
EmbeddedSupersetEmitDataMasks = 'EMBEDDED_SUPERSET_EMIT_DATA_MASKS',
EnableAdvancedDataTypes = 'ENABLE_ADVANCED_DATA_TYPES',
/** @deprecated */
EnableJavascriptControls = 'ENABLE_JAVASCRIPT_CONTROLS',
Expand Down
17 changes: 16 additions & 1 deletion superset-frontend/src/embedded/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
import { lazy, Suspense } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { makeApi, t, logging } from '@superset-ui/core';
import {
makeApi,
t,
logging,
isFeatureEnabled,
FeatureFlag,
} from '@superset-ui/core';
import Switchboard from '@superset-ui/switchboard';
import getBootstrapData from 'src/utils/getBootstrapData';
import setupClient from 'src/setup/setupClient';
Expand Down Expand Up @@ -213,4 +219,13 @@
}
});

if (isFeatureEnabled(FeatureFlag.EmbeddedSupersetEmitDataMasks)) {
log('setting up Switchboard event emitter');

Check warning on line 223 in superset-frontend/src/embedded/index.tsx

View check run for this annotation

Codecov / codecov/patch

superset-frontend/src/embedded/index.tsx#L223

Added line #L223 was not covered by tests

store.subscribe(() => {
const state = store.getState();
Switchboard.emit('getDataMasks', state.dataMask);

Check warning on line 227 in superset-frontend/src/embedded/index.tsx

View check run for this annotation

Codecov / codecov/patch

superset-frontend/src/embedded/index.tsx#L225-L227

Added lines #L225 - L227 were not covered by tests
});
}

log('embed page is ready to receive messages');
1 change: 1 addition & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class D3TimeFormat(TypedDict, total=False):
# This feature flag is stil in beta and is not recommended for production use.
"GLOBAL_ASYNC_QUERIES": False,
"EMBEDDED_SUPERSET": False,
"EMBEDDED_SUPERSET_EMIT_DATA_MASKS": False,
# Enables Alerts and reports new implementation
"ALERT_REPORTS": False,
"ALERT_REPORT_TABS": False,
Expand Down
Loading