microsoft / powerbi-client-react

Power BI for React which provides components and services to enabling developers to easily embed Power BI reports into their applications.
MIT License
310 stars 98 forks source link

Refresh of "PowerBIEmbed" view when embedding PowerBI reports making use of RLS doesn't work correctly #88

Closed mabrizi01 closed 5 months ago

mabrizi01 commented 1 year ago

Hello, I recently worked for a customer engagement where I created a PoC for an MS Teams app using REACT. I made use of the "powerbi-client-react" library to embed the PowerBI reports. Some of the reports made available by the customer, make use of RLS security, that can be implemented using a funny pattern described here: https://learn.microsoft.com/en-us/power-bi/developer/embedded/cloud-rls. Our App is structured in a way where we have a left-hand side menu listing different report, and a central screen with the visualization area. Some of the item listed into the left-hand side list are occurrences of the same report but having a different set of parameters, that we will use to build the request to get the embedding token. Everything seems to be working fine until you do not try to open with a different set of parameters a PowerBI report previously shown by the "PowerBIEmbed" component. I've seen that in the RLS scenario, the returned emebeddingUrl doesn't change, the only difference is represented by the Token. Looking into the code, I think to have understood that if the URL doesn't change, it will not reload the PowerBI report but probably it will take from status history. But in this case, it is wrong.

I resolved this situation on the client-side (I mean, on the side of the "master" component asking to reload the PowerBI report into the "detail" component) forcing the destruction of the "detail" component, queuing a refreshing call into a separate thread that will completely put out-of-scope the "PowerBIEmbed" component, something like this:

<button onClick={() => { onReportOpen({}); // This forces the substitution of "PowerBIEmbed" component with an empty HTML in the visualization area setTimeout(() => { onReportOpen(reportInfo); // This recreates the "PowerBIEmbed" component in the visualization area }, 100); }}>Show Report

I think It would be more logic to simply not apply any caching strategy for already open PowerBI reports.

bapat-atharva commented 1 year ago

Thank you @mabrizi01 for reporting this. Your approach is one of the workaround for this as of now, if you dont want to resubstitute, you can use the powerbi.reset api on the container and then embed the new report.

const powerbi = new service.Service(factories.hpmFactory, factories.wpmpFactory, factories.routerFactory);

// reset container powerbi.reset(document.getElementsByClassName("report-container")[0] as HTMLElement);

// set this so you dont get into the condition where it checks for previous embed-configuration setReportConfig({embedUrl:"", accessToken:""});

settimeout(() => { *set new config here* }, 10);

In the meanwhile, we are planning to update the design to consider your scenario.