Read attribute hierarchies
An attribute hierarchy is a named, ordered list of attributes that describes a drill path — for example Country, then State, then City. Dashboards use a saved hierarchy to let viewers drill from one level to the next on a widget.
Read hierarchies from the catalog
Saved hierarchies are catalog items. Load them the same way as measures and attributes — see Load the workspace catalog at runtime — by including "attributeHierarchy" in forTypes, then read them off the loaded IWorkspaceCatalog:
import { type IAnalyticalBackend } from "@gooddata/sdk-backend-spi";
export async function loadHierarchies(backend: IAnalyticalBackend, workspace: string) {
const catalog = await backend.workspace(workspace).catalog().forTypes(["attributeHierarchy"]).load();
return catalog.attributeHierarchies();
}
catalog.attributeHierarchies() returns every ICatalogAttributeHierarchy in the workspace. Use catalog.availableAttributeHierarchies() instead when you have already narrowed the catalog to items compatible with a specific measure or visualization (see Offer only compatible items).
Each ICatalogAttributeHierarchy wraps an IAttributeHierarchyMetadataObject, which carries the ordered attributes: ObjRef[] — the drill path, from top level to bottom.
List hierarchies from a dashboard plugin
To list the hierarchies available in the workspace from inside a plugin, use the @beta selector selectCatalogAttributeHierarchies with useDashboardSelector:
import { selectCatalogAttributeHierarchies, useDashboardSelector } from "@gooddata/sdk-ui-dashboard";
const hierarchies = useDashboardSelector(selectCatalogAttributeHierarchies);
See Dashboard component for the rest of the dashboard selector surface.
Notes
attributeson a hierarchy is ordered top to bottom. Reordering it changes the drill path, not just its membership.
Related
Load measures, attributes, and date datasets while your application runs, and turn catalog items into IMeasure and IAttribute objects.
Create and modify IAttribute objects with newAttribute, apply optional local identifiers and alias overrides.
Read Dashboard component state with useDashboardSelector and the select* selectors, from components, event handlers, and outside code.
Embed a saved dashboard with Dashboard, read its state through selectors, dispatch commands, handle events, configure behavior, and access its store externally.
Configure drillableItems with header predicates to make visualization measures or attributes interactive and receive drill event context.