Skip to content

Commit f754cbb

Browse files
authored
Merge pull request #71 from sigmacomputing/api-embed-carousel
Api embed carousel
2 parents aa84a56 + e917b21 commit f754cbb

File tree

27 files changed

+964
-66
lines changed

27 files changed

+964
-66
lines changed

embedding_qs_series_2_api_use_cases/.env

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,4 @@ VIEW_TEAMS=Embed_Users
5050
# Test Users - Build User (full editing access)
5151
BUILD_EMAIL=build.embed.qs@example.com
5252
BUILD_ACCOUNT_TYPE=Build
53-
BUILD_TEAMS=Embed_Users
54-
55-
# =============================================================================
56-
# SIGMA EMBED PARAMETERS (OPTIONAL)
57-
# =============================================================================
58-
# These parameters control the appearance and behavior of embedded content
59-
# All values shown are defaults - modify as needed for your use case
60-
61-
# Content Visibility Controls
62-
HIDE_FOLDER_NAVIGATION=true
63-
HIDE_MENU=true
64-
HIDE_PAGE_CONTROLS=false
65-
HIDE_RELOAD_BUTTON=false
66-
HIDE_TITLE=false
67-
HIDE_TOOLTIP=2
68-
HIDE_VIEW_SELECT=false
69-
70-
# Interface Configuration
71-
MENU_POSITION=none
72-
THEME=Lite
73-
LNG=English
74-
75-
# Responsive and Mobile Settings
76-
DISABLE_AUTO_REFRESH=false
77-
DISABLE_MOBILE_VIEW=false
78-
RESPONSIVE_HEIGHT=false
79-
80-
# Page and View Targeting (leave empty for workbook-level embedding)
81-
PAGE_ID=
82-
VIEW_ID=
53+
BUILD_TEAMS=Embed_Users
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
2-
"defaults": []
2+
"defaults": [
3+
{
4+
"userEmail": "view.embed.qs@example.com",
5+
"memberID": "Upf4cYouz5fAvk1SDH80L4pGihtUg",
6+
"workbookName": "Plugs Transactions",
7+
"workbookUrlId": "6QEnNYADhD50tbSnlwMltH",
8+
"createdAt": "2025-08-08T19:33:58.595Z",
9+
"updatedAt": "2025-08-08T19:33:58.595Z"
10+
}
11+
]
312
}

embedding_qs_series_2_api_use_cases/helpers/create-jwt.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ function generateJwt({ embedUrl, mode, sub, permissions }) {
1717
}
1818

1919
const finalPermissions =
20-
permissions || (mode === "build" ? ["build", "view"] : ["view"]);
20+
permissions ||
21+
(mode === "admin" ? ["build", "view", "admin"] :
22+
mode === "build" ? ["build"] : ["view"]);
2123

2224
const payload = {
2325
iss: process.env.CLIENT_ID,

embedding_qs_series_2_api_use_cases/helpers/get-workbooks.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@ async function getWorkbooksByTeam(teamName = process.env.WORKSPACE_NAME) {
2929

3030
const data = await response.json();
3131

32+
if (process.env.DEBUG === "true") {
33+
console.log(`All workbooks returned by API:`, data?.entries?.map(w => ({ name: w.name, path: w.path })));
34+
console.log(`Filtering for team: "${teamName}"`);
35+
}
36+
3237
// Filter workbooks by exact match to provided team/workspace path
3338
const filtered = data?.entries?.filter((w) => w.path === teamName);
3439

40+
if (process.env.DEBUG === "true") {
41+
console.log(`Filtered workbooks:`, filtered?.map(w => ({ name: w.name, path: w.path })));
42+
}
43+
3544
// Return only relevant metadata for downstream use
3645
return filtered.map((w) => ({
3746
id: w.workbookId, // full UUID for API calls

embedding_qs_series_2_api_use_cases/public/api-embed-bookmarks/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ <h3>JWT:</h3>
351351

352352
try {
353353
const res = await fetch(
354-
`/api/jwt/api-embed-bookmarks?workbookUrlId=${encodeURIComponent(
354+
`/api/jwt/${currentMode}?workbookUrlId=${encodeURIComponent(
355355
workbookUrlId
356356
)}&embedType=${encodeURIComponent(embedType)}`,
357357
{

embedding_qs_series_2_api_use_cases/public/api-embed-bookmarks_db/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ <h2>Save Bookmark</h2>
915915

916916
try {
917917
const res = await fetch(
918-
`/api/jwt/api-embed-bookmarks_db?workbookUrlId=${encodeURIComponent(
918+
`/api/jwt/${currentMode}?workbookUrlId=${encodeURIComponent(
919919
workbookUrlId
920920
)}&embedType=${embedType}`,
921921
{
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# API Workbook Carousel QuickStart
2+
3+
## Overview
4+
This QuickStart demonstrates an interactive workbook selection experience using a simple, stable carousel interface. Users can visually browse through available workbooks using thumbnail images and smooth navigation, providing an engaging way to discover and select embedded content.
5+
6+
## Features
7+
- Simple Carousel Navigation: Clean horizontal slider with previous/next buttons
8+
- User-Specific Content: Dynamic filtering showing only workbooks accessible to the selected user
9+
- Thumbnail Support: Visual workbook previews with stable image display
10+
- Instant Visual Feedback: Loading indicators and selected state animations
11+
- Stable Performance: Custom implementation designed for reliability during all interactions
12+
13+
## Key Technical Design: User-Specific Workbook Filtering
14+
15+
### API Architecture
16+
This carousel implements user-specific content filtering using Sigma's member-based API approach:
17+
18+
// Uses member-specific API endpoint
19+
const res = await fetch("/api/workbook-copy-create/all-workbooks");
20+
21+
### How Filtering Works
22+
1. Member ID Resolution: Resolves the selected embed user's member ID
23+
2. Permission-Based Filtering: Calls `/members/{memberId}/files` to get user-accessible content
24+
3. Shows only workbooks the selected user can actually access
25+
4. Cross-Workspace Access: Not limited to specific workspace folders
26+
27+
- Best Practice: Production embed apps should use workspace organization for better content governance
28+
29+
### API Endpoints Used
30+
- `GET /api/workbook-copy-create/all-workbooks` - User-specific workbook filtering
31+
- `POST /api/jwt/{currentMode}` - Dynamic JWT generation based on user type
32+
- `GET /env.json` - Environment configuration and user account types
33+
34+
## File Structure
35+
api-embed-carousel/
36+
├── index.html # Main carousel interface
37+
└── README.md # This documentation
38+
39+
## Thumbnail Configuration
40+
1. Location: Place images in `/public/assets/workbook-thumbnails/`
41+
2. Naming: Use exact workbook names as filenames (e.g., `Sales Dashboard.png`)
42+
3. Format: PNG format recommended, 240x140px optimal size
43+
4. Fallback: Missing thumbnails show "Missing Thumbnail" placeholder
44+
45+
46+
## Technical Implementation
47+
48+
### Custom Carousel Implementation
49+
- Simple HTML structure with CSS transforms for smooth sliding
50+
- Previous/next button navigation with keyboard support
51+
- Fixed positioning to avoid layout conflicts
52+
- Stable image display without DOM manipulation during interactions
53+
54+
### User State Management
55+
- Mode Switching: Automatic carousel reset when changing users
56+
- Loading States: Immediate visual feedback with spinner and workbook name
57+
- Selection Memory: Maintains selected workbook display after carousel closes
58+
- Stable Navigation: Simple slide tracking without complex state management
59+
60+
### JWT Generation
61+
- Dynamic Modes: View users get `["view"]`, Build users get `["build"]` permissions
62+
- Real-time Generation: JWT created on workbook selection with user-specific claims
63+
- Debug Display: Decoded JWT payload visible in sidebar for learning

0 commit comments

Comments
 (0)