//Import Page enumeration
import { AppEmbed, Page } from '@thoughtspot/visual-embed-sdk';
const embed = new AppEmbed("#embed", {
// Set the initial page
pageId: Page.Liveboards,
//... other embed view configuration attributes
});
Customize default page and navigation path
In full application embedding, the home page is set as the default landing page when the embedded app loads.
To change the default settings, you can use either the pageId or path parameter in the Visual Embed SDK. If both path and pageId properties are specified, the path definition takes precedence.
Set the default page using pageId🔗
The pageId parameter in AppEmbed sets the default ThoughtSpot page to load using a value from the Page enumeration. Valid values for this attribute are:
-
Page.Homefor the ThoughtSpot Home page -
Page.Searchfor the ThoughtSpot Search page -
Page.Answersfor the Answers page -
Page.Liveboardsfor the Liveboards page -
Page.Datafor the Data page -
Page.SpotIQfor the SpotIQ analyses page
Example🔗
Set the default page via path🔗
The path parameter allows setting the default ThoughtSpot application page using a URL path. Valid strings for the path parameter are:
| Page | Classic experience | V2 and v3 experience |
|---|---|---|
Home |
|
|
Insights |
|
|
Liveboards list page |
|
|
Liveboard page |
|
|
Answers list page |
|
|
Saved Answer page |
|
|
Spotter |
|
|
Search data |
|
|
Data |
|
|
Model, tables, views |
|
|
SpotIQ analysis list page |
|
|
SpotIQ analysis page |
|
|
Monitor |
| Supported settings include:
|
Example🔗
const embed = new AppEmbed("#embed", {
// Set the initial page
path: 'pinboard/96a1cf0b-a159-4cc8-8af4-1a297c492ff9',
//... other embed view configuration attributes
});
Customize navigation between pages within the app🔗
To programmatically control navigation between the pages within the embedded app, you can use the navigateToPage() method and custom actions.
Using navigateToPage()🔗
The AppEmbed object includes a navigateToPage() method that can switch the currently loaded page in the embedded view.
The navigateToPage() method accepts the same string values that work for pageId or path attributes. If you are customizing the menu, the new navigation menu should call navigateToPage for the various pages you want to provide access to:
// Navigate to the Answers page
embed.navigateToPage(Page.Answers);
// Navigate to the Answers page without reloading the iframe (noReload = true)
embed.navigateToPage(Page.Answers, true);
Using navigateToPage() with a custom action🔗
To add a custom action for in-app navigation, create a callback custom action and define the navigation path.
In this example, the view-report action on a Liveboard page calls the navigateTo method to open a specific Answer page when the user clicks the View report button.
// Listen for the CustomAction event triggered from the embedded ThoughtSpot app
appEmbed.on(EmbedEvent.CustomAction, async (payload: any) => {
// Check if the custom action ID is 'view-report'
if (payload.payload.id === 'view-report') {
// Navigate to the specific saved Answer page using its GUID
appEmbed.navigateToPage(
'saved-answer/3da14030-11e4-42b2-8e56-5ee042a8de9e'
);
}
});
To navigate to a specific application page without initiating a reload, you can set the noReload attribute to true as shown in this example:
// Listen for the CustomAction event triggered from the embedded ThoughtSpot app
appEmbed.on(EmbedEvent.CustomAction, async (payload: any) => {
// Check if the custom action ID is 'view-report'
if (payload.payload.id === 'view-report') {
// Navigate to the specific saved Answer page using its GUID,
// and set noReload to true to avoid reloading the iframe
appEmbed.navigateToPage('saved-answer/3da14030-11e4-42b2-8e56-5ee042a8de9e', true);
}
});
Using history.back()🔗
Page changes within the AppEmbed component register as part of the embedding app’s history to the web browser.
The standard JavaScript history.back() function will cause the AppEmbed component to go to the previously loaded page up until the very first ThoughtSpot page loaded within the component.
Detect changes in the currently loaded page🔗
Various actions the user takes within the embedded ThoughtSpot application may cause navigation within ThoughtSpot.
User actions within the embedded ThoughtSpot application can trigger navigation events within ThoughtSpot. The embedding application can listen for these navigation changes via EmbedEvent.RouteChange and handle the event response.
The response can include a currentPath property, which is the path after the ThoughtSpot domain, for example:
pinboard/96a1cf0b-a159-4cc8-8af4-1a297c492ff9
To parse the currentPath into varying useful components, you can include this tsAppState object code in the global scope for use by other web application code:
// Simple global object to handle details about what is visible in the AppEmbed component at a given moment
let tsAppState = {
currentPath: startPath,
currentDatasources: [], // Can be set later when detected from TML or other events
// return to what is being viewed at the moment, in the form that will translate to the pageId property if captialized, or path property if not
get pageType() {
if (this.currentPath.includes('/saved-answer/')){
return 'answer';
}
else if (this.currentPath.includes('/pinboard/')){
return 'liveboard';
}
/*
* Others are meant to match the exact pageId from SDK
*/
else if(this.currentPath.includes('/answer/')){
return 'Search';
}
else if(this.currentPath.includes('/answers')){
return 'Answers';
}
else if (this.currentPath.includes('/pinboards')){
return 'Liveboards';
}
else if(this.currentPath.includes('/insights')){
return 'SpotIQ';
}
else if(this.currentPath.includes('/monitor')){
return 'Monitor';
}
else if(this.currentPath.includes('/data')){
return 'Data';
}
else {
return 'Home';
}
},
// If viewing an Answer or Liveboard, returns the GUID of that object from the parsed URL
get objectId() {
let pathParts = this.currentPath.split('/');
// '/saved-answer/' is path for Answers (vs. /answer/)
if (this.currentPath.includes('/saved-answer/')){
answerGUID = pathParts[2];
return pathParts[2];
}
// '/pinboard/' is path for saved Liveboards
else if (this.currentPath.includes('/pinboard/')){
let pathParts = this.currentPath.split('/');
// May need adjustment for tabbed views to add in current Tab
liveboardGUID = pathParts[2];
return pathParts[2];
}
else{
return null;
}
}
}
The following example shows the event listener code updating the global tsAppState object whenever a change is detected within the embedded ThoughtSpot app:
embed.on(EmbedEvent.RouteChange, (response) => {
// console.log("RouteChange fires");
// console.log(response);
// tsAppState object has currentPath property, which allows its other methods to parse out pageId, object type, GUIDs etc.
tsAppState.currentPath = response.data.currentPath;
console.log("TS App page is now: ", tsAppState.currentPath);
// Update elements within your web application based on the new state of ThoughtSpot (adjust menu selections, etc.)
})