diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index 2147bb95e8..b4876dcf45 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -4194,11 +4194,6 @@
"count": 1
}
},
- "web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-value-method.tsx": {
- "no-restricted-imports": {
- "count": 1
- }
- },
"web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/metadata-filter/index.tsx": {
"no-restricted-imports": {
"count": 1
diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/__tests__/integration.spec.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/__tests__/integration.spec.tsx
index b9f2b17bb2..81943ff86c 100644
--- a/web/app/components/workflow/nodes/knowledge-retrieval/__tests__/integration.spec.tsx
+++ b/web/app/components/workflow/nodes/knowledge-retrieval/__tests__/integration.spec.tsx
@@ -19,6 +19,7 @@ import { BlockEnum, VarType } from '../../../types'
import AddDataset from '../components/add-dataset'
import DatasetItem from '../components/dataset-item'
import DatasetList from '../components/dataset-list'
+import AddCondition from '../components/metadata/add-condition'
import ConditionCommonVariableSelector from '../components/metadata/condition-list/condition-common-variable-selector'
import ConditionDate from '../components/metadata/condition-list/condition-date'
import ConditionItem from '../components/metadata/condition-list/condition-item'
@@ -462,6 +463,29 @@ describe('knowledge-retrieval path', () => {
expect(screen.getByText('metadata-panel')).toBeInTheDocument()
})
+ it('should call handleAddCondition with the correct metadata item when clicking any part of the row', async () => {
+ const user = userEvent.setup()
+ const handleAddCondition = vi.fn()
+ const permissionMetadata = createMetadata({ id: 'meta-perm', name: 'permission', type: MetadataFilteringVariableType.string })
+ const topicMetadata = createMetadata({ id: 'meta-topic', name: 'topic', type: MetadataFilteringVariableType.string })
+
+ render(
+ ,
+ )
+
+ await user.click(screen.getByRole('button', { name: /workflow.nodes.knowledgeRetrieval.metadata.panel.add/i }))
+ await user.click(screen.getAllByText('string', { selector: 'div.shrink-0' })[0]!)
+
+ expect(handleAddCondition).toHaveBeenCalledTimes(1)
+ expect(handleAddCondition).toHaveBeenCalledWith(expect.objectContaining({
+ id: 'meta-perm',
+ name: 'permission',
+ }))
+ })
+
it('should render automatic and manual metadata filter states', async () => {
const user = userEvent.setup()
const baseProps: MetadataShape = {
@@ -591,6 +615,24 @@ describe('knowledge-retrieval path', () => {
expect(onUpdateCondition).toHaveBeenCalledWith('condition-1', expect.objectContaining({ value: 'updated-agent' }))
expect(onRemoveCondition).toHaveBeenCalledWith('condition-1')
})
+
+ it('should resolve built-in metadata fields by name because their ids are shared', () => {
+ render(
+ ,
+ )
+
+ expect(screen.getByText('uploader')).toBeInTheDocument()
+ expect(screen.queryByText('document_name')).not.toBeInTheDocument()
+ })
})
describe('Node rendering', () => {
diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/add-condition.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/add-condition.tsx
index fe332aa871..2de3348ca3 100644
--- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/add-condition.tsx
+++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/add-condition.tsx
@@ -65,6 +65,7 @@ const AddCondition = ({
handleAddConditionWrapped(metadata)}
>
@@ -72,7 +73,6 @@ const AddCondition = ({
handleAddConditionWrapped(metadata)}
>
{metadata.name}
diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx
index 46f03d0c77..56936d9251 100644
--- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx
+++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx
@@ -62,13 +62,16 @@ const ConditionItem = ({
}, [onRemoveCondition, condition.id])
const currentMetadata = useMemo(() => {
- // Try to match by metadata_id first (reliable reference)
if (condition.metadata_id) {
- const found = metadataList.find(metadata => metadata.id === condition.metadata_id)
- if (found)
- return found
+ const foundByIdAndName = metadataList.find(metadata => metadata.id === condition.metadata_id && metadata.name === condition.name)
+ if (foundByIdAndName)
+ return foundByIdAndName
+
+ const foundById = metadataList.filter(metadata => metadata.id === condition.metadata_id)
+ if (foundById.length === 1)
+ return foundById[0]
}
- // Fallback to name matching for backward compatibility with old conditions
+
return metadataList.find(metadata => metadata.name === condition.name)
}, [metadataList, condition.metadata_id, condition.name])
diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-value-method.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-value-method.tsx
index 12d7c9cc69..d93af76fd7 100644
--- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-value-method.tsx
+++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-value-method.tsx
@@ -1,13 +1,13 @@
import { Button } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from '@langgenius/dify-ui/popover'
import { RiArrowDownSLine } from '@remixicon/react'
import { capitalize } from 'es-toolkit/string'
import { useState } from 'react'
-import {
- PortalToFollowElem,
- PortalToFollowElemContent,
- PortalToFollowElemTrigger,
-} from '@/app/components/base/portal-to-follow-elem'
export type ConditionValueMethodProps = {
valueMethod?: string
@@ -24,23 +24,27 @@ const ConditionValueMethod = ({
const [open, setOpen] = useState(false)
return (
-
- setOpen(v => !v)}>
-
-
-
+
+ {capitalize(valueMethod)}
+
+
+ )}
+ />
+
{
options.map(option => (
@@ -63,8 +67,8 @@ const ConditionValueMethod = ({
))
}
-
-
+
+
)
}