Vikraman
11/22/2024, 8:55 AMfilterContextRef
referring to the documentation Dashboard Props
To understand how it works, I’m starting with a constant filter value to verify its functionality.
To achieve this, I examined the API requests made when filters are applied after opening the dashboard. The relevant URL for the API request is:
https://{env}.cloud.gooddata.com/api/v1/actions/workspaces/{workspaceId}/execution/afm/execute
for which the payload was as follows
{
"resultSpec": {
"dimensions": [
{
"localIdentifier": "dim_0",
"itemIdentifiers": [
"measureGroup"
]
}
],
"totals": []
},
"execution": {
"measures": [
{
"localIdentifier": "m_c_gwp_100_sum",
"definition": {
"measure": {
"item": {
"identifier": {
"id": "c_gwp_100",
"type": "fact"
}
},
"aggregation": "SUM"
}
}
}
],
"attributes": [],
"filters": [
{
"positiveAttributeFilter": {
"label": {
"identifier": {
"id": "org_id",
"type": "label"
}
},
"in": {
"values": [
"ABC"
]
}
}
}
],
"auxMeasures": []
},
"settings": {}
}
I tried to replicate this and create a filter context and passed it to embedded dashboard
const orgFilter = newPositiveAttributeFilter(
idRef("org_id", "label"), // matches the id from JSON
["ABC - XYZ"]
);
const filterContext = {
filtersByIdentifier: {
orgFilter: orgFilter
}
};
<Dashboard
config={{ initialRenderMode: 'view', isReadOnly: true }}
dashboard={props.dashboardId}
filterContextRef={filterContext}
/>
But it doesn't work, and I get the Unexpected URI: "undefined"
in the dashboard page. I don't see any failed APIs in the network tab.
Is this the correct approach, or is there a better way to achieve this?Julius Kos
11/22/2024, 12:13 PMVikraman
11/22/2024, 12:19 PMVikraman
11/25/2024, 10:07 AMVikraman
11/26/2024, 8:54 AMconst filterContextRef = {
content: {
filters: [
{
attributeFilter: {
displayForm: {
identifier: {
id: "org_id",
type: "label"
}
},
attributeElements: {
uris: ["Titan - XYZ", "Titan - ABC"]
},
negativeSelection: false,
selectionMode: "multi"
}
}
],
version: "2"
}
};
and I passed the same in dashboard as follows
<Dashboard
config={{ initialRenderMode: 'view', isReadOnly: true }}
dashboard={props.dashboardId}
filterContextRef={filterContextRef}
/>
But the issue still persists. I want to clarify my goal: I would like to apply filters directly when generating the dashboard, rather than using the filters from the dashboard page.
Any insights on this will be appreciated. Thanks!Radek Novacek
11/26/2024, 2:58 PMVikraman
11/26/2024, 3:21 PMVikraman
11/27/2024, 12:33 PMVikraman
11/28/2024, 1:18 PMRadek Novacek
11/28/2024, 1:20 PMVikraman
11/28/2024, 1:24 PMRadek Novacek
11/28/2024, 3:09 PMfilterContextRef
is that this needs a URI to the filter definition existing on the backend - as such, you would have to implement logic where the filters in your app are sent to our REST API, and the resulting URI is then used as the reference to load the Dashboard.
On the other hand, dispatch commands are also used in our own filter loading on the website - it is implemented through events/actions. Essentially, we listen to dashboard init and dispatch action to set the filter state.
Next up, for Md.RestaurantCategory
- this is a reference to an attribute existing in the local metadata catalog; the catalog is exported via a tool we provide, and it essentially provides a handy way to reference your metadata objects (attributes, metrics and so on) in code! If you execute the export tool, you will end up with a file like catalog.ts
in the src
folder - importing this in your script allows you to refer to your objects easier.
As far as /gdc/md/
paths go, this is the GD Platform API - for GD Cloud, the equivalent is /api/v1/entities/workspaces/{workspaceId}/attributes/{objectId}
(or replace with "metrics" for metrics 🙂). Similarly, if you want to get all attributes/metrics, you can just leave out the objectId! This would be the preferred way of getting your list of IDs if you decided not to use the metadata catalog export instead.
I know I kind of aggregated the list into a free-flow answer, but I think this about covered all that should be helpful to the implementation/relevant to GD Cloud! 🙂Vikraman
11/29/2024, 3:57 PMuris: ["/gdc/md/xms7ga4tf3g3nzucd8380o2bev8oeknp/obj/2196/elements?id=1"]
We are currently trying to construct a similar URI for our use case. However, we are unsure about what 2196
and id=1
represent in this context. When we used the endpoint:
/api/v1/entities/workspaces/{workspaceId}/attributes/{objectId}
we couldn’t identify the corresponding values for 2196
in the API response.
Could you please provide more clarity on the meaning of 2196
and id=1
? If there’s any relevant documentation or additional examples available, we would greatly appreciate it if you could share them.
Thank you for your assistance.Radek Novacek
11/29/2024, 5:53 PMRadek Novacek
12/04/2024, 2:00 PMVikraman
12/17/2024, 7:41 AM