Skip to content

Route change Dev example #39

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

Open
wants to merge 6 commits into
base: main
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
21 changes: 21 additions & 0 deletions visual-embed/embed-events/route-change/.codesandbox/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// These tasks will run in order when initializing your CodeSandbox project.
"setupTasks": [
{
"name": "Installing Dependencies",
"command": "npm install"
}
],

// These tasks can be run from CodeSandbox. Running one will open a log in the app.
"tasks": {
"dev": {
"name": "dev",
"command": "npm run dev",
"runAtStart": true,
"preview": {
"port": 3000
}
}
}
}
3 changes: 3 additions & 0 deletions visual-embed/embed-events/route-change/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_THOUGHTSPOT_HOST=https://training.thoughtspot.cloud
VITE_THOUGHTSPOT_USERNAME=code-sandbox
VITE_THOUGHTSPOT_PASSWORD="3mbed+#3xplz"
1 change: 1 addition & 0 deletions visual-embed/embed-events/route-change/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.env
55 changes: 55 additions & 0 deletions visual-embed/embed-events/route-change/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Route Change Embed Event

This example demonstrates how to handle route changes in ThoughtSpot embeds using React. It shows how to:

1. Listen for route changes in embedded ThoughtSpot components
2. Extract liveboard IDs from URLs
3. Fetch liveboard metadata using the ThoughtSpot API
4. Display toast notifications for user feedback

## Demo

Open in [Codesandbox](https://githubbox.com/thoughtspot/developer-examples/tree/main/visual-embed/embed-events/route-change)

## Documentation

- [Visual Embed SDK](https://developers.thoughtspot.com/docs/VisualEmbedSdk)
- [Route Change Embed Event](https://developers.thoughtspot.com/docs/Enumeration_EmbedEvent#_routechange)
- [Metadata API](https://developers.thoughtspot.com/docs/rest-apiv2-search#_search_metadata)

## Run locally

```bash
$ git clone https://github.com/thoughtspot/developer-examples
$ cd visual-embed/embed-events/route-change
```

```bash
$ npm i
```

```bash
$ npm run dev
```

## Preview

<p align="center">
<img src="preview.png" width="800" alt="Route Change Handler Preview" />
</p>

### Environment Variables

Update the `.env` file in the root directory with the following variables to use your own ThoughtSpot instance:

```
VITE_THOUGHTSPOT_HOST=your-thoughtspot-host
VITE_THOUGHTSPOT_USERNAME=your-username
VITE_THOUGHTSPOT_PASSWORD=your-password
```

### Technology labels

- React
- TypeScript
- Web
13 changes: 13 additions & 0 deletions visual-embed/embed-events/route-change/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/ts-logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ThoughtSpot Route Change Handler Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading