Hi everyone, we are embedding a Gooddata dashboard...
# gooddata-ui
r
Hi everyone, we are embedding a Gooddata dashboard and we have our own components on the same page. Any user interaction with our component causes the gooddata dashboard to refresh (this makes sense since the component is being re-rendered). Is there any way to stop this behavior as far as the dashboard is concerned?
So we actually found a workaround for this. When rendering a
<Dashboard />
component, instead of passing the dashboard prop as
idRef(dashboardId)
if we just pass the dashboardId string, it doesn't make the re-renders. I'm just not sure why that is. From the source, it seems like ifRef just wraps the dashboardId in an object. If anyone has any ideas I'd really appreciate it.
r
Hi there Ramtin, Radek from the GoodData technical team, let me have a look and come back to you!
How are your components implemented with the Dashboard? Normally, React would re-render the whole page only if there are state changes within the page, but if the states being changed are contained within the component, the re-render should affect just the component itself.
r
Hi Radek, the state changes are within the page, causing the component to be re-rendered. We fixed it by removing idRef from the dashboardId and instead just passing the dashboardId to the dashboard prop. It works, I'm just not sure why. I figured I'd drop it here to see if anyone would know. Thank you for your response
Radek, another question if I may. We are embedding gooddata dashboards in our application using the
<Dashboard />
component. There are a default set of filters applied from the filterContext, but we would like users on our application to be able to set their own filters and for the filter to not go away after the page refreshes. So different users should be able to have different filters on the same dashboard embedded in our application. It seems like this is not natively possible, a work around I am thinking of is to somehow collect the filter state per user and save it in our database. I would like to be able to save this filter configuration per user, and pass them as props to the
<Dashboard />
component to change the filters dynamically per user. Is this a possibility? I don't see any props to change filter state in the application without creating a filter context first. I'm not even sure of the correct way to collect the filters and handle changes. Ideally, we'd be able to save some json configuration for the user and pass that to the dashboard component. Thank you for your help!
r
Ooh, I definitely like the idea for this implementation 🙂 I'll have to check with the devs, will come back to you!
🙏 1
Hi Ramtin, I've had some dev feedback on this, and essentially, the practical way of doing this would be the following: To provide filters to the Dashboard component you should use only a form of filterContext. You can do that by two different props:
Copy code
/*
     * Specify dashboard to render; you can specify the dashboard either by reference (ObjRef) or
     * by value (of type IDashboard).
     *
     * @remarks
     * As a convenience, you may also specify a dashboard object
     * identifier - this is same as using idRef(objectIdentifier).
     *
     * If you do not specify dashboard to render, a new default empty dashboard will be rendered.
     */
    dashboard?: string | ObjRef | IDashboard;
Provide already loaded IDashboard and put filterContext directly into it. Then the place where you would store custom per user filterContexts is up to you. Or you can provide custom filterContext via its ref:
Copy code
/*
     * Specify reference to a filter context that should be used instead of the default,
     * built-in filter context.
     *
     * @remarks
     * Note: this property only makes sense if you also specify dashboard by reference. If you specify
     * dashboard by value, then the component assumes that the value also contains the desired filter context
     * and will use it as is.
     */
    filterContextRef?: ObjRef;
Then custom filter context itself needs to be stored directly in our MD server and you can store only mapping between the user and the customFilterContext ref on your side. Realistically, this whole implementation may be a good time to look into whether Dashboard plugins would fit your use-case as well 🙂
r
Thank you for your help Radek! So if I understand correctly, we will need to create a new context filter for each user via API? Also, is there an obvious way to get the filter "state" for the dashboard component easily? I see the
FilterBarComponent
prop but I was wondering if there are any other ways also. Thank you again!
r
Correct, the filter definitions would be per user (or you could organize your users into groups on your side). For the filter state, it may be worth having a look at the implementation of a Dashboard with a DashboardStore accessor we have in the examples gallery - the filter context definitions are returned within the DashboardStore.
r
Thank you, I will take a look at this 🙏
a
Hi @Radek Novacek, my colleague @Ramtin Ghassemi ask for this but we didn’t get an answer:
So we actually found a workaround for this. When rendering a
<Dashboard />
component, instead of passing the dashboard prop as
idRef(dashboardId)
if we just pass the dashboardId string, it doesn’t make the re-renders. I’m just not sure why that is. From the source, it seems like ifRef just wraps the dashboardId in an object. If anyone has any ideas I’d really appreciate it.
now, we are struggling with the same issue with
filterContextRef={idRef(filterContextId)}
, this time the workaround of using the id as a string doesn’t work. We need explicitly to use
idRef
and this makes the dashboard rerender on every react render. Any help on this? Thanks
👀 1