useInsightDataView
Load a saved visualization by reference and return its execution result as a DataViewFacade with optional filters and sorting.
React hook that loads a saved visualization by reference and returns its execution result as a DataViewFacade. For ad-hoc executions, use useExecutionDataView.
Basic usage
import { useInsightDataView } from "@gooddata/sdk-ui";
import { idRef } from "@gooddata/sdk-model";
function VisualizationData({ visualizationId }: { visualizationId: string }) {
const { result, status, error } = useInsightDataView({
insight: idRef(visualizationId),
});
if (status === "loading" || status === "pending") {
return <div>Loading...</div>;
}
if (status === "error") {
return <div>Error: {error?.message}</div>;
}
const data = result?.data().slices().toArray();
// ...
}
Parameters
| Property | Type | Description |
|---|---|---|
insight | ObjRef | Reference to the saved visualization. When not provided, the hook stays in "pending" state. |
filters | INullableFilter[] | Additional filters to merge with the visualization’s own filters. |
sorts | ISortItem[] | (def: IExecutionDefinition) => ISortItem[] | Custom sorting for the execution. |
window | DataViewWindow | Load only a specific data window (for paging). |
executeByReference | boolean | Execute by reference to the saved visualization instead of sending the full execution definition. Required by some backends. |
backend | IAnalyticalBackend | Backend override (defaults to BackendProvider context). |
workspace | string | Workspace override (defaults to WorkspaceProvider context). |
Return value
UseCancelablePromiseState<DataViewFacade, GoodDataSdkError>, the same shape as useCancelablePromise returns.
| Field | Type | Description |
|---|---|---|
status | "pending" | "loading" | "success" | "error" | Combined state of the visualization load and the execution. |
result | DataViewFacade | undefined | The loaded data view. Set only in the "success" state. |
error | GoodDataSdkError | undefined | The first error: from the visualization load, otherwise from the execution. |
States
The hook works in two steps: it loads the visualization, then executes it through useExecutionDataView. The returned status is the status of the first step that has not succeeded yet.
status | result | error | When |
|---|---|---|---|
"pending" | undefined | undefined | insight is not provided. |
"loading" | undefined | undefined | The visualization is being loaded, or it is loaded and its execution is running. |
"success" | DataViewFacade | undefined | The visualization loaded and its data view was read. |
"error" | undefined | The visualization-load error or a GoodDataSdkError | Loading the visualization or executing it failed. |
When it re-runs
- The visualization is loaded again when
backend,workspace, theinsightreference (compared by its string form, so a newidRef()object with the same identifier does not reload), or an item indepschanges. - The hook rebuilds the prepared execution on every render from the loaded visualization,
filters,sorts,dimensions,dateFormat, andexecuteByReference. The execution runs again when the fingerprint of that prepared execution changes, and whenbackend,workspace,window.offset,window.size(by reference),enableExecutionCancelling, or an item indepschanges. - A superseded or unmounted load is canceled the same way as in useExecutionDataView: its result is ignored, and the execution request is aborted only when
enableExecutionCancellingistrue.
Notes
- Without a
backendprop or aBackendProvider, the hook throws: “useInsightDataView: IAnalyticalBackend must be defined. Either pass it as a parameter or make sure there is a BackendProvider up the component tree.” A missing workspace throws the matchingWorkspaceProvidererror. - The
backendandworkspaceprops take precedence over the context values. sorts,dimensions, anddateFormataccept either a value or a function. The function receives the execution definition of the visualization and returns the value to apply.- The callbacks
onLoading,onPending,onSuccess,onError, andonCanceltrack only the execution step. While the visualization is loading,onPendingis called, notonLoading. A failed visualization load is returned inerrorbut does not callonError. - Errors from the visualization load are returned as the backend rejects them. Only execution errors are converted to a
GoodDataSdkErrorsubtype. window.offsetandwindow.sizeare arrays compared by reference. Keep them stable; a new array on every render starts a new execution on every render.
Props
| Prop | Type | Required | Description | Inherited from |
|---|---|---|---|---|
backend | IAnalyticalBackend | No | Backend to work with. | — |
dateFormat | string | ((def: IExecutionDefinition) => string) | No | Modify date formatting on prepared insight execution, before it’s executed. | — |
dimensions | IDimension[] | ((def: IExecutionDefinition) => IDimension[]) | No | Modify dimensions on prepared insight execution, before it’s executed. | — |
enableExecutionCancelling | boolean | No | Optionally enable real execution cancellation. This means that if the execution request is not yet finished and the execution changes, the request will be cancelled and the new execution will be started. Default: false | — |
executeByReference | boolean | No | Indicates that the execution to obtain the data for the insight should be an ’execution by reference’. Execution by reference means that the useInsightDataView will ask analytical backend to compute results for an insight which is stored on the backend by specifying link to the insight, additional filters and description how to organize the data. Otherwise, a freeform execution is done, in which the InsightView will send to backend the full execution definition of what to compute. This distinction is in place because some backends MAY want to prohibit users from doing freeform executions and only allow computing data for set of insights created by admins. Note: the need for execute by reference is rare. You will typically be notified by the solution admin to use this mode. | — |
filters | INullableFilter[] | No | Specify filters to merge with filters already defined in the insight. | — |
insight | ObjRef | No | Reference to the insight for which you want to get the data view. | — |
sorts | ISortItem[] | ((def: IExecutionDefinition) => ISortItem[]) | No | Modify sorts on prepared insight execution, before it’s executed. | — |
window | DataViewWindow | No | You can define only a specific “window” of data to load. | — |
workspace | string | No | Workspace where execution should be executed. | — |
Related
Run a saved visualization and pass the resulting data view to a render-prop child.
Fetch execution data as a DataViewFacade from a prepared execution or inline seriesBy/slicesBy configuration.
Read measures, attributes, filters, and identity from IInsight with the insight* accessors, and derive copies with insightSet*.
Render any saved GoodData visualization by reference with the InsightView component.
Use useDataExport to run CSV, XLSX, or raw exports from a prepared execution, handle export lifecycle callbacks, and retrieve the download URI.