Repository navigation
[SCAL-351755] Add DataAppEmbed host events, tile events and options - #745
akshay-pandey-thoughtspot wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the DataAppEmbed component and its React wrapper to support embedding single ThoughtSpot Apps. It adds new host events (DataAppInit, RefreshDataApp), embed events (TileClick, TileLoad, TileError, Darkmode), associated payloads, and comprehensive unit tests. The review feedback suggests avoiding the reassignment of constructor parameter properties in DataAppEmbed, adding a defensive guard in getIframeSrc to handle missing dataAppId values, and correcting invalid JSX syntax in the JSDoc example for the React component.
| constructor(container: HTMLElement, protected viewConfig: DataAppEmbedViewConfig) { | ||
| viewConfig = { | ||
| embedComponentType: 'dataApp', | ||
| ...viewConfig, | ||
| // Filters and parameters go in the app init payload, never the URL. | ||
| excludeRuntimeFiltersfromURL: true, | ||
| excludeRuntimeParametersfromURL: true, | ||
| } as DataAppEmbedViewConfig; | ||
| // Not in the view config type, but a JS caller can still pass it. | ||
| if ((viewConfig as { fullHeight?: boolean }).fullHeight) { | ||
| logger.warn('DataAppEmbed does not support fullHeight; it is ignored.'); | ||
| viewConfig = { ...viewConfig, fullHeight: false } as DataAppEmbedViewConfig; | ||
| } | ||
| super(container, viewConfig); | ||
| } |
There was a problem hiding this comment.
Reassigning constructor parameter properties is highly discouraged and error-prone in TypeScript, especially when overriding a property from a base class. Instead, declare viewConfig as a class property and pass a regular parameter to the constructor, consistent with other embed components like AppEmbed.
protected viewConfig: DataAppEmbedViewConfig;
constructor(container: HTMLElement, viewConfig: DataAppEmbedViewConfig) {
const config = {
embedComponentType: 'dataApp',
...viewConfig,
// Filters and parameters go in the app init payload, never the URL.
excludeRuntimeFiltersfromURL: true,
excludeRuntimeParametersfromURL: true,
} as DataAppEmbedViewConfig;
// Not in the view config type, but a JS caller can still pass it.
if ((config as any).fullHeight) {
logger.warn('DataAppEmbed does not support fullHeight; it is ignored.');
(config as any).fullHeight = false;
}
super(container, config);
this.viewConfig = config;
}| public getIframeSrc(): string { | ||
| const path = `embed/insights/apps/${encodeURIComponent(this.viewConfig.dataAppId)}`; | ||
| return `${this.getRootIframeSrc()}/${path}${this.getThoughtSpotPostUrlParams()}`; | ||
| } |
There was a problem hiding this comment.
Add a defensive guard for this.viewConfig.dataAppId to prevent encodeURIComponent from receiving undefined or generating a broken URL if the ID is missing or empty.
| public getIframeSrc(): string { | |
| const path = `embed/insights/apps/${encodeURIComponent(this.viewConfig.dataAppId)}`; | |
| return `${this.getRootIframeSrc()}/${path}${this.getThoughtSpotPostUrlParams()}`; | |
| } | |
| public getIframeSrc(): string { | |
| const appId = this.viewConfig.dataAppId || ''; | |
| const path = `embed/insights/apps/${encodeURIComponent(appId)}`; | |
| return `${this.getRootIframeSrc()}/${path}${this.getThoughtSpotPostUrlParams()}`; | |
| } |
| /** | ||
| * React component for embedding a single ThoughtSpot App. | ||
| * @version SDK: <TBD> | ThoughtSpot Cloud: 26.12.0.cl | ||
| * @example | ||
| * ```tsx | ||
| * function App() { | ||
| * return <DataAppEmbed | ||
| * dataAppId="<app-id>" | ||
| * enableDataApps={true} | ||
| * frameParams={{ height: '800px' }} | ||
| * ... other view config props or event listeners. | ||
| * /> | ||
| * } | ||
| * ``` | ||
| */ |
There was a problem hiding this comment.
The JSDoc example contains ... other view config props or event listeners. which is invalid JSX syntax and will cause compilation/parsing errors in documentation tools. Remove this line to keep the example clean and syntactically valid.
/**
* React component for embedding a single ThoughtSpot App.
* @version SDK: <TBD> | ThoughtSpot Cloud: 26.12.0.cl
* @example
* ```tsx
* function App() {
* return <DataAppEmbed
* dataAppId="<app-id>"
* enableDataApps={true}
* frameParams={{ height: '800px' }}
* />
* }
* ```
*/
DataAppEmbed embeds a single ThoughtSpot App, the way LiveboardEmbed embeds one Liveboard. It loads the App embed route on the v2 shell, /v2/?...#/embed/insights/apps/<dataAppId>, which renders the App page inside ThoughtSpot. - dataAppId is required: without it, a DATA_APP_ID_MISSING validation error and no frame - fullHeight is not supported: it is dropped with a warning - React <DataAppEmbed> wrapper and type exports - embedComponentType 'dataApp' Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Embedded ThoughtSpot hides Apps unless the host opts in. The new enableDataApps view config sends enableDataApps on the iframe URL; the app shows Apps only when it is true and the instance has Apps on. - AppViewConfig and DataAppEmbedViewConfig take enableDataApps (default false); DataAppEmbed now sends its own embed params - Keep the param on the URL under excludeConfigFromURL, since the app reads it at boot for its route guards - Specs for both embed types and the excludeConfigFromURL case Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hosts embedding an App can now load or switch Apps, refresh them,
filter them and follow their tiles and color scheme.
- HostEvent.DataAppInit { appId, runtimeFilters?, runtimeParameters? }
and HostEvent.RefreshDataApp, typed in HostEventRequestMap
- EmbedEvent.TileClick, TileLoad, TileError and Darkmode, typed in
EmbedEventDataExtension
- ContextType.DataApp for host events v2
- DataAppEmbedViewConfig: runtimeFilters and runtimeParameters (sent in
APP_INIT, never the URL) and hideDataAppHeader
- UpdateRuntimeFilters, UpdateParameters and UpdateTheme docs cover
DataAppEmbed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dafd21a to
82acd37
Compare
commit: |
Summary
Host events, embed events and options for
DataAppEmbed: load or switch Apps, refresh them, filter them, follow the host's theme, and hear about tile clicks, loads, errors and the App's own scheme switch.Stacked on #734 (
DataAppEmbed,enableDataApps): its two commits show here until it merges. Only the last commit is this PR. The branch is rebased on currentmain, which turns host events v2 on by default (#740), so theDataAppcontext matters for every host.Changes
HostEventRequestMap:HostEvent.DataAppInit(DataAppInitRequest { appId, runtimeFilters?, runtimeParameters? }): open an App or switch to another; its filters and parameters replace the earlier onesHostEvent.RefreshDataApp(no payload): re-run the App's tiles, no frame reloadDataAppEmbed:UpdateRuntimeFilters,UpdateParameters,UpdateTheme(a single-scheme App rejects)EmbedEventDataExtension:TileClick,TileLoad:DataAppTilePayload { appId, tileId }TileError:DataAppTileErrorPayload { appId, tileId, errorCode?, message?, sourceName?, connectorName? }Darkmode:DarkmodePayload { isDarkMode }, only from the App's own scheme buttonContextType.DataApp('dataApp'), for host events v2DataAppEmbedViewConfig:runtimeFilters,runtimeParameters: sent inAPP_INIT, never in the URLhideDataAppHeader: hides the ThoughtSpot header above the App (hideDataAppHeaderURL param)index.tsandreact/all-types-export.ts; wire values added to the locks incontracts.spec.ts@version SDK: <TBD> | ThoughtSpot Cloud: 26.12.0.clon everything newTesting
jest -c jest.config.sdk.js(full suite, rebased on current main): 56 suites, 2361 passeddata-app.spec.ts:hideDataAppHeaderon the URL; filters and parameters inAPP_INIT, not the URLcontracts.spec.ts: new wire values locked;DataAppInitandRefreshDataAppexamples compile againstTriggerDatatsc -p tsconfig.build.json --noEmiteslinton the changed files (no new findings)npm run lint-versionsAdditional Notes
RefreshDataApp is a new event, not a reuse. The review comment asked to reuse the Liveboard one. The candidates:
HostEvent.RefreshLiveboardBrowserCache: named for the Liveboard and its browser data cache, documented as needingenableLiveboardDataCache, and typed withScheduleEmailRequest. Apps have no browser cache; every load is a fresh stream.HostEvent.Reload: reloads the whole iframe inside the SDK and never reaches ThoughtSpot, which is whatRefreshDataAppmust not do.Reusing either would give a Liveboard-named event a different meaning for Apps. Easy to alias later if the reviewers still prefer it.
overrideFilters(in the design'sDataAppInitpayload) is left out of the type: the design does not defineOverrideFilters, and narrowing a published field later is a breaking change. ThoughtSpot accepts and ignores it for now.Port messages between the Apps page and the App frame (in the scaligent and apps-core PRs, listed here for reviewers):
host:refresh{ requestId, force? }force:RefreshDataApp, every visible tile re-runs. Without: the usual refresh (steps: []) after the host's filters or parameters changehost:theme{ requestId, isDarkMode }UpdateTheme, and the host'sisDarkModewhen the frame connectsdataapp:host-reply{ requestId, error? }host:*request;errorrejects itdataapp:tile-click{ tileId }<Tile>dataapp:tile-load{ tileId }<StepData>in the tile settled, once per rundataapp:tile-error{ tileId, errorCode?, message?, sourceName?, connectorName? }dataapp:scheme-change{ isDarkMode }host:themeNames follow the existing port protocol:
host:*goes into the frame,dataapp:*comes out of it.Landing order
Older ThoughtSpot: the new host events get "no handler" validation errors (host events v2) or no reply;
hideDataAppHeaderand the filters are ignored.Follow-ups, not in this PR
Share,Edit,ViewPublished,Rename,MakeACopy,Present,RestoreToPublished,Remove, and their actionsSourceData,UserInputs, style customizations (host:style), SpotterX, connectorsDataAppInitdoes not update the view config, so a pre-render show cycle re-sends the original filtersUpdateRuntimeFilters/UpdateParametersstill get no reply, as in other embedsoverrideFilterstypeDesign doc: https://docs.google.com/document/d/1rBzPGZG3Y-IcZZQkUreTls93fK_WKZThXOlQjlxLZNQ/edit
Jira: SCAL-351755
Sibling PRs:
🤖 Generated with Claude Code