Skip to main content

Hooks

useActivePivotClient#

React hook returning the ActivePivotClient at serverKey.

useActivePivotClient(serverKey)
ArgumentTypeDescription
serverKeystring | undefined
Returns:

ActivePivotClient | undefined

Throws:

ClientsNotFoundError when no clients are provided via ClientsProvider.

ActivePivotClientNotFoundError when serverKey is defined but no ActivePivotClient is provided for this key via ClientsProvider.

useActivePivotClients#

React hook returning the map of all registered ActivePivotClients.

useActivePivotClients()
Returns:

{ [serverKey: string]: ActivePivotClient; }

useActivity#

React hook returning:

  • the value for the given activity key

  • a function to update this value

  • whether the activity is loading

useActivity(key)
ArgumentTypeDescription
keyT
Returns:

[Activity[T] | null, (value: Activity[T]) => void, { isLoading: boolean; }]

useCanShare#

Deprecated

React hook returning whether the current user is allowed to share content. This is a specialized version of usePermission that handles deprecated usage of the ROLE_SHARE role until it is removed in 5.0

useCanShare()
Returns:

boolean

useConnectionStatuses#

React hook returning the overall status of the connection with the registered ActivePivot clients.

useConnectionStatuses()
Returns:

{ [serverKey: string]: ConnectionStatus; }

useContentClient#

React hook returning the ContentClient.

useContentClient()
Returns:

ContentClient

Throws:

ClientsNotFoundError when no clients are provided via ClientsProvider.

ContentClientNotFoundError when no ContentClient is provided via ClientsProvider.

useDataModel#

React hook returning the DataModel of the ActivePivot server identified by serverKey.

useDataModel(serverKey)
ArgumentTypeDescription
serverKeystring | undefined
Returns:

DataModel | undefined

Throws:

DataModelNotFoundError when serverKey is defined but the data model could not be found.

useDataModels#

React hook returning the data models of all ActivePivot servers to which the client is connected.

useDataModels()
Returns:

{ [serverKey: string]: DataModel; }

useDrillthroughColumns#

React hook returning the drillthrough columns for a given cube. Lazily fetches the columns on the server the first time this hook is invoked.

Returns:

  • the columns if they are loaded

  • isLoading: a boolean indicating if the loading is in progress

  • error: the error thrown while attempting to fetch the drillthrough columns (only returned if the drillthrough columns are missing because an error was thrown) Returns undefined If serverKey is undefined.

useDrillthroughColumns(serverKey, cubeName)
ArgumentTypeDescription
serverKeystring | undefined
cubeNamestring
Returns:

[DrillthroughColumn[] | undefined, { isLoading: boolean; error?: Error; }] | undefined

useIsModalMounted#

Hook returning whether a modal should be mounted/unmounted depending on whether it is visible. It allows to reset the state of a Modal declaratively, without losing Ant Design's close animation.

See https://github.com/activeviam/activeui-5/pull/1465\#issuecomment-862306468.

useIsModalMounted(isModalVisible)
ArgumentTypeDescription
isModalVisibleboolean
Returns:

boolean

For example:
const ModalParent = () => {  const [isModalVisible, setIsModalVisible] = useState(false);  const isModalMounted = useIsModalMounted(isModalVisible);  const handleModalClosed = () => {setIsModalVisible(false);};  return isModalMounted &&     <Modal         isVisible={isModalVisible}         onSubmit={handleModalClosed}         onCancel={handleModalClosed}      >         <ModalChildren />     </Modal>}

useIsPresenting#

React hook returning the current state of isPresenting.

useIsPresenting()
Returns:

boolean

useMultiSelection#

React hook that handles multiple selection of items. It takes the initially selected ranges as argument. It returns:

  • the ranges of selected elements,

  • a callback to handle the selection event,

  • a callback to clear the selection.

The selection callback handles combining the selections using the Ctrl and Shift keys.

useMultiSelection(initiallySelectedRanges)
ArgumentTypeDescription
initiallySelectedRangesRange[]
Returns:

{ selectedRanges: Range[]; onItemSelected: (index: number, event: MouseEvent<unknown, unknown>) => void; clearSelection: () => void; }

usePermission#

React hook returning:

  • the permission value for the given key

  • a function to update this permission when authenticated as a user with admin privileges

  • an object indicating whether the permissions are loading and whether the permission has explicitly been set

usePermission(key)
ArgumentTypeDescription
keyT
Returns:

[ Permissions[T], (value: Permissions[T]) => Promise<void>, { isLoading: boolean; isSet: boolean; } ]

usePersisted#

React hook returning the value for the key in the browser local storage and the function to update it.

usePersisted(key, initialValue)
ArgumentTypeDescription
keystring
initialValueT
Returns:

[T | undefined, (newValue: T) => void]

usePositionInDashboard#

Returns the PositionInDashboard of the widget in the dashboard.

usePositionInDashboard()
Returns:

PositionInDashboard | null

useQuery#

React hook returning the up-to-date Query corresponding to queryId.

useQuery({   serverKey,   queryId, })
ArgumentTypeDescription
{
   serverKey,
   queryId,
}
{
   serverKey?: string;
   queryId?: string;
}
Returns:

Query<MdxString> | undefined

useQueryResult#

React hook allowing to subscribe to a query's result. If query is provided, also runs the query.

useQueryResult({   serverKey,   queryId,   query, })
ArgumentTypeDescription
{
   serverKey,
   queryId,
   query,
}
{
   serverKey?: string;
   queryId?: string;
   query?: Query<MdxString>;
}
Returns:

QueryResult<ResultType>

Remarks:

If queryId is not provided, the subscription is canceled and an empty result is returned.

useSetting#

React hook returning:

  • the setting value for the given key

  • a function to update this setting

  • an object containing a property for whether the settings are loading

useSetting(key)
ArgumentTypeDescription
keyT
Returns:

[ Settings[T], (value: Settings[T]) => Promise<void>, { isLoading: boolean; } ]

useSwitchedWidgetState#

React Hook returning the switched widget state if switched or the original state if not switched.

useSwitchedWidgetState(widgetState, queryId)
ArgumentTypeDescription
widgetStateWidgetState
queryIdstring
Returns:

WidgetState

useTheme#

React hook returning the Theme.

useTheme()
Returns:

Theme

useTree#

React hook returning the dashboards or widgets tree.

useTree(type)
ArgumentTypeDescription
typeT
Returns:

ContentRecord<DashboardMetaData | WidgetMetaData | FilterMetaData> | null

useUser#

React hook returning the user from context.

useUser()
Returns:

User

Throws:

UserNotFoundError when no User is provided via UserProvider.

useUserGroupNames#

React hook returning the user group names from context.

useUserGroupNames()
Returns:

UserGroupName[] | null

useUserNames#

React hook returning the provided user names from context.

useUserNames()
Returns:

UserName[] | null

useWidgetName#

React Hook returning either widgetState.name if defined otherwise returns a translated initial name from the widget plugin.

useWidgetName(widgetState)
ArgumentTypeDescription
widgetStateAWidgetState
Returns:

string

useWidgetPluginKeys#

React hook returning the keys of all the registered widget plugins.

useWidgetPluginKeys()
Returns:

string[]

useWidgetPlugins#

React hook returning the widget plugins corresponding to widgetKeys.

useWidgetPlugins(widgetKeys)
ArgumentTypeDescription
widgetKeysstring[]
Returns:

WidgetPlugin[]

useWidgetQuery#

Deprecated

use useWidgetQueryResult to run your query directly instead.

Returns the widget's Query, impacted by the user/dashboard/page filters and query contexts. When the widget is in an inactive dashboard page, the query is paused.

useWidgetQuery({   widgetState,   dashboardState,   pageKey,   cube,   ranges, })
ArgumentTypeDescription
{
   widgetState,
   dashboardState,
   pageKey,
   cube,
   ranges,
}
{
   widgetState: WidgetWithQueryState<MdxSelect | MdxDrillthrough>;
   dashboardState: DashboardState | undefined;
   pageKey?: string;
   cube: Cube;
   ranges?: Partial<{
     [axisId in AxisId]: QueryRange;
  }>;
}
Returns:

Query<MdxString> | undefined

useWidgetQueryResult#

React hook running the widget's Query, impacted by the user/dashboard/page filters and query contexts, and returning its result. When the widget is in an inactive dashboard page or deferred updates are enabled: - The query is paused if it was in real-time mode. - Updates to the query on the client side are not forwarded to the server.

useWidgetQueryResult({   serverKey,   queryId,   widgetState,   dashboardState,   pageKey,   cube,   queryRanges,   isDeferred, })
ArgumentTypeDescription
{
   serverKey,
   queryId,
   widgetState,
   dashboardState,
   pageKey,
   cube,
   queryRanges,
   isDeferred,
}
{
   serverKey?: string;
   queryId?: string;
   widgetState: WidgetWithQueryState<MdxType>;
   dashboardState?: DashboardState;
   pageKey?: string;
   cube: Cube;
   queryRanges?: Partial<{
     [axisId in AxisId]: QueryRange;
  }>;
   isDeferred?: boolean;
}
Returns:

QueryResult<MdxType extends MdxSelect ? CellSet : DrillthroughResult>