Skip to content

Commit eb2f95b

Browse files
authored
Merge pull request #61 from thoughtspot/SCAL-314115-default
SCAL-314115 host-event subscription
2 parents 12d576b + 7214000 commit eb2f95b

9 files changed

Lines changed: 112 additions & 428 deletions

File tree

‎visual-embed/host-event-parameterized/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const App = () => {
4646
};
4747
```
4848

49+
> **Triggering host events at load time?** These examples are button-driven, so no readiness handling is needed. For triggers fired automatically at load, use the `subscribedEvent` readiness pattern (requires `useHostEventsV2: true`) — see [update-filters-and-params](../update-filters-and-params/README.md).
50+
4951
## Documentation
5052

5153
- [Host Event Parameterization](https://developers.thoughtspot.com/docs/events-app-integration#hostEventParameterization)

‎visual-embed/liveboard/package-lock.json‎

Lines changed: 24 additions & 201 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎visual-embed/liveboard/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"@thoughtspot/visual-embed-sdk": "latest",
13+
"@thoughtspot/visual-embed-sdk": "^1.50.1",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0",
1616
"react-router": "^7.5.2"
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
1+
import { useEffect } from "react";
12
import Header from "../components/Header";
23
import { EmbedEvent, HostEvent, LiveboardEmbed, RuntimeFilterOp, useEmbedRef } from "@thoughtspot/visual-embed-sdk/react";
34

45
function EmbedWithReactWithOptions() {
56

67
const ref = useEmbedRef<typeof LiveboardEmbed>();
78
//apply runtime filters
8-
9+
910
const runtimeFilters = [
1011
{
1112
columnName: "state",
1213
operator: RuntimeFilterOp.EQ,
1314
values: ["michigan"],
1415
},
1516
];
16-
17+
1718
const onLoad = () => {
1819
console.log(EmbedEvent.Load, {});
1920
};
20-
21-
//Register an event handler to trigger the SetVisibleVizs event when the Liveboard is rendered
22-
const onLiveboardRendered = () => {
23-
ref.current.trigger(HostEvent.SetVisibleVizs, [
24-
"3f84d633-e325-44b2-be25-c6650e5a49cf",
25-
"28b73b4a-1341-4535-ab71-f76b6fe7bf92",
26-
]);
27-
};
21+
22+
// Standard pattern for triggering a host event at load time: listen for the
23+
// "<Event> Subscribed" ready signal via subscribedEvent() — it fires the moment
24+
// the embedded app has registered its handler, so the trigger cannot be dropped.
25+
// Requires useHostEventsV2 on the embed (SDK 1.45.2+ / ThoughtSpot 26.3.0.cl+).
26+
useEffect(() => {
27+
const embed = ref.current;
28+
if (!embed) return;
29+
const subscribed = embed.subscribedEvent(HostEvent.SetVisibleVizs) as EmbedEvent;
30+
const onReady = () => {
31+
embed.trigger(HostEvent.SetVisibleVizs, [
32+
"3f84d633-e325-44b2-be25-c6650e5a49cf",
33+
"28b73b4a-1341-4535-ab71-f76b6fe7bf92",
34+
]);
35+
};
36+
embed.on(subscribed, onReady);
37+
return () => {
38+
embed.off(subscribed, onReady);
39+
};
40+
}, []);
2841

2942
return (
3043
<>
@@ -38,11 +51,11 @@ function EmbedWithReactWithOptions() {
3851
liveboardId={import.meta.env.VITE_LIVEBOARD_ID}
3952
runtimeFilters={runtimeFilters}
4053
onLoad={onLoad}
41-
onLiveboardRendered={onLiveboardRendered}
54+
useHostEventsV2
4255
fullHeight={true} />
4356
</div>
4457
</>
4558
)
4659
}
4760

48-
export default EmbedWithReactWithOptions;
61+
export default EmbedWithReactWithOptions;

0 commit comments

Comments
 (0)