michael-s-molina opened a new pull request, #36924:
URL: https://github.com/apache/superset/pull/36924

   ### SUMMARY
   
   This PR adds a `resolvePermalinkUrl` callback to the Embedded SDK that 
allows host applications to customize the permalink URLs generated when users 
click share buttons inside an embedded dashboard.
   
   **Problem:**
   When users click "Copy Link" on a chart or dashboard inside an embedded 
Superset dashboard, the generated permalink uses Superset's domain (e.g., 
`https://superset.example.com/superset/dashboard/p/xyz789/`). Host applications 
often need full control over the permalink URL to use their own domain, paths, 
and query parameters.
   
   **Solution:**
   - Added `resolvePermalinkUrl` callback to the SDK's `embedDashboard()` 
options
   - When a permalink is generated, Superset calls this callback with the 
permalink key
   - The host can return a custom URL (e.g., 
`https://my-app.com/analytics/share/xyz789`)
   - If no callback is provided, Superset's default URL is used (backward 
compatible)
   
   **Architecture:**
   ```
   User clicks "Copy Link" in embedded Superset
               ↓
       POST /api/v1/dashboard/{id}/permalink
               ↓
       Backend returns { key: "xyz789", url: "..." }
               ↓
       Switchboard.get('resolvePermalinkUrl', { key })  ──→  SDK
               ↓                                              ↓
               ↓                                    host.resolvePermalinkUrl({ 
key })
               ↓                                              ↓
               ←──────────────────────────────────  
"https://my-app.com/share/xyz789";
               ↓
       Copy resolved URL to clipboard
   ```
   
   **Additional fix:**
   - Fixed anchor scrolling for permalinks in embedded mode. The anchor 
(chart/tab ID to scroll to) was already stored in the permalink state but 
wasn't being applied when loading embedded dashboards. Now `DashboardPage.tsx` 
extracts the anchor from the permalink state and scrolls to the element after 
hydration.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A - This is an SDK API change, not a UI change.
   
   ### TESTING INSTRUCTIONS
   
   1. **Test custom permalink URLs in embedded mode:**
      ```javascript
      embedDashboard({
        id: "your-dashboard-uuid",
        supersetDomain: "https://superset.example.com";,
        mountPoint: document.getElementById("dashboard"),
        fetchGuestToken: () => fetchGuestTokenFromBackend(),
        resolvePermalinkUrl: ({ key }) => {
          console.log("Permalink key:", key);
          return `https://my-app.com/share/${key}`;
        }
      });
      ```
      - Click the share/copy link button on a chart inside the embedded 
dashboard
      - Verify the clipboard contains your custom URL (e.g., 
`https://my-app.com/share/xyz789`)
   
   2. **Test fallback behavior (no callback):**
      - Remove the `resolvePermalinkUrl` callback
      - Click share/copy link
      - Verify Superset's default URL is used
   
   3. **Test permalink restoration with anchor:**
      ```javascript
      embedDashboard({
        // ...
        dashboardUiConfig: {
          urlParams: {
            permalink_key: "xyz789"  // A permalink that was created from a 
specific chart
          }
        }
      });
      ```
      - Verify the dashboard loads with the correct filter state
      - Verify the page scrolls to the specific chart that was shared
   
   4. **Test non-embedded mode still works:**
      - Open a regular (non-embedded) dashboard
      - Click share/copy link on a chart
      - Verify the permalink URL is generated correctly
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [x] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to