Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { startTransition, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { createLogger } from '@sim/logger'
import { useQueryClient } from '@tanstack/react-query'
import { ChevronDown, ChevronUp, FileText, Pencil, Tag } from 'lucide-react'
import { useParams, useRouter, useSearchParams } from 'next/navigation'
import {
Expand Down Expand Up @@ -41,7 +40,6 @@ import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/provide
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
import { useDocument, useDocumentChunks, useKnowledgeBase } from '@/hooks/kb/use-knowledge'
import {
knowledgeKeys,
useBulkChunkOperation,
useDeleteDocument,
useDocumentChunkSearchQuery,
Expand Down Expand Up @@ -137,7 +135,6 @@ export function Document({
knowledgeBaseName,
documentName,
}: DocumentProps) {
const queryClient = useQueryClient()
const { workspaceId } = useParams()
const router = useRouter()
const searchParams = useSearchParams()
Expand Down Expand Up @@ -704,9 +701,7 @@ export function Document({
},
{
onSuccess: (result) => {
if (operation === 'delete' || result.errorCount > 0) {
refreshChunks()
} else {
if (operation !== 'delete' && result.errorCount === 0) {
chunks.forEach((chunk) => {
updateChunk(chunk.id, { enabled: operation === 'enable' })
})
Expand Down Expand Up @@ -789,12 +784,6 @@ export function Document({
setContextMenuChunk(null)
}, [closeContextMenu])

const handleDocumentTagsUpdate = useCallback(() => {
queryClient.invalidateQueries({
queryKey: knowledgeKeys.document(knowledgeBaseId, documentId),
})
}, [knowledgeBaseId, documentId, queryClient])

const prevDocumentIdRef = useRef<string>(documentId)
const isNavigatingToNewDoc = prevDocumentIdRef.current !== documentId

Expand Down Expand Up @@ -1121,7 +1110,6 @@ export function Document({
knowledgeBaseId={knowledgeBaseId}
documentId={documentId}
documentData={documentData}
onDocumentUpdate={handleDocumentTagsUpdate}
/>

<DeleteChunkModal
Expand Down
23 changes: 12 additions & 11 deletions apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ export function KnowledgeBase({
refresh: refreshKnowledgeBase,
} = useKnowledgeBase(id)

const { data: connectors = [], isLoading: isLoadingConnectors } = useConnectorList(id)
const hasSyncingConnectors = connectors.some((c) => c.status === 'syncing')
const hasSyncingConnectorsRef = useRef(hasSyncingConnectors)
useEffect(() => {
hasSyncingConnectorsRef.current = hasSyncingConnectors
}, [hasSyncingConnectors])

const {
documents,
pagination,
Expand All @@ -292,24 +299,24 @@ export function KnowledgeBase({
const hasPending = data?.documents?.some(
(doc) => doc.processingStatus === 'pending' || doc.processingStatus === 'processing'
)
return hasPending ? 3000 : false
if (hasPending) return 3000
if (hasSyncingConnectorsRef.current) return 5000
return false
},
enabledFilter,
tagFilters: activeTagFilters.length > 0 ? activeTagFilters : undefined,
})

const { tagDefinitions } = useKnowledgeBaseTagDefinitions(id)

const { data: connectors = [], isLoading: isLoadingConnectors } = useConnectorList(id)
const hasSyncingConnectors = connectors.some((c) => c.status === 'syncing')

const prevHadSyncingRef = useRef(false)
useEffect(() => {
if (prevHadSyncingRef.current && !hasSyncingConnectors) {
refreshKnowledgeBase()
refreshDocuments()
}
prevHadSyncingRef.current = hasSyncingConnectors
}, [hasSyncingConnectors, refreshKnowledgeBase])
}, [hasSyncingConnectors, refreshKnowledgeBase, refreshDocuments])

const router = useRouter()

Expand Down Expand Up @@ -406,7 +413,6 @@ export function KnowledgeBase({
},
{
onSuccess: () => {
refreshDocuments()
logger.info(`Document retry initiated successfully for: ${docId}`)
},
onError: (err) => {
Expand Down Expand Up @@ -480,7 +486,6 @@ export function KnowledgeBase({
{ knowledgeBaseId: id, documentId: documentToDelete },
{
onSuccess: () => {
refreshDocuments()
setSelectedDocuments((prev) => {
const newSet = new Set(prev)
newSet.delete(documentToDelete)
Expand Down Expand Up @@ -575,7 +580,6 @@ export function KnowledgeBase({
logger.info(`Successfully enabled ${result.successCount} documents`)
setSelectedDocuments(new Set())
setIsSelectAllMode(false)
refreshDocuments()
},
}
)
Expand Down Expand Up @@ -623,7 +627,6 @@ export function KnowledgeBase({
logger.info(`Successfully disabled ${result.successCount} documents`)
setSelectedDocuments(new Set())
setIsSelectAllMode(false)
refreshDocuments()
},
}
)
Expand Down Expand Up @@ -671,7 +674,6 @@ export function KnowledgeBase({
{
onSuccess: (result) => {
logger.info(`Successfully deleted ${result.successCount} documents`)
refreshDocuments()
setSelectedDocuments(new Set())
setIsSelectAllMode(false)
},
Expand All @@ -696,7 +698,6 @@ export function KnowledgeBase({
{
onSuccess: (result) => {
logger.info(`Successfully deleted ${result.successCount} documents`)
refreshDocuments()
setSelectedDocuments(new Set())
},
onSettled: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ interface BaseTagsModalProps {
}

export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsModalProps) {
const { tagDefinitions: kbTagDefinitions, fetchTagDefinitions: refreshTagDefinitions } =
useKnowledgeBaseTagDefinitions(knowledgeBaseId)
const { tagDefinitions: kbTagDefinitions } = useKnowledgeBaseTagDefinitions(knowledgeBaseId)

const createTagMutation = useCreateTagDefinition()
const deleteTagMutation = useDeleteTagDefinition()
Expand Down Expand Up @@ -219,7 +218,7 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
fieldType: createTagForm.fieldType,
})

await Promise.all([refreshTagDefinitions(), fetchTagUsage()])
await fetchTagUsage()

setCreateTagForm({
displayName: '',
Expand All @@ -240,7 +239,7 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
tagDefinitionId: selectedTag.id,
})

await Promise.all([refreshTagDefinitions(), fetchTagUsage()])
await fetchTagUsage()

setDeleteTagDialogOpen(false)
setSelectedTag(null)
Expand Down
20 changes: 4 additions & 16 deletions apps/sim/hooks/queries/kb/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function useCreateConnector() {
mutationFn: createConnector,
onSuccess: (_, { knowledgeBaseId }) => {
queryClient.invalidateQueries({
queryKey: connectorKeys.list(knowledgeBaseId),
queryKey: knowledgeKeys.detail(knowledgeBaseId),
})
},
})
Expand Down Expand Up @@ -198,12 +198,9 @@ export function useUpdateConnector() {

return useMutation({
mutationFn: updateConnector,
onSuccess: (_, { knowledgeBaseId, connectorId }) => {
queryClient.invalidateQueries({
queryKey: connectorKeys.list(knowledgeBaseId),
})
onSuccess: (_, { knowledgeBaseId }) => {
queryClient.invalidateQueries({
queryKey: connectorKeys.detail(knowledgeBaseId, connectorId),
queryKey: connectorKeys.all(knowledgeBaseId),
})
},
})
Expand Down Expand Up @@ -239,9 +236,6 @@ export function useDeleteConnector() {
return useMutation({
mutationFn: deleteConnector,
onSuccess: (_, { knowledgeBaseId }) => {
queryClient.invalidateQueries({
queryKey: connectorKeys.list(knowledgeBaseId),
})
queryClient.invalidateQueries({
queryKey: knowledgeKeys.detail(knowledgeBaseId),
})
Expand Down Expand Up @@ -270,13 +264,7 @@ export function useTriggerSync() {

return useMutation({
mutationFn: triggerSync,
onSuccess: (_, { knowledgeBaseId, connectorId }) => {
queryClient.invalidateQueries({
queryKey: connectorKeys.list(knowledgeBaseId),
})
queryClient.invalidateQueries({
queryKey: connectorKeys.detail(knowledgeBaseId, connectorId),
})
onSuccess: (_, { knowledgeBaseId }) => {
queryClient.invalidateQueries({
queryKey: knowledgeKeys.detail(knowledgeBaseId),
})
Expand Down
Loading