mirror of https://github.com/langgenius/dify.git
fix: fix metadata filter not survive a rename (#30174)
This commit is contained in:
parent
7e06225ce2
commit
b892906d71
|
|
@ -176,7 +176,7 @@ const DatasetConfig: FC = () => {
|
||||||
}))
|
}))
|
||||||
}, [setDatasetConfigs, datasetConfigsRef])
|
}, [setDatasetConfigs, datasetConfigsRef])
|
||||||
|
|
||||||
const handleAddCondition = useCallback<HandleAddCondition>(({ name, type }) => {
|
const handleAddCondition = useCallback<HandleAddCondition>(({ id, name, type }) => {
|
||||||
let operator: ComparisonOperator = ComparisonOperator.is
|
let operator: ComparisonOperator = ComparisonOperator.is
|
||||||
|
|
||||||
if (type === MetadataFilteringVariableType.number)
|
if (type === MetadataFilteringVariableType.number)
|
||||||
|
|
@ -184,6 +184,7 @@ const DatasetConfig: FC = () => {
|
||||||
|
|
||||||
const newCondition = {
|
const newCondition = {
|
||||||
id: uuid4(),
|
id: uuid4(),
|
||||||
|
metadata_id: id, // Save metadata.id for reliable reference
|
||||||
name,
|
name,
|
||||||
comparison_operator: operator,
|
comparison_operator: operator,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,15 @@ const ConditionItem = ({
|
||||||
}, [onRemoveCondition, condition.id])
|
}, [onRemoveCondition, condition.id])
|
||||||
|
|
||||||
const currentMetadata = useMemo(() => {
|
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
|
||||||
|
}
|
||||||
|
// Fallback to name matching for backward compatibility with old conditions
|
||||||
return metadataList.find(metadata => metadata.name === condition.name)
|
return metadataList.find(metadata => metadata.name === condition.name)
|
||||||
}, [metadataList, condition.name])
|
}, [metadataList, condition.metadata_id, condition.name])
|
||||||
|
|
||||||
const handleConditionOperatorChange = useCallback((operator: ComparisonOperator) => {
|
const handleConditionOperatorChange = useCallback((operator: ComparisonOperator) => {
|
||||||
onUpdateCondition?.(
|
onUpdateCondition?.(
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,17 @@ const MetadataTrigger = ({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedDatasetsLoaded) {
|
if (selectedDatasetsLoaded) {
|
||||||
conditions.forEach((condition) => {
|
conditions.forEach((condition) => {
|
||||||
if (!metadataList.find(metadata => metadata.name === condition.name))
|
// First try to match by metadata_id for reliable reference
|
||||||
|
const foundById = condition.metadata_id && metadataList.find(metadata => metadata.id === condition.metadata_id)
|
||||||
|
// Fallback to name matching only for backward compatibility with old conditions
|
||||||
|
const foundByName = !condition.metadata_id && metadataList.find(metadata => metadata.name === condition.name)
|
||||||
|
|
||||||
|
// Only remove condition if both metadata_id and name matching fail
|
||||||
|
if (!foundById && !foundByName)
|
||||||
handleRemoveCondition(condition.id)
|
handleRemoveCondition(condition.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [metadataList, handleRemoveCondition, selectedDatasetsLoaded])
|
}, [metadataFilteringConditions, metadataList, handleRemoveCondition, selectedDatasetsLoaded])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PortalToFollowElem
|
<PortalToFollowElem
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ export enum MetadataFilteringVariableType {
|
||||||
export type MetadataFilteringCondition = {
|
export type MetadataFilteringCondition = {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
|
metadata_id?: string
|
||||||
comparison_operator: ComparisonOperator
|
comparison_operator: ComparisonOperator
|
||||||
value?: string | number
|
value?: string | number
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
||||||
}))
|
}))
|
||||||
}, [setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
const handleAddCondition = useCallback<HandleAddCondition>(({ name, type }) => {
|
const handleAddCondition = useCallback<HandleAddCondition>(({ id, name, type }) => {
|
||||||
let operator: ComparisonOperator = ComparisonOperator.is
|
let operator: ComparisonOperator = ComparisonOperator.is
|
||||||
|
|
||||||
if (type === MetadataFilteringVariableType.number)
|
if (type === MetadataFilteringVariableType.number)
|
||||||
|
|
@ -313,6 +313,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
||||||
|
|
||||||
const newCondition = {
|
const newCondition = {
|
||||||
id: uuid4(),
|
id: uuid4(),
|
||||||
|
metadata_id: id, // Save metadata.id for reliable reference
|
||||||
name,
|
name,
|
||||||
comparison_operator: operator,
|
comparison_operator: operator,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue