MCPcopy Index your code
hub / github.com/simstudioai/sim / useReactiveConditions

Function useReactiveConditions

apps/sim/hooks/use-reactive-conditions.ts:14–63  ·  view source on GitHub ↗
(
  subBlocks: SubBlockConfig[],
  blockId: string,
  activeWorkflowId: string | null,
  canonicalModeOverrides?: CanonicalModeOverrides
)

Source from the content-addressed store, hash-verified

12 * Returns a Set of subblock IDs that should be hidden.
13 */
14export function useReactiveConditions(
15 subBlocks: SubBlockConfig[],
16 blockId: string,
17 activeWorkflowId: string | null,
18 canonicalModeOverrides?: CanonicalModeOverrides
19): Set<string> {
20 const reactiveSubBlock = useMemo(() => subBlocks.find((sb) => sb.reactiveCondition), [subBlocks])
21 const reactiveCond = reactiveSubBlock?.reactiveCondition
22
23 const canonicalIndex = useMemo(() => buildCanonicalIndex(subBlocks), [subBlocks])
24
25 // Resolve watchFields through canonical index to get the active credential value
26 const watchedCredentialId = useSubBlockStore(
27 useCallback(
28 (state) => {
29 if (!reactiveCond || !activeWorkflowId) return ''
30 const blockValues =
31 state.workflowValues[activeWorkflowId]?.[blockId] ?? EMPTY_BLOCK_SUBBLOCK_VALUES
32 for (const field of reactiveCond.watchFields) {
33 const val = resolveDependencyValue(
34 field,
35 blockValues,
36 canonicalIndex,
37 canonicalModeOverrides
38 )
39 if (val && typeof val === 'string') return val
40 }
41 return ''
42 },
43 [reactiveCond, activeWorkflowId, blockId, canonicalIndex, canonicalModeOverrides]
44 )
45 )
46
47 // Always call useWorkspaceCredential (stable hook count), disable when not needed
48 const { data: credential } = useWorkspaceCredential(
49 watchedCredentialId || undefined,
50 Boolean(reactiveCond && watchedCredentialId)
51 )
52
53 return useMemo(() => {
54 const hidden = new Set<string>()
55 if (!reactiveSubBlock || !reactiveCond) return hidden
56
57 const conditionMet = credential?.type === reactiveCond.requiredType
58 if (!conditionMet) {
59 hidden.add(reactiveSubBlock.id)
60 }
61 return hidden
62 }, [reactiveSubBlock, reactiveCond, credential?.type])
63}

Callers 2

useEditorSubblockLayoutFunction · 0.90
workflow-block.tsxFile · 0.90

Calls 4

buildCanonicalIndexFunction · 0.90
resolveDependencyValueFunction · 0.90
useWorkspaceCredentialFunction · 0.90
addMethod · 0.45

Tested by

no test coverage detected