Horizon Framework

UI API — Actions

apiClient.ui.actions manages action definitions and bulk action execution. Actions define operations that can be performed on records — both single-record actions and bulk operations across multiple records.

Methods

getAction

Fetch a single action by ID or ActionKey.

// By action ID
const action = await apiClient.ui.actions.getAction({ id: 'action-uid' })

// By ActionKey (resource + name combination)
const action = await apiClient.ui.actions.getAction({
  actionKey: { resource: 'Jobs', name: 'Approve Job' },
})

console.log(action.label)
console.log(action.description)

getActionsList

Fetch a list of available actions for a resource. Results are cached.

const response = await apiClient.ui.actions.getActionsList({
  resourceName: 'Jobs',
})

response.actions.forEach((action) => {
  console.log(action.label, action.id)
})

resolveActions

Resolve which actions are available for a given set of record IDs, taking permissions and state into account. Results are cached.

const actions = await apiClient.ui.actions.resolveActions({
  resourceName: 'Jobs',
  ids: ['job-uid-1', 'job-uid-2'],
})

actions.forEach((action) => {
  console.log(action.label, action.enabled)
})

executeBulkAction (on apiClient.ui)

Execute a bulk action against a set of records. This method is on the parent UiApiClientV1 rather than the actions sub-service.

const result = await apiClient.ui.executeBulkAction({
  actionId: 'action-uid',
  resourceName: 'Jobs',
  ids: ['job-uid-1', 'job-uid-2'],
  // additional action parameters...
})

console.log(result.successCount)
console.log(result.failureCount)

initiateSchemaSync (on apiClient.ui)

Trigger a schema synchronisation. This method is on the parent UiApiClientV1.

await apiClient.ui.initiateSchemaSync({ resourceName: 'Jobs' })

Caching

getActionsList and resolveActions both use in-memory caching to avoid redundant network requests. The cache is keyed on the full request object, so different request parameters will result in separate cache entries.

React Example

import { useApiClient } from '@skedulo/horizon-core'
import { useEffect, useState, useCallback } from 'react'

const ActionBar = ({ resourceName, selectedIds }) => {
  const apiClient = useApiClient()
  const [actions, setActions] = useState([])

  useEffect(() => {
    if (!selectedIds.length) return
    let mounted = true
    apiClient?.ui.actions
      .resolveActions({ resourceName, ids: selectedIds })
      .then((result) => {
        if (mounted) setActions(result)
      })
    return () => {
      mounted = false
    }
  }, [apiClient, resourceName, selectedIds])

  const handleAction = useCallback(
    async (actionId) => {
      await apiClient?.ui.executeBulkAction({
        actionId,
        resourceName,
        ids: selectedIds,
      })
    },
    [apiClient, resourceName, selectedIds],
  )

  return (
    <div>
      {actions
        .filter((a) => a.enabled)
        .map((action) => (
          <button key={action.id} onClick={() => handleAction(action.id)}>
            {action.label}
          </button>
        ))}
    </div>
  )
}