|
| 1 | +# 🚀 Sigma Dashboard Builder - Multi-Area KPI Placement System |
| 2 | + |
| 3 | +A sophisticated host application for Sigma's Dashboard Builder plugin that enables users to place different KPIs across three independent dashboard areas with persistent bookmark management. |
| 4 | + |
| 5 | +## ✨ Key Features |
| 6 | + |
| 7 | +- **🎯 Multi-Area KPI Placement**: Place different KPIs in 3 independent dashboard areas |
| 8 | +- **💾 Persistent Bookmarks**: Save and restore complete multi-area configurations |
| 9 | +- **🔄 Incremental Building**: Add KPIs to existing bookmarks without losing current state |
| 10 | +- **🛡️ Cross-Contamination Prevention**: Each area operates independently |
| 11 | +- **⚡ Real-time Synchronization**: ExploreKey sync across all areas |
| 12 | +- **🔐 Secure Authentication**: JWT-based authentication with automatic token refresh |
| 13 | + |
| 14 | +## 🏗️ Architecture |
| 15 | + |
| 16 | +### Dual Storage System |
| 17 | +- **Sigma Bookmarks**: Store exploreKey and workbook state (single-state, cloud) |
| 18 | +- **LowDB Database**: Store multi-area configurations (multi-state, local) |
| 19 | +- **Combined**: Complete bookmark restoration across all dashboard areas |
| 20 | + |
| 21 | +This project provides host application examples for Sigma plugins, demonstrating advanced multi-area plugin integration and persistent state management. |
| 22 | + |
| 23 | +## Project Structure |
| 24 | + |
| 25 | +``` |
| 26 | +plugin_use_cases/ |
| 27 | +├── .env # Configuration file (copy from .env.example) |
| 28 | +├── package.json # Node.js dependencies |
| 29 | +├── server/ |
| 30 | +│ └── server.js # Express server for hosting |
| 31 | +├── helpers/ |
| 32 | +│ └── create-jwt.js # JWT generation utilities |
| 33 | +├── routes/ |
| 34 | +│ └── api/ |
| 35 | +│ └── jwt.js # JWT API endpoints |
| 36 | +└── public/ |
| 37 | + ├── styles/ # Shared CSS styles |
| 38 | + └── dashboard-builder/ # Dashboard Builder plugin host |
| 39 | + └── index.html # Host application |
| 40 | +``` |
| 41 | + |
| 42 | +## Quick Start |
| 43 | + |
| 44 | +### Prerequisites |
| 45 | + |
| 46 | +1. **Sigma Instance Access**: You need a Sigma instance with: |
| 47 | + - API credentials (Client ID and Secret) |
| 48 | + - A registered plugin (e.g., "Dashboard Builder") |
| 49 | + - A workbook configured for the plugin |
| 50 | + |
| 51 | +2. **Node.js**: Version 14 or higher |
| 52 | + |
| 53 | +### Setup |
| 54 | + |
| 55 | +1. **Clone and Navigate**: |
| 56 | + ```bash |
| 57 | + cd plugin_use_cases |
| 58 | + ``` |
| 59 | + |
| 60 | +2. **Install Dependencies**: |
| 61 | + ```bash |
| 62 | + npm install |
| 63 | + ``` |
| 64 | + |
| 65 | +3. **Configure Environment**: |
| 66 | + - Copy `.env` to create your configuration |
| 67 | + - Update the following required fields: |
| 68 | + ``` |
| 69 | + ORG_SLUG=your-sigma-org |
| 70 | + CLIENT_ID=your-client-id |
| 71 | + SECRET=your-client-secret |
| 72 | + ADMIN_EMAIL=your-admin-email@company.com |
| 73 | + ``` |
| 74 | +
|
| 75 | +4. **Start the Server**: |
| 76 | + ```bash |
| 77 | + npm start |
| 78 | + ``` |
| 79 | + |
| 80 | +5. **Access the Application**: |
| 81 | + - Open http://localhost:3000 |
| 82 | + - Navigate to the Dashboard Builder example |
| 83 | + |
| 84 | +## Dashboard Builder Plugin Host |
| 85 | + |
| 86 | +The Dashboard Builder host application demonstrates: |
| 87 | + |
| 88 | +- **Plugin Integration**: Embedding a Sigma plugin in a host application |
| 89 | +- **Bidirectional Communication**: Messages between host and plugin |
| 90 | +- **Element Selection**: UI for selecting dashboard elements |
| 91 | +- **JWT Authentication**: Secure embedding with proper tokens |
| 92 | + |
| 93 | +### Usage |
| 94 | + |
| 95 | +1. **Select User**: Choose between View or Build user |
| 96 | +2. **Enter Workbook ID**: Provide the ID of your Dashboard Builder workbook |
| 97 | +3. **Connect Plugin**: Click to establish the connection |
| 98 | +4. **Select Elements**: Use the gallery to choose dashboard elements |
| 99 | +5. **Add to Dashboard**: Send selected elements to the plugin |
| 100 | + |
| 101 | +### Plugin Communication |
| 102 | + |
| 103 | +The host application communicates with the plugin via `postMessage`: |
| 104 | + |
| 105 | +**Messages sent to plugin**: |
| 106 | +- `CONFIGURE`: Initial plugin configuration |
| 107 | +- `ADD_ELEMENTS`: Selected elements to add to dashboard |
| 108 | + |
| 109 | +**Messages received from plugin**: |
| 110 | +- `PLUGIN_READY`: Plugin has loaded and is ready |
| 111 | +- `ELEMENT_SELECTED`: User selected an element in the plugin |
| 112 | +- `DASHBOARD_UPDATED`: Dashboard configuration changed |
| 113 | + |
| 114 | +## Configuration |
| 115 | + |
| 116 | +### Environment Variables |
| 117 | + |
| 118 | +| Variable | Description | Required | |
| 119 | +|----------|-------------|----------| |
| 120 | +| `ORG_SLUG` | Your Sigma organization identifier | Yes | |
| 121 | +| `CLIENT_ID` | Sigma API client ID | Yes | |
| 122 | +| `SECRET` | Sigma API client secret | Yes | |
| 123 | +| `ADMIN_EMAIL` | Admin user email for API calls | Yes | |
| 124 | +| `PLUGIN_NAME` | Name of your registered plugin | No | |
| 125 | +| `WORKBOOK_NAME` | Default workbook name | No | |
| 126 | +| `PORT` | Server port (default: 3000) | No | |
| 127 | +| `DEBUG` | Enable debug logging (default: true) | No | |
| 128 | + |
| 129 | +### Plugin-Specific Settings |
| 130 | + |
| 131 | +Additional configuration for plugin behavior: |
| 132 | +- `HIDE_FOLDER_NAVIGATION`: Hide folder navigation in embed |
| 133 | +- `HIDE_MENU`: Hide Sigma menu |
| 134 | +- `MENU_POSITION`: Menu position (top/bottom/none) |
| 135 | +- `THEME`: Plugin theme (light/dark) |
| 136 | + |
| 137 | +## Extending to Other Plugins |
| 138 | + |
| 139 | +To add support for additional plugins: |
| 140 | + |
| 141 | +1. **Create Plugin Directory**: |
| 142 | + ```bash |
| 143 | + mkdir public/your-plugin-name |
| 144 | + ``` |
| 145 | + |
| 146 | +2. **Copy Template**: |
| 147 | + Use `dashboard-builder/index.html` as a starting point |
| 148 | + |
| 149 | +3. **Customize Communication**: |
| 150 | + - Update message types in JavaScript |
| 151 | + - Modify UI elements for your plugin's needs |
| 152 | + - Add plugin-specific configuration |
| 153 | + |
| 154 | +4. **Update Server Routes**: |
| 155 | + Add any plugin-specific API endpoints if needed |
| 156 | + |
| 157 | +## Development |
| 158 | + |
| 159 | +### Adding New Features |
| 160 | + |
| 161 | +1. **Plugin Communication**: Extend the `postMessage` handlers |
| 162 | +2. **UI Elements**: Add new controls in the sidebar |
| 163 | +3. **API Endpoints**: Create additional routes in `routes/api/` |
| 164 | +4. **Configuration**: Add new environment variables |
| 165 | + |
| 166 | +### Debugging |
| 167 | + |
| 168 | +- Set `DEBUG=true` in `.env` for verbose logging |
| 169 | +- Use browser developer tools to inspect plugin messages |
| 170 | +- Check server logs for API errors |
| 171 | + |
| 172 | +## Security Notes |
| 173 | + |
| 174 | +- Never commit `.env` files with real credentials |
| 175 | +- JWT tokens are short-lived (5 minutes) for security |
| 176 | +- Validate all plugin communications |
| 177 | +- Use HTTPS in production environments |
| 178 | + |
| 179 | +## Support |
| 180 | + |
| 181 | +For issues with: |
| 182 | +- **Sigma Platform**: Contact Sigma support |
| 183 | +- **Plugin Development**: Refer to Sigma plugin documentation |
| 184 | +- **This Host Application**: Check the issues in this repository |
0 commit comments