Hi, I’m trying to use the `useInsightDataView` hoo...
# gooddata-ui
e
Hi, I’m trying to use the
useInsightDataView
hook to get all the relevant data from a table insight, but I’m not seeing how to get aggregate row data out of the results it returns (the footer rows stuff like sum of a measure across all rows of the table). One thing I noticed is that in the request payload of the
afm/execute
calls generated by the hook,
resultSpec.totals
is always left empty, whereas when looking at the
afm/execute
calls made by the Analyze tool over the same insight it does have values in there. I’ve also tried using
<ExecuteInsight>
to similar results. Is there an easy way to get
useInsightDataView
to also fetch these aggregate rows? Currently it’s looking like I will have to make a separate call to the analytical backend to get the insight definition, then create new dimensions from the attribute bucket’s
totals
to give to
useInsightDataView
. I wanted to make sure that this is the correct path and I’m not missing something that could save some work. Thanks!
👍 1
j
Hello @Evan Shen! What you're looking for is achievable, but not with
useInsightDataView()
. You'll want to investigate a more programmatic approach with
backend.workspace().execution()
. Please see https://sdk.gooddata.com/gooddata-ui-apidocs/v8.12.0/docs/sdk-backend-spi.ipreparedexecution.html and https://community.gooddata.com/gooddata-ui-kb-articles-48/dimensions-in-custom-executions-716. The article shows how to add custom dimensions to the execution, and in a similar manner you should be able to add custom totals and other aspects. Hope that helps!
e
I’m aware of adding dimensions, but it seems like even with custom executions I would still need to first obtain the insight definition to even know what totals are needed. Was hoping I could do it in just a single call, chaining fetches like this leads to a slow user experience. While we’re at it, I’d like to put in a feature request for
useInsightDataView()
and
<ExecuteInsight>
to include
grandTotals
data in the response. It is unintuitive that such tools intended for getting everything about an insight aren’t actually returning everything.
i
@Evan Shen Hi, there is difference between Insight and Execution. Insight defines its own execution in form so it can then parse and visualize its result. If you add totals or something which Insight can not understand then it is useless. To define your own execution including totals yuo can check
withDimensions(..._dim_: Array<IDimension | DimensionGenerator>): IPreparedExecution;
method and interface
Copy code
export interface IDimension {
    /**
     * List of localIdentifier's of attribute to put in this dimension.
     */
    itemIdentifiers: Identifier[];

    /**
     * List of totals to include in this dimension.
     */
    totals?: ITotal[];
}
Totals are defined declaratively as part of dimension def. This enhanced execution needs enhanced counter part Insight/custom visualization in you app.
e
ok, but I will still need to first get the totals information correct? From what I’m seeing and hearing there is no way to get an execution definition for an insight that already includes dimensions with totals
i
I am afraid so
e
Alright, thank your for the confirmation
I would still like to request that in future versions the GoodData team considers adding totals information to these hooks/components. It is only natural to expect them to return a comprehensive definition of the insight made in Analyze
i
So far only Analyze visualization supporting Totals is Table. If you create its definition in Analyze including Totals you will get totals as a part of this insight definition and its execution.
e
That is not the behavior I am experiencing, as described in my original message
I am currently using
@gooddata/sdk-ui-all@8.11.0
i
This is saved table definition from our GoodData Cloud platform:
Copy code
{
    "data": {
        "id": "8fb1fdf5-73de-4f8b-abc8-4865c6939f01",
        "type": "visualizationObject",
        "attributes": {
            "title": "Table with avg total",
            "description": "",
            "content": {
                "buckets": [
                    {
                        "items": [
                            {
                                "measure": {
                                    "localIdentifier": "726d013e645c4aa6abb9b317c51fc4fd",
                                    "definition": {
                                        "measureDefinition": {
                                            "item": {
                                                "identifier": {
                                                    "id": "f_population",
                                                    "type": "fact"
                                                }
                                            },
                                            "aggregation": "sum",
                                            "filters": []
                                        }
                                    },
                                    "title": "Sum of Population",
                                    "format": "#,##0.00"
                                }
                            }
                        ],
                        "localIdentifier": "measures"
                    },
                    {
                        "items": [
                            {
                                "attribute": {
                                    "localIdentifier": "f41f70c82cad479e841fe0c3f609803c",
                                    "displayForm": {
                                        "identifier": {
                                            "id": "f_city.id.cityname",
                                            "type": "label"
                                        }
                                    }
                                }
                            }
                        ],
                        "localIdentifier": "attribute",
                        "totals": [
                            {
                                "type": "avg",
                                "measureIdentifier": "726d013e645c4aa6abb9b317c51fc4fd",
                                "attributeIdentifier": "f41f70c82cad479e841fe0c3f609803c"
                            }
                        ]
                    }
                ],
                "filters": [],
                "sorts": [
                    {
                        "attributeSortItem": {
                            "attributeIdentifier": "f41f70c82cad479e841fe0c3f609803c",
                            "direction": "asc"
                        }
                    }
                ],
                "properties": {},
                "visualizationUrl": "local:table",
                "version": "2"
            }
        },
        "meta": {
            "origin": {
                "originType": "NATIVE",
                "originId": "adff2de919ab43849ef91f1c79d33522"
            }
        }
    },
}
And in definition of table’s attribute, you can see also its total defined
Copy code
"totals": [
   {
      "type": "avg",
      "measureIdentifier": "726d013e645c4aa6abb9b317c51fc4fd",
      "attributeIdentifier": "f41f70c82cad479e841fe0c3f609803c"
   }
]
This is RAW object, but the same total definition should be accessible also via Gooddata SDK.UI types and abstractions