ExecuteInsight
Run a saved visualization and pass the resulting data view to a render-prop child.
The ExecuteInsight component loads a visualization saved in the workspace (referenced by ObjRef), runs its execution, and passes the loading state, error, and data view to its children render function. Use it to render the data of a saved visualization with your own code instead of InsightView.
Basic usage
import { ExecuteInsight } from "@gooddata/sdk-ui";
import { idRef } from "@gooddata/sdk-model";
export const Example = () => (
<ExecuteInsight insight={idRef("<visualization-id>")}>
{({ isLoading, error, result }) => {
if (isLoading) {
return <div>Loading...</div>;
}
if (error) {
return <div>Error: {error.message}</div>;
}
return <pre>{JSON.stringify(result?.dataView.data, null, 2)}</pre>;
}}
</ExecuteInsight>
);
States
The children function receives a WithLoadingResult in one of these states.
isLoading | result | error | When |
|---|---|---|---|
false | undefined | undefined | Before the first load starts: on the first render and, when loadOnMount is false, until you call reload() or a prop change triggers a new execution. |
true | undefined | undefined | The visualization is loading or its execution is running. |
false | DataViewFacade | undefined | The data was loaded. An empty result is returned here, not as a NoDataError. |
false | undefined | GoodDataSdkError | Loading the visualization, the execution, or the data read failed. |
reload is available in every state and starts a new execution.
Rendering
ExecuteInsight picks what to render in this order:
| Condition | Renders |
|---|---|
ErrorComponent is set and there is an error | ErrorComponent with the error prop. |
LoadingComponent is set and isLoading is true | LoadingComponent. |
Both LoadingComponent and ErrorComponent are set and there is no result | Nothing (null). |
| Otherwise | The children function. |
When you set both LoadingComponent and ErrorComponent, children is called only with a successful result.
When it re-runs
ExecuteInsightstarts a new execution wheninsight,filters, orwindowchanges by deep comparison.- It also starts a new execution when
onError,onLoadingChanged,onLoadingFinish, oronLoadingStartchanges by reference. Memoize these callbacks. - Changing
sorts,dimensions, ordateFormatalone does not start a new execution. Callreload()to apply them. - When a new execution starts before the running one finishes, the running one is canceled. The request itself keeps running unless
enableExecutionCancellingistrue; then its signal is aborted.
Notes
backendandworkspaceprops take precedence overBackendProviderandWorkspaceProvider. If neither is available, the load fails with an error.filtersare added to the filters saved in the visualization.sorts,dimensions, anddateFormatoverride the saved ones; each also accepts a function that receives the execution definition and returns the value.- Set
executeByReferenceto run the saved visualization by reference instead of sending its full definition. Use it only when your backend requires executions tied to stored visualizations. - Set
loadOnMount={false}to skip the initial run, and callreload()to start it. - Without
window,ExecuteInsightreads all data. Passwindowwithoffsetandsizearrays to read one page. exportTitledefaults tocomponentName, which defaults to"ExecuteInsight".
Props
| Prop | Type | Required | Description | Inherited from |
|---|---|---|---|---|
children | (executionResult: WithLoadingResult) => ReactElement | null | Yes | Child component to which rendering is delegated. | — |
insight | ObjRef | Yes | Reference to the insight for which you want to get the data view. | — |
backend | IAnalyticalBackend | No | Backend to execute against. | — |
componentName | string | No | Informative name of the component. | — |
dateFormat | string | ((def: IExecutionDefinition, props: IExecuteInsightProps) => string) | No | Modify date formatting on prepared insight execution, before it’s executed. | — |
dimensions | IDimension[] | ((def: IExecutionDefinition, props: IExecuteInsightProps) => 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 | — |
ErrorComponent | IExecuteErrorComponent | No | Provide component for rendering of the error state. | — |
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 ExecuteInsight 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. | — |
exportTitle | string | No | Name to use for files exported from this component. | — |
filters | INullableFilter[] | No | Filters to apply on server side. | — |
LoadingComponent | IExecuteLoadingComponent | No | Provide component for rendering of the loading state. | — |
loadOnMount | boolean | No | Specifies whether Execute should trigger execution and loading right after it is mounted. | — |
sorts | ISortItem[] | ((def: IExecutionDefinition, props: IExecuteInsightProps) => ISortItem[]) | No | Modify sorts on prepared insight execution, before it’s executed. | — |
window | DataViewWindow | No | Specifies whether Execute should load all data from backend or just a particular window - specified by offset and size of the window. | — |
workspace | string | No | Workspace in whose context to perform the execution. | — |
onError | (error: GoodDataSdkError, props: TProps) => void | No | If specified, this function will be called in case loading runs into an error. | IWithLoadingEvents |
onExportReady | (exportFunction: IExportFunction, props: TProps) => void | No | Called when loading finishes and it is possible to export the underlying data. Function that does the export will be provided on the callback. | IWithLoadingEvents |
onLoadingChanged | (isLoading: boolean, props: TProps) => void | No | Called when loading starts and finishes, indicating the current state using the isLoading parameter. | IWithLoadingEvents |
onLoadingFinish | (result: DataViewFacade, props: TProps) => void | No | Called when loading finishes. | IWithLoadingEvents |
onLoadingStart | (props: TProps) => void | No | Called when loading starts. | IWithLoadingEvents |
Related
Load a saved visualization by reference and return its execution result as a DataViewFacade with optional filters and sorting.
Fetch and render backend data with the Execute component using series, slices, filters, and a render-prop child.
Run a prepared execution and pass the resulting data view to a render-prop child.
Render any saved GoodData visualization by reference with the InsightView component.