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
39 changes: 24 additions & 15 deletions apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import type {
SortConfig,
} from '@/app/workspace/[workspaceId]/components'
import { FloatingOverflowText, Resource } from '@/app/workspace/[workspaceId]/components'
import { DocumentTagsModal } from '@/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components'
import {
ActionBar,
AddConnectorModal,
Expand Down Expand Up @@ -342,6 +343,8 @@ export function KnowledgeBase({
const [contextMenuDocument, setContextMenuDocument] = useState<DocumentData | null>(null)
const [showRenameModal, setShowRenameModal] = useState(false)
const [documentToRename, setDocumentToRename] = useState<DocumentData | null>(null)
const [showDocumentTagsModal, setShowDocumentTagsModal] = useState(false)
const [documentForTagsId, setDocumentForTagsId] = useState<string | null>(null)
const showAddConnectorModal = addConnectorType != null
const updateAddConnectorParam = useCallback(
(value: string | null) => {
Expand Down Expand Up @@ -531,6 +534,14 @@ export function KnowledgeBase({
setShowRenameModal(true)
}

/**
* Opens the document tags modal
*/
const handleViewDocumentTags = (doc: DocumentData) => {
setDocumentForTagsId(doc.id)
setShowDocumentTagsModal(true)
}

/**
* Saves the renamed document
*/
Expand Down Expand Up @@ -1345,6 +1356,17 @@ export function KnowledgeBase({
/>
)}

{documentForTagsId && (
<DocumentTagsModal
open={showDocumentTagsModal}
onOpenChange={setShowDocumentTagsModal}
knowledgeBaseId={id}
documentId={documentForTagsId}
documentData={documents.find((doc) => doc.id === documentForTagsId) ?? null}
onDocumentUpdate={(updates) => updateDocument(documentForTagsId, updates)}
/>
Comment thread
waleedlatif1 marked this conversation as resolved.
)}

<ChipModal
open={showConnectorsModal}
onOpenChange={setShowConnectorsModal}
Expand All @@ -1371,11 +1393,6 @@ export function KnowledgeBase({
onClose={handleContextMenuClose}
hasDocument={contextMenuDocument !== null}
isDocumentEnabled={contextMenuDocument?.enabled ?? true}
hasTags={
contextMenuDocument
? getDocumentTags(contextMenuDocument, tagDefinitions).length > 0
: false
}
selectedCount={selectedDocuments.size}
enabledCount={enabledCount}
disabledCount={disabledCount}
Expand Down Expand Up @@ -1413,16 +1430,8 @@ export function KnowledgeBase({
: undefined
}
onViewTags={
contextMenuDocument && selectedDocuments.size === 1
? () => {
const urlParams = new URLSearchParams({
kbName: knowledgeBaseName,
docName: contextMenuDocument.filename || 'Document',
})
router.push(
`/workspace/${workspaceId}/knowledge/${id}/${contextMenuDocument.id}?${urlParams.toString()}`
)
}
contextMenuDocument && selectedDocuments.size === 1 && userPermissions.canEdit
? () => handleViewDocumentTags(contextMenuDocument)
: undefined
}
Comment thread
waleedlatif1 marked this conversation as resolved.
onDelete={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface DocumentContextMenuProps {
onAddDocument?: () => void
isDocumentEnabled?: boolean
hasDocument: boolean
hasTags?: boolean
disableRename?: boolean
disableToggleEnabled?: boolean
disableDelete?: boolean
Expand Down Expand Up @@ -50,7 +49,6 @@ export function DocumentContextMenu({
onAddDocument,
isDocumentEnabled = true,
hasDocument,
hasTags = false,
disableRename = false,
disableToggleEnabled = false,
disableDelete = false,
Expand All @@ -70,7 +68,7 @@ export function DocumentContextMenu({
}

const hasNavigationSection = !isMultiSelect && (!!onOpenInNewTab || !!onOpenSource)
const hasEditSection = !isMultiSelect && (!!onRename || (hasTags && !!onViewTags))
const hasEditSection = !isMultiSelect && (!!onRename || !!onViewTags)
const hasStateSection = !!onToggleEnabled
const hasDestructiveSection = !!onDelete

Expand Down Expand Up @@ -121,10 +119,10 @@ export function DocumentContextMenu({
Rename
</DropdownMenuItem>
)}
{!isMultiSelect && hasTags && onViewTags && (
{!isMultiSelect && onViewTags && (
<DropdownMenuItem onSelect={onViewTags}>
<TagIcon />
View tags
Tags
</DropdownMenuItem>
)}
{hasEditSection && (hasStateSection || hasDestructiveSection) && (
Expand Down
Loading