Skip to content

Commit acb4e57

Browse files
icecrasher321Vikhyath Mondreti
andauthored
fix(doc-selector-kb): enable doc selector when kb is selected (#596)
Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@vikhyaths-air.lan>
1 parent c2faf04 commit acb4e57

File tree

1 file changed

+6
-13
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/document-selector

1 file changed

+6
-13
lines changed

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

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

3-
import { useCallback, useEffect, useMemo, useState } from 'react'
3+
import { useCallback, useEffect, useState } from 'react'
44
import { Check, ChevronDown, FileText } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
66
import {
@@ -13,7 +13,6 @@ import {
1313
} from '@/components/ui/command'
1414
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
1515
import type { SubBlockConfig } from '@/blocks/types'
16-
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1716
import { useSubBlockValue } from '../../hooks/use-sub-block-value'
1817

1918
interface DocumentData {
@@ -51,19 +50,16 @@ export function DocumentSelector({
5150
isPreview = false,
5251
previewValue,
5352
}: DocumentSelectorProps) {
54-
const { getValue } = useSubBlockStore()
55-
5653
const [documents, setDocuments] = useState<DocumentData[]>([])
5754
const [error, setError] = useState<string | null>(null)
5855
const [open, setOpen] = useState(false)
5956
const [selectedDocument, setSelectedDocument] = useState<DocumentData | null>(null)
60-
const [initialFetchDone, setInitialFetchDone] = useState(false)
6157

6258
// Use the proper hook to get the current value and setter
6359
const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlock.id)
6460

65-
// Get the knowledge base ID from the same block's knowledgeBaseId subblock - memoize to prevent re-renders
66-
const knowledgeBaseId = useMemo(() => getValue(blockId, 'knowledgeBaseId'), [getValue, blockId])
61+
// Get the knowledge base ID from the same block's knowledgeBaseId subblock
62+
const [knowledgeBaseId] = useSubBlockValue(blockId, 'knowledgeBaseId')
6763

6864
// Use preview value when in preview mode, otherwise use store value
6965
const value = isPreview ? previewValue : storeValue
@@ -73,7 +69,6 @@ export function DocumentSelector({
7369
if (!knowledgeBaseId) {
7470
setDocuments([])
7571
setError('No knowledge base selected')
76-
setInitialFetchDone(true)
7772
return
7873
}
7974

@@ -94,7 +89,6 @@ export function DocumentSelector({
9489

9590
const fetchedDocuments = result.data || []
9691
setDocuments(fetchedDocuments)
97-
setInitialFetchDone(true)
9892
} catch (err) {
9993
if ((err as Error).name === 'AbortError') return
10094
setError((err as Error).message)
@@ -138,16 +132,15 @@ export function DocumentSelector({
138132
useEffect(() => {
139133
setDocuments([])
140134
setSelectedDocument(null)
141-
setInitialFetchDone(false)
142135
setError(null)
143136
}, [knowledgeBaseId])
144137

145-
// Fetch documents when knowledge base is available and we haven't fetched yet
138+
// Fetch documents when knowledge base is available
146139
useEffect(() => {
147-
if (knowledgeBaseId && !initialFetchDone && !isPreview) {
140+
if (knowledgeBaseId && !isPreview) {
148141
fetchDocuments()
149142
}
150-
}, [knowledgeBaseId, initialFetchDone, isPreview, fetchDocuments])
143+
}, [knowledgeBaseId, isPreview, fetchDocuments])
151144

152145
const formatDocumentName = (document: DocumentData) => {
153146
return document.filename

0 commit comments

Comments
 (0)