Skip to content

Commit 7c29341

Browse files
committed
selectors fixes
1 parent 7164580 commit 7c29341

File tree

3 files changed

+100
-14
lines changed

3 files changed

+100
-14
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/document-selector/document-selector.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import { useCallback, useMemo } from 'react'
44
import { Tooltip } from '@/components/emcn'
5+
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
56
import { SelectorCombobox } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox'
67
import { useDependsOnGate } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-depends-on-gate'
7-
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
88
import { resolvePreviewContextValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/utils'
9+
import { getBlock } from '@/blocks/registry'
910
import type { SubBlockConfig } from '@/blocks/types'
1011
import type { SelectorContext } from '@/hooks/selectors/types'
12+
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
13+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
14+
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1115

1216
interface DocumentSelectorProps {
1317
blockId: string
@@ -28,15 +32,41 @@ export function DocumentSelector({
2832
previewValue,
2933
previewContextValues,
3034
}: DocumentSelectorProps) {
35+
const { activeWorkflowId } = useWorkflowRegistry()
36+
3137
const { finalDisabled } = useDependsOnGate(blockId, subBlock, {
3238
disabled,
3339
isPreview,
3440
previewContextValues,
3541
})
36-
const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
37-
const knowledgeBaseIdValue = previewContextValues
38-
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
39-
: knowledgeBaseIdFromStore
42+
43+
const blockState = useWorkflowStore((state) => state.blocks[blockId])
44+
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
45+
const canonicalIndex = useMemo(
46+
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
47+
[blockConfig?.subBlocks]
48+
)
49+
const canonicalModeOverrides = blockState?.data?.canonicalModes
50+
51+
const blockValues = useSubBlockStore((state) => {
52+
if (!activeWorkflowId) return {}
53+
const workflowValues = state.workflowValues[activeWorkflowId] || {}
54+
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
55+
})
56+
57+
const knowledgeBaseIdValue = useMemo(
58+
() =>
59+
previewContextValues
60+
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
61+
: resolveDependencyValue(
62+
'knowledgeBaseId',
63+
blockValues,
64+
canonicalIndex,
65+
canonicalModeOverrides
66+
),
67+
[previewContextValues, blockValues, canonicalIndex, canonicalModeOverrides]
68+
)
69+
4070
const normalizedKnowledgeBaseId =
4171
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
4272
? knowledgeBaseIdValue

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/document-tag-entry/document-tag-entry.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ import {
1313
} from '@/components/emcn'
1414
import { cn } from '@/lib/core/utils/cn'
1515
import { FIELD_TYPE_LABELS, getPlaceholderForFieldType } from '@/lib/knowledge/constants'
16+
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
1617
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
1718
import { TagDropdown } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tag-dropdown/tag-dropdown'
1819
import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-input'
1920
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
2021
import { resolvePreviewContextValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/utils'
2122
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
23+
import { getBlock } from '@/blocks/registry'
2224
import type { SubBlockConfig } from '@/blocks/types'
2325
import { useKnowledgeBaseTagDefinitions } from '@/hooks/kb/use-knowledge-base-tag-definitions'
2426
import { useTagSelection } from '@/hooks/kb/use-tag-selection'
27+
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
28+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
29+
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
2530

2631
interface DocumentTag {
2732
id: string
@@ -60,11 +65,26 @@ export function DocumentTagEntry({
6065
previewValue,
6166
previewContextValues,
6267
}: DocumentTagEntryProps) {
68+
const { activeWorkflowId } = useWorkflowRegistry()
6369
const [storeValue, setStoreValue] = useSubBlockValue<string>(blockId, subBlock.id)
6470
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
6571
const valueInputRefs = useRef<Record<string, HTMLInputElement>>({})
6672
const overlayRefs = useRef<Record<string, HTMLDivElement>>({})
6773

74+
const blockState = useWorkflowStore((state) => state.blocks[blockId])
75+
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
76+
const canonicalIndex = useMemo(
77+
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
78+
[blockConfig?.subBlocks]
79+
)
80+
const canonicalModeOverrides = blockState?.data?.canonicalModes
81+
82+
const blockValues = useSubBlockStore((state) => {
83+
if (!activeWorkflowId) return {}
84+
const workflowValues = state.workflowValues[activeWorkflowId] || {}
85+
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
86+
})
87+
6888
const inputController = useSubBlockInput({
6989
blockId,
7090
subBlockId: subBlock.id,
@@ -77,10 +97,18 @@ export function DocumentTagEntry({
7797
disabled,
7898
})
7999

80-
const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
81-
const knowledgeBaseIdValue = previewContextValues
82-
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
83-
: knowledgeBaseIdFromStore
100+
const knowledgeBaseIdValue = useMemo(
101+
() =>
102+
previewContextValues
103+
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
104+
: resolveDependencyValue(
105+
'knowledgeBaseId',
106+
blockValues,
107+
canonicalIndex,
108+
canonicalModeOverrides
109+
),
110+
[previewContextValues, blockValues, canonicalIndex, canonicalModeOverrides]
111+
)
84112
const knowledgeBaseId =
85113
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
86114
? knowledgeBaseIdValue

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/knowledge-tag-filters/knowledge-tag-filters.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useRef } from 'react'
3+
import { useMemo, useRef } from 'react'
44
import { Plus } from 'lucide-react'
55
import {
66
Badge,
@@ -14,14 +14,19 @@ import {
1414
import { cn } from '@/lib/core/utils/cn'
1515
import { FIELD_TYPE_LABELS, getPlaceholderForFieldType } from '@/lib/knowledge/constants'
1616
import { type FilterFieldType, getOperatorsForFieldType } from '@/lib/knowledge/filters/types'
17+
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
1718
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
1819
import { TagDropdown } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tag-dropdown/tag-dropdown'
1920
import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-input'
2021
import { resolvePreviewContextValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/utils'
2122
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
23+
import { getBlock } from '@/blocks/registry'
2224
import type { SubBlockConfig } from '@/blocks/types'
2325
import { useKnowledgeBaseTagDefinitions } from '@/hooks/kb/use-knowledge-base-tag-definitions'
2426
import { useTagSelection } from '@/hooks/kb/use-tag-selection'
27+
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
28+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
29+
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
2530
import { useSubBlockValue } from '../../hooks/use-sub-block-value'
2631

2732
interface TagFilter {
@@ -64,15 +69,38 @@ export function KnowledgeTagFilters({
6469
previewValue,
6570
previewContextValues,
6671
}: KnowledgeTagFiltersProps) {
72+
const { activeWorkflowId } = useWorkflowRegistry()
6773
const [storeValue, setStoreValue] = useSubBlockValue<string | null>(blockId, subBlock.id)
6874
const emitTagSelection = useTagSelection(blockId, subBlock.id)
6975
const valueInputRefs = useRef<Record<string, HTMLInputElement>>({})
7076
const overlayRefs = useRef<Record<string, HTMLDivElement>>({})
7177

72-
const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
73-
const knowledgeBaseIdValue = previewContextValues
74-
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
75-
: knowledgeBaseIdFromStore
78+
const blockState = useWorkflowStore((state) => state.blocks[blockId])
79+
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
80+
const canonicalIndex = useMemo(
81+
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
82+
[blockConfig?.subBlocks]
83+
)
84+
const canonicalModeOverrides = blockState?.data?.canonicalModes
85+
86+
const blockValues = useSubBlockStore((state) => {
87+
if (!activeWorkflowId) return {}
88+
const workflowValues = state.workflowValues[activeWorkflowId] || {}
89+
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
90+
})
91+
92+
const knowledgeBaseIdValue = useMemo(
93+
() =>
94+
previewContextValues
95+
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
96+
: resolveDependencyValue(
97+
'knowledgeBaseId',
98+
blockValues,
99+
canonicalIndex,
100+
canonicalModeOverrides
101+
),
102+
[previewContextValues, blockValues, canonicalIndex, canonicalModeOverrides]
103+
)
76104
const knowledgeBaseId =
77105
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
78106
? knowledgeBaseIdValue

0 commit comments

Comments
 (0)