apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.8k stars 13.87k forks source link

iframe refresh #30826

Closed erdemcer closed 1 week ago

erdemcer commented 1 week ago

I have a simple application which has iframe contains Superset dashboard. I would like to refresh dashboard from custom button in main page but everytime when refresh button is called full whole iframe is reloading. Is there any way to refresh dashboard in iframe without reloading whole iframe.

Thanks

dosubot[bot] commented 1 week ago

Merhaba @erdemcer! I'm here to help you with any bugs or questions you have while waiting for a human maintainer. Let's solve this together!

To refresh the Superset dashboard in an iframe without reloading the entire iframe, you can use the postMessage API to communicate with the iframe and trigger a refresh. Superset provides a way to handle custom events or messages using the Switchboard class, which facilitates communication between the parent window and the iframe.

Here's a basic outline of how you can achieve this:

  1. Set up a MessageChannel: Establish a communication channel between the parent window and the iframe.

  2. Define a refresh method in the iframe: Use the Switchboard class to define a method in the iframe that handles the refresh logic.

  3. Emit a refresh message from the parent: Use the emit method to send a message to the iframe to trigger the refresh.

Example code snippet:

// In the parent window
const switchboard = new Switchboard({ port: yourMessagePort });

// Emit a message to trigger the refresh
switchboard.emit('refresh');
// In the iframe
switchboard.defineMethod('refresh', () => {
  // Logic to refresh the dashboard content
});

This setup allows you to refresh the dashboard content without reloading the entire iframe [1].

To continue talking to Dosu, mention @dosu.

erdemcer commented 1 week ago

Hi @dosu

Thanks for reply . But i have following error while initialize Switchboard in the parent window.

Uncaught ReferenceError: Switchboard is not defined

Could you please give detail about your outline ?

Thanks.

dosubot[bot] commented 1 week ago

To resolve the "Uncaught ReferenceError: Switchboard is not defined" error, ensure that the Switchboard class is properly imported or included in your script. The Switchboard class is exported as a default instance, so you need to import it correctly in your parent window script. Here's how you can do it:

  1. Import the Switchboard: Make sure you have the correct import statement in your parent window script.

    import Switchboard from 'path-to-switchboard-file';

    Replace 'path-to-switchboard-file' with the actual path to the file where the Switchboard class is defined.

  2. Ensure Script Order: If you are not using a module system, ensure that the script containing the Switchboard class is loaded before any script that tries to use it.

By following these steps, you should be able to initialize the Switchboard without encountering the reference error [1].

To continue talking to Dosu, mention @dosu.

erdemcer commented 1 week ago

Hi @dosu I am not using module system. I am trying to import it from supersetEmbeddedSdk with "onst switchboard = new supersetEmbeddedSdk.Switchboard({ port: channel.port1 });" But gives another error ; Uncaught TypeError: supersetEmbeddedSdk.Switchboard is not a constructor

Thanks.

geido commented 1 week ago

Hello @erdemcer I am closing this issue as this is not supported at the moment, but feel free to open up a PR to make this possible. Thank you!