Skip to content

Commit 099f525

Browse files
authored
improvement(knowledge): open document tags from row context menu (#5510)
* improvement(knowledge): open document tags from row context menu The document row context menu had a Tags entry that only navigated to the document detail page, requiring another click through the breadcrumb dropdown to actually edit tags. It now opens the tag editor directly, and shows even when the document has no tags yet so a first tag can be added. * fix(knowledge): gate document tags menu item on edit permission Matches the existing disableRename/disableDelete/disableToggleEnabled pattern; the document detail breadcrumb already hides its Tags entry for non-editors the same way. * fix(knowledge): derive tags modal document data from live list cache The modal was fed a frozen document snapshot taken at right-click time. After a save, the mutation only invalidates the single-document and KB-detail queries (not the documents list query), so the modal's own sync effect rebuilt tags from the stale snapshot and could revert or drop the just-saved value. Track only the document id and look it up from the same documents array updateDocument() patches, so the modal always sees current data.
1 parent cb6f99d commit 099f525

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import type {
4949
SortConfig,
5050
} from '@/app/workspace/[workspaceId]/components'
5151
import { FloatingOverflowText, Resource } from '@/app/workspace/[workspaceId]/components'
52+
import { DocumentTagsModal } from '@/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components'
5253
import {
5354
ActionBar,
5455
AddConnectorModal,
@@ -342,6 +343,8 @@ export function KnowledgeBase({
342343
const [contextMenuDocument, setContextMenuDocument] = useState<DocumentData | null>(null)
343344
const [showRenameModal, setShowRenameModal] = useState(false)
344345
const [documentToRename, setDocumentToRename] = useState<DocumentData | null>(null)
346+
const [showDocumentTagsModal, setShowDocumentTagsModal] = useState(false)
347+
const [documentForTagsId, setDocumentForTagsId] = useState<string | null>(null)
345348
const showAddConnectorModal = addConnectorType != null
346349
const updateAddConnectorParam = useCallback(
347350
(value: string | null) => {
@@ -531,6 +534,14 @@ export function KnowledgeBase({
531534
setShowRenameModal(true)
532535
}
533536

537+
/**
538+
* Opens the document tags modal
539+
*/
540+
const handleViewDocumentTags = (doc: DocumentData) => {
541+
setDocumentForTagsId(doc.id)
542+
setShowDocumentTagsModal(true)
543+
}
544+
534545
/**
535546
* Saves the renamed document
536547
*/
@@ -1345,6 +1356,17 @@ export function KnowledgeBase({
13451356
/>
13461357
)}
13471358

1359+
{documentForTagsId && (
1360+
<DocumentTagsModal
1361+
open={showDocumentTagsModal}
1362+
onOpenChange={setShowDocumentTagsModal}
1363+
knowledgeBaseId={id}
1364+
documentId={documentForTagsId}
1365+
documentData={documents.find((doc) => doc.id === documentForTagsId) ?? null}
1366+
onDocumentUpdate={(updates) => updateDocument(documentForTagsId, updates)}
1367+
/>
1368+
)}
1369+
13481370
<ChipModal
13491371
open={showConnectorsModal}
13501372
onOpenChange={setShowConnectorsModal}
@@ -1371,11 +1393,6 @@ export function KnowledgeBase({
13711393
onClose={handleContextMenuClose}
13721394
hasDocument={contextMenuDocument !== null}
13731395
isDocumentEnabled={contextMenuDocument?.enabled ?? true}
1374-
hasTags={
1375-
contextMenuDocument
1376-
? getDocumentTags(contextMenuDocument, tagDefinitions).length > 0
1377-
: false
1378-
}
13791396
selectedCount={selectedDocuments.size}
13801397
enabledCount={enabledCount}
13811398
disabledCount={disabledCount}
@@ -1413,16 +1430,8 @@ export function KnowledgeBase({
14131430
: undefined
14141431
}
14151432
onViewTags={
1416-
contextMenuDocument && selectedDocuments.size === 1
1417-
? () => {
1418-
const urlParams = new URLSearchParams({
1419-
kbName: knowledgeBaseName,
1420-
docName: contextMenuDocument.filename || 'Document',
1421-
})
1422-
router.push(
1423-
`/workspace/${workspaceId}/knowledge/${id}/${contextMenuDocument.id}?${urlParams.toString()}`
1424-
)
1425-
}
1433+
contextMenuDocument && selectedDocuments.size === 1 && userPermissions.canEdit
1434+
? () => handleViewDocumentTags(contextMenuDocument)
14261435
: undefined
14271436
}
14281437
onDelete={

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/document-context-menu/document-context-menu.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ interface DocumentContextMenuProps {
2222
onAddDocument?: () => void
2323
isDocumentEnabled?: boolean
2424
hasDocument: boolean
25-
hasTags?: boolean
2625
disableRename?: boolean
2726
disableToggleEnabled?: boolean
2827
disableDelete?: boolean
@@ -50,7 +49,6 @@ export function DocumentContextMenu({
5049
onAddDocument,
5150
isDocumentEnabled = true,
5251
hasDocument,
53-
hasTags = false,
5452
disableRename = false,
5553
disableToggleEnabled = false,
5654
disableDelete = false,
@@ -70,7 +68,7 @@ export function DocumentContextMenu({
7068
}
7169

7270
const hasNavigationSection = !isMultiSelect && (!!onOpenInNewTab || !!onOpenSource)
73-
const hasEditSection = !isMultiSelect && (!!onRename || (hasTags && !!onViewTags))
71+
const hasEditSection = !isMultiSelect && (!!onRename || !!onViewTags)
7472
const hasStateSection = !!onToggleEnabled
7573
const hasDestructiveSection = !!onDelete
7674

@@ -121,10 +119,10 @@ export function DocumentContextMenu({
121119
Rename
122120
</DropdownMenuItem>
123121
)}
124-
{!isMultiSelect && hasTags && onViewTags && (
122+
{!isMultiSelect && onViewTags && (
125123
<DropdownMenuItem onSelect={onViewTags}>
126124
<TagIcon />
127-
View tags
125+
Tags
128126
</DropdownMenuItem>
129127
)}
130128
{hasEditSection && (hasStateSection || hasDestructiveSection) && (

0 commit comments

Comments
 (0)