Skip to content

Conversation

@amaannawab923
Copy link
Contributor

@amaannawab923 amaannawab923 commented May 13, 2025

SUMMARY

This pr implements Embeddable Charts as per SIP #30075 (comment)
The only takeaway , the solution doesnt use charts in standalone mode , instead it takes the dashboard charts, hydrates them with all the required data & tells them to take full width & height of iframe , this avoids use of standalone mode & gives the same experience as dashboard charts

Chart embedding in action with nextjs app

screen-capture.23.webm

Embed uuid generation just like dashboard
chart_embed

Screenshot 2025-05-14 at 1 13 28 AM

Most of normal chart features of dashboard works

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@korbit-ai
Copy link

korbit-ai bot commented May 13, 2025

Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment /korbit-review.

Your admin can change your review schedule in the Korbit Console

@amaannawab923 amaannawab923 changed the title Feat(Embedding) : Embeddable Charts as per SIP feat(Embedding) : Embeddable Charts as per SIP May 13, 2025
@github-actions github-actions bot added the risk:db-migration PRs that require a DB migration label May 13, 2025
@codecov
Copy link

codecov bot commented May 13, 2025

Codecov Report

❌ Patch coverage is 63.79310% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.73%. Comparing base (76d897e) to head (e3a65ba).
⚠️ Report is 3040 commits behind head on master.

Files with missing lines Patch % Lines
superset/charts/api.py 58.33% 25 Missing ⚠️
superset/embedded/view.py 11.11% 8 Missing ⚠️
superset/commands/chart/delete.py 60.00% 4 Missing ⚠️
superset/daos/chart.py 55.55% 4 Missing ⚠️
superset/models/embedded_chart.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #33424      +/-   ##
==========================================
+ Coverage   60.48%   65.73%   +5.24%     
==========================================
  Files        1931      554    -1377     
  Lines       76236    40109   -36127     
  Branches     8568        0    -8568     
==========================================
- Hits        46114    26367   -19747     
+ Misses      28017    13742   -14275     
+ Partials     2105        0    -2105     
Flag Coverage Δ
hive 48.28% <63.79%> (-0.87%) ⬇️
javascript ?
presto 52.74% <63.79%> (-1.06%) ⬇️
python 65.73% <63.79%> (+2.23%) ⬆️
unit 61.32% <63.79%> (+3.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amaannawab923 amaannawab923 changed the title feat(Embedding) : Embeddable Charts as per SIP feat(Embedding): Embeddable Charts as per SIP May 14, 2025
@github-actions github-actions bot added the api Related to the REST API label May 14, 2025
@amaannawab923 amaannawab923 marked this pull request as ready for review May 14, 2025 18:41
@dosubot dosubot bot added the embedded label May 14, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Documentation Missing embedded property context ▹ view 🧠 Not in scope
Functionality Missing null check in HYDRATE_EMBEDDED reducer ▹ view 🧠 Incorrect
Security Insecure Default Embedding Policy ▹ view
Readability Inconsistent and Unclear Column Naming ▹ view 🧠 Not in standard
Security Unchecked External Data Injection ▹ view 🧠 Not in scope
Performance Unsafe Type Bypass and Inefficient Object Copy ▹ view 🧠 Incorrect
Functionality Unsafe Type Bypass in Embedded Datasource Hydration ▹ view 🧠 Not in standard
Functionality State overwrite in HYDRATE_EMBEDDED case ▹ view 🧠 Incorrect
Functionality Duplicate Hydration Logic for Embedded Charts ▹ view
Functionality Nullable Audit Timestamps ▹ view 🧠 Not in scope
Files scanned
File Path Reviewed
superset-frontend/src/dashboard/reducers/datasources.ts
superset-frontend/src/explore/reducers/datasourcesReducer.ts
superset-frontend/src/dashboard/reducers/dashboardInfo.js
superset-frontend/src/dashboard/actions/datasources.ts
superset-frontend/src/dashboard/reducers/sliceEntities.js
superset/models/embedded_chart.py
superset/migrations/versions/2025-05-14_03-40_67dd9e3429b2_add_embedded_charts_table.py
superset/daos/chart.py
superset/commands/chart/delete.py
superset-frontend/src/embedded/embeddedChart/useExploreData.ts
superset-frontend/src/types/bootstrapTypes.ts
superset/commands/chart/exceptions.py
superset/embedded/view.py
superset-frontend/src/dataMask/reducer.ts
superset-frontend/packages/superset-ui-core/src/ui-overrides/types.ts
superset-frontend/src/components/Chart/chartReducer.ts
superset-frontend/src/dashboard/reducers/dashboardState.js
superset-frontend/src/embedded/embeddedChart/hydrateEmbedded.ts
superset-frontend/src/embedded/index.tsx
superset-frontend/src/embedded/embeddedChart/index.tsx
superset-frontend/src/dashboard/components/SliceHeader/index.tsx
superset-frontend/src/dashboard/components/EmbeddedModal/index.tsx
superset/models/slice.py
superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx
superset-frontend/src/dashboard/components/Header/index.jsx
superset/charts/api.py
superset/charts/schemas.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines 165 to 169
embedded?: {
dashboard_id: string;
chart_id: string;
resource_type: 'dashboard' | 'chart';
};

This comment was marked as resolved.

Comment on lines +47 to +51
[HYDRATE_EMBEDDED]() {
return {
...action.data.sliceEntities,
};
},

This comment was marked as resolved.

Comment on lines +47 to +52
@property
def allowed_domains(self) -> list[str]:
"""
A list of domains which are allowed to embed the chart.
An empty list means any domain can embed.
"""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insecure Default Embedding Policy category Security

Tell me more
What is the issue?

The allowed_domains property allows unrestricted embedding from any domain when allow_domain_list is empty, which is an insecure default that enables clickjacking attacks.

Why this matters

Without domain restrictions by default, malicious sites could embed and manipulate the chart content, potentially leading to data theft or user deception through UI redressing attacks.

Suggested change ∙ Feature Preview

Change the behavior to deny all domains by default instead of allow all. For example:

@property
def allowed_domains(self) -> list[str]:
    """A list of domains which are allowed to embed the chart.
    An empty list means no domains can embed (secure by default).
    """
    return self.allow_domain_list.split(",") if self.allow_domain_list else ["DENY_ALL"]
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

__tablename__ = "embedded_charts"

uuid = Column(UUIDType(binary=True), default=uuid.uuid4, primary_key=True)
allow_domain_list = Column(Text)

This comment was marked as resolved.

Comment on lines +42 to +44
if (action.type === HYDRATE_EMBEDDED) {
// @ts-ignore
return { ...action.data.datasources };

This comment was marked as resolved.

Comment on lines +43 to +44
// @ts-ignore
return { ...action.data.datasources };

This comment was marked as resolved.

Comment on lines +42 to +45
if (action.type === HYDRATE_EMBEDDED) {
// @ts-ignore
return { ...action.data.datasources };
}

This comment was marked as resolved.

Comment on lines +43 to +47
if (action.type === HYDRATE_EMBEDDED) {
return {
...action.data.datasources,
};
}

This comment was marked as resolved.

Comment on lines +62 to +64
[HYDRATE_EMBEDDED]() {
return { ...state, ...action.data.dashboardState };
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Hydration Logic for Embedded Charts category Functionality

Tell me more
What is the issue?

The HYDRATE_EMBEDDED action handler is exactly the same as HYDRATE_DASHBOARD, which could lead to inconsistent state management if embedded charts require different hydration logic.

Why this matters

If embedded charts have unique state requirements or need special handling during hydration, using the same logic as dashboard hydration could cause incorrect behavior or state inconsistencies in embedded contexts.

Suggested change ∙ Feature Preview

Consider whether embedded charts need different hydration logic and modify accordingly. If they truly need the same logic, consider using a shared function:

const hydrateState = data => ({ ...state, ...data.dashboardState });

[HYDRATE_DASHBOARD]() {
  return hydrateState(action.data);
},
[HYDRATE_EMBEDDED]() {
  return hydrateState(action.data);
}
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

Comment on lines +37 to +38
sa.Column("created_on", sa.DateTime(), nullable=True),
sa.Column("changed_on", sa.DateTime(), nullable=True),

This comment was marked as resolved.

@mistercrunch
Copy link
Member

I commented on the SIP back in October, #30075 (comment), but why not embedding a single-chart-dashboard?

There's a related idea which is allowing to embed parts of the Explore experience, potentaly allowing embedded use cases for light data exploration. Wondering if that's in-scope here (?) The idea would be to allow/limit part of the Explore experience, say I may want to hide/show different panels and/or controls... I'm guessing the idea here is more to simply embed a single chart, without interactions.

@amaannawab923
Copy link
Contributor Author

amaannawab923 commented May 14, 2025

I commented on the SIP back in October, #30075 (comment), but why not embedding a single-chart-dashboard?

There's a related idea which is allowing to embed parts of the Explore experience, potentaly allowing embedded use cases for light data exploration. Wondering if that's in-scope here (?) The idea would be to allow/limit part of the Explore experience, say I may want to hide/show different panels and/or controls... I'm guessing the idea here is more to simply embed a single chart, without interactions.

This pr deals with embedding a single chart with normal dashboard interactons

What i understood from the previous comment of the sip was #30075 (comment) we need to have chart creation within dashboard ... I have implemented the same in a private fork , we used to call it easy charts

1.User can place a chart container on the grid <- completely empty which will have a button +add chart on it
2. It opens up a control panel in a popover with 3 controls , Groupby , metric & dataset & a top bar for selecting viz type
3. When the user saves the chart ... it gets saved to slices & gets absorbed by the chart container & the easy charts default attributes can also be edited via the chartlist
This allowed for flexibility for creating charts on the fly & more customisations via proper control panel if the end user wants to

We can connect on this , if easy charts are implemented in a seperate sip , we can bring those anytime here in embedded charts

@mistercrunch

@amaannawab923
Copy link
Contributor Author

Screenshot 2025-05-15 at 2 16 01 AM

Something like this @mistercrunch , Some level of explore controls in dashboard for the chart

Or something where its metric centric & the user can select metrics & create instant charts within dashboard like below
Screenshot 2025-05-15 at 2 21 05 AM

Or something where the user can just change the query groupby just by hitting a dropdown & selecting from a list of Groupbys like Display by departments like the below
Screenshot 2025-05-15 at 2 21 22 AM

Curious to know , whats the idea will fit best with superset so we can implement it

@mistercrunch

@github-actions
Copy link
Contributor

@mistercrunch Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments

@github-actions
Copy link
Contributor

@mistercrunch Ephemeral environment spinning up at http://35.87.137.37:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup.

@mistercrunch
Copy link
Member

mistercrunch commented May 15, 2025

Complex topic. We should probably talk.

Some thoughts related to all this:

  1. it would be really great to be able to "edit chart", or "explore data" within a dashboard. Idea here is that within a dashboard, if you "edit chart" or "explore chart", we pop a large Modal with what is currently in the explore page, while keeping the user in the dashboard. Here there needs to be different options depending on the user level of access (do they have access to edit/modify the chart?). If we allow them to explore the data, what controls do we expose? Metric? Filters? Groupby? Filters? All? In the context of embedded, the person embedding needs to be able to define what it allows the user to do, if anything, within that modal.
  2. it would be great to be able to embed a single chart, yes, and offer some options. Which controls do you want to expose? Do you allow the user to switch the metric? apply filters? ...
  3. it would be great to allow "embedders" to externally control the chart, so that the host application can emit events inside the embedded chart, things like "group by something else", "switch the metric to this other metric", "apply this filter", ...

@amaannawab923
Copy link
Contributor Author

Complex topic. We should probably talk.

Some thoughts related to all this:

  1. it would be really great to be able to "edit chart", or "explore data" within a dashboard. Idea here is that within a dashboard, if you "edit chart" or "explore chart", we pop a large Modal with what is currently in the explore page, while keeping the user in the dashboard. Here there needs to be different options depending on the user level of access (do they have access to edit/modify the chart?). If we allow them to explore the data, what controls do we expose? Metric? Filters? Groupby? Filters? All? In the context of embedded, the person embedding needs to be able to define what it allows the user to do, if anything, within that modal.
  2. it would be great to be able to embed a single chart, yes, and offer some options. Which controls do you want to expose? Do you allow the user to switch the metric? apply filters? ...
  3. it would be great to allow "embedders" to externally control the chart, so that the host application can emit events inside the embedded chart, things like "group by something else", "switch the metric to this other metric", "apply this filter", ...

Yes , i somewhat got the idea , we can connect on this ,

#33448

i have created an sip for the same , would include points from the ones mentioned above
@mistercrunch

@github-actions github-actions bot removed the embedded label May 20, 2025
@rusackas
Copy link
Member

This needs a big rebase... do we still want to carry this through? The SIP is already approved, so it just needs to be completed, or the SIP may (eventually) be discarded due to inactivity.

aminghadersohi added a commit to aminghadersohi/superset that referenced this pull request Jan 8, 2026
Add "Embed chart" option to chart header dropdown menu on dashboards.
When clicked, opens a modal that generates embed code (iframe + guest token)
using the existing permalink + guest token infrastructure.

Changes:
- Add POST /api/v1/embedded_chart/ endpoint to create embeddable charts
- Add EmbeddedChartModal component with allowed domains and TTL settings
- Add "Embed chart" menu item to SliceHeaderControls
- Add EmbedChart to MenuKeys enum

This brings UI parity with PR apache#33424's approach while using our simpler
ephemeral permalink-based architecture (no database model needed).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API packages risk:db-migration PRs that require a DB migration size/XXL testenv-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants