Hello gooddata team! Could you help me regarding t...
# gooddata-ui
m
Hello gooddata team! Could you help me regarding this User Story: """ - As a user of our SaaS application, I want to select sites, products or events of interest when I am onboarded to the platform. - The home page should be made of multiple dashboards whose filters are preselected depending on my preferences and I should be able to expand these filters to ALL if I want to. """ We're trying to do this with iframes if possible, this way we don't need to code anything. It looks like it's possible to preselect filters and save the dashboard, we just create one dashboard with the preferences of this user. But we have many users each of them with their own set of preselected filters. How do we call the iframe and automatically preselect the filters ? Do we need to create one dashboard for each user ?
j
Hi Merwane, The following community post directly addresses the predefined filters you are speaking about HERE. However, it is not available on the user level. Meaning that the filter won’t be applied based on the user who access the dashboard. If you have too many user the dashboards could get quite messy, so maybe you could limit the data the users see based on DATA PERMISSIONS.
🙌 1
m
waw first thanks for your quick response ! let me go through this...
ok, so if I want to use iframes, I won't be able to preselect filters for each of my users. That's good to know. the problem with permissions is I do want to allow the user to see other things, I just need the filters preselected for him, so he immediately sees the dashboard he's interested in. If I use permissions the user won't see the other filters right ? What about the react GoodData.UI ? Can I do that with it ?
t
Hello @Merwane Hamadi, it is possible to dynamically set a filter context even with iFrames. It will require your host app to send a post message like this:
Copy code
document.getElementById(IFRAME_ID).contentWindow.postMessage(
  {
    gdc: {
      product: "dashboard",
      event: {
        name: "setFilterContext",
        data: {
          filters: [newFilter]
        }
      }
    }
  },
  backend
);
Check the following article for more details: https://community.gooddata.com/sdks-and-apis-kb-articles-52/embedding-dashboards-into-your-application-206 Note: Dashboard component in GoodData.UI allows to set the filter context as well: https://sdk.gooddata.com/gooddata-ui/docs/dashboard_component.html#base-props
🙌 1
m
Great news thanks !
I am going to take a look at that, are there any limitation I should be aware of before we build iframes and we realize 2 months later we have to switch to React ? Will it be hard to switch in your opinion ?
t
I as an UX designer would not dare to recommend one over the other. Feel free to ask this question directly to the community, I believe others will provide you with valid pros and cons. In the meantime, check this community article that summarises the topic. https://community.gooddata.com/sdks-and-apis-kb-articles-52/embedding-via-iframe-vs-gd-ui-dashboardview-291
👀 1
m
ok thanks for your help, I followed the tutorial and I have added a setFilter function (this is a blade page using php)
Copy code
@extends('app')

@section('content')

<form id="helperForm" target="embeddedGoodDataIframe" method="post" action="{{ $customerLoginUrl }}">
    <input id="targetUrl" type="hidden" name="targetUrl" value="{{ $targetUrl }}"/>
    <input id="ssoProvider" type="hidden" name="ssoProvider" value="{{ $ssoProvider }}"/>
    <input id="encryptedClaims" type="hidden" name="encryptedClaims" value=""/>
</form>

<iframe id="embeddedGoodDataIframe" style="height: calc(100vh - 125px);width:100%" name="embeddedGoodDataIframe" frameborder="0"></iframe>
@endsection
<script>
    document.addEventListener('DOMContentLoaded', () => {
      let pgpMessage = `{{ $encryptedClaims }}`;
      document.getElementById('encryptedClaims').value = pgpMessage;
      document.getElementById('helperForm').submit();

      const newFilter = {
        id: "yourAttributeOrMeasureIdentifier",
        type: "attribute", // or "measure"
        operator: "IN",
        values: ["value1", "value2", "value3"]
      };
      const backendUrl = "*"; // Replace this with the actual backend URL
      setFilter(newFilter, backendUrl);
    });



    function setFilter(newFilter, backend) {
      const IFRAME_ID = "embeddedGoodDataIframe";
      document.getElementById(IFRAME_ID).contentWindow.postMessage(
        {
          gdc: {
            product: "dashboard",
            event: {
              name: "setFilterContext",
              data: {
                filters: [newFilter]
              }
            }
          }
        },
        backend
      );
    }
</script>
Question: • what's the backend supposed to be is it the targeturl ? • as you can see I want to hardcode a filter just to try. but I can't find the id of this filter. I am in my dashboard and trying to find the place where the id is mentioned.
t
Hello @Merwane Hamadi, which version of GoodData are you using? GoodData Platform or GoodData Cloud / GoodData.CN?
m
this is our endpoint: https://redica.poc.gooddata.com/
probably gooddata platform
t
Thank you @Merwane Hamadi. @Jiri Zajic would you be able to help here?