( workflowIds: ReadonlyArray<string | undefined> )
| 90 | * register their own observer. |
| 91 | */ |
| 92 | export function useWorkflowStates( |
| 93 | workflowIds: ReadonlyArray<string | undefined> |
| 94 | ): Map<string, WorkflowState | null> { |
| 95 | const uniqueIds = Array.from(new Set(workflowIds.filter((id): id is string => Boolean(id)))) |
| 96 | const results = useQueries({ |
| 97 | queries: uniqueIds.map((id) => ({ |
| 98 | queryKey: workflowKeys.state(id), |
| 99 | queryFn: ({ signal }: { signal?: AbortSignal }) => fetchWorkflowEnvelope(id, signal), |
| 100 | select: mapWorkflowState, |
| 101 | staleTime: 30 * 1000, |
| 102 | })), |
| 103 | }) |
| 104 | const map = new Map<string, WorkflowState | null>() |
| 105 | uniqueIds.forEach((id, i) => { |
| 106 | map.set(id, (results[i].data as WorkflowState | null | undefined) ?? null) |
| 107 | }) |
| 108 | return map |
| 109 | } |
| 110 | |
| 111 | export function useWorkflows(workspaceId?: string, options?: { scope?: WorkflowQueryScope }) { |
| 112 | const { scope = 'active' } = options || {} |
no test coverage detected