mirror of https://github.com/langgenius/dify.git
fix: fix custom tool content is not update (#30250)
This commit is contained in:
parent
543ce38a6c
commit
bf56c2e9db
|
|
@ -48,6 +48,7 @@ const EditCustomCollectionModal: FC<Props> = ({
|
||||||
|
|
||||||
const [editFirst, setEditFirst] = useState(!isAdd)
|
const [editFirst, setEditFirst] = useState(!isAdd)
|
||||||
const [paramsSchemas, setParamsSchemas] = useState<CustomParamSchema[]>(payload?.tools || [])
|
const [paramsSchemas, setParamsSchemas] = useState<CustomParamSchema[]>(payload?.tools || [])
|
||||||
|
const [labels, setLabels] = useState<string[]>(payload?.labels || [])
|
||||||
const [customCollection, setCustomCollection, getCustomCollection] = useGetState<CustomCollectionBackend>(isAdd
|
const [customCollection, setCustomCollection, getCustomCollection] = useGetState<CustomCollectionBackend>(isAdd
|
||||||
? {
|
? {
|
||||||
provider: '',
|
provider: '',
|
||||||
|
|
@ -67,6 +68,15 @@ const EditCustomCollectionModal: FC<Props> = ({
|
||||||
|
|
||||||
const originalProvider = isEdit ? payload.provider : ''
|
const originalProvider = isEdit ? payload.provider : ''
|
||||||
|
|
||||||
|
// Sync customCollection state when payload changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (isEdit) {
|
||||||
|
setCustomCollection(payload)
|
||||||
|
setParamsSchemas(payload.tools || [])
|
||||||
|
setLabels(payload.labels || [])
|
||||||
|
}
|
||||||
|
}, [isEdit, payload])
|
||||||
|
|
||||||
const [showEmojiPicker, setShowEmojiPicker] = useState(false)
|
const [showEmojiPicker, setShowEmojiPicker] = useState(false)
|
||||||
const emoji = customCollection.icon
|
const emoji = customCollection.icon
|
||||||
const setEmoji = (emoji: Emoji) => {
|
const setEmoji = (emoji: Emoji) => {
|
||||||
|
|
@ -124,7 +134,6 @@ const EditCustomCollectionModal: FC<Props> = ({
|
||||||
const [currTool, setCurrTool] = useState<CustomParamSchema | null>(null)
|
const [currTool, setCurrTool] = useState<CustomParamSchema | null>(null)
|
||||||
const [isShowTestApi, setIsShowTestApi] = useState(false)
|
const [isShowTestApi, setIsShowTestApi] = useState(false)
|
||||||
|
|
||||||
const [labels, setLabels] = useState<string[]>(payload?.labels || [])
|
|
||||||
const handleLabelSelect = (value: string[]) => {
|
const handleLabelSelect = (value: string[]) => {
|
||||||
setLabels(value)
|
setLabels(value)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,28 @@ const ProviderDetail = ({
|
||||||
const [isShowEditCollectionToolModal, setIsShowEditCustomCollectionModal] = useState(false)
|
const [isShowEditCollectionToolModal, setIsShowEditCustomCollectionModal] = useState(false)
|
||||||
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
||||||
const [deleteAction, setDeleteAction] = useState('')
|
const [deleteAction, setDeleteAction] = useState('')
|
||||||
|
|
||||||
|
const getCustomProvider = useCallback(async () => {
|
||||||
|
setIsDetailLoading(true)
|
||||||
|
const res = await fetchCustomCollection(collection.name)
|
||||||
|
if (res.credentials.auth_type === AuthType.apiKey && !res.credentials.api_key_header_prefix) {
|
||||||
|
if (res.credentials.api_key_value)
|
||||||
|
res.credentials.api_key_header_prefix = AuthHeaderPrefix.custom
|
||||||
|
}
|
||||||
|
setCustomCollection({
|
||||||
|
...res,
|
||||||
|
labels: collection.labels,
|
||||||
|
provider: collection.name,
|
||||||
|
})
|
||||||
|
setIsDetailLoading(false)
|
||||||
|
}, [collection.labels, collection.name])
|
||||||
|
|
||||||
const doUpdateCustomToolCollection = async (data: CustomCollectionBackend) => {
|
const doUpdateCustomToolCollection = async (data: CustomCollectionBackend) => {
|
||||||
await updateCustomCollection(data)
|
await updateCustomCollection(data)
|
||||||
onRefreshData()
|
onRefreshData()
|
||||||
|
await getCustomProvider()
|
||||||
|
// Use fresh data from form submission to avoid race condition with collection.labels
|
||||||
|
setCustomCollection(prev => prev ? { ...prev, labels: data.labels } : null)
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('common.api.actionSuccess'),
|
message: t('common.api.actionSuccess'),
|
||||||
|
|
@ -118,20 +137,6 @@ const ProviderDetail = ({
|
||||||
})
|
})
|
||||||
setIsShowEditCustomCollectionModal(false)
|
setIsShowEditCustomCollectionModal(false)
|
||||||
}
|
}
|
||||||
const getCustomProvider = useCallback(async () => {
|
|
||||||
setIsDetailLoading(true)
|
|
||||||
const res = await fetchCustomCollection(collection.name)
|
|
||||||
if (res.credentials.auth_type === AuthType.apiKey && !res.credentials.api_key_header_prefix) {
|
|
||||||
if (res.credentials.api_key_value)
|
|
||||||
res.credentials.api_key_header_prefix = AuthHeaderPrefix.custom
|
|
||||||
}
|
|
||||||
setCustomCollection({
|
|
||||||
...res,
|
|
||||||
labels: collection.labels,
|
|
||||||
provider: collection.name,
|
|
||||||
})
|
|
||||||
setIsDetailLoading(false)
|
|
||||||
}, [collection.labels, collection.name])
|
|
||||||
// workflow provider
|
// workflow provider
|
||||||
const [isShowEditWorkflowToolModal, setIsShowEditWorkflowToolModal] = useState(false)
|
const [isShowEditWorkflowToolModal, setIsShowEditWorkflowToolModal] = useState(false)
|
||||||
const getWorkflowToolProvider = useCallback(async () => {
|
const getWorkflowToolProvider = useCallback(async () => {
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ const VersionHistoryButton: FC<VersionHistoryButtonProps> = ({
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className={cn(
|
className={cn(
|
||||||
'p-2 rounded-lg border border-transparent',
|
'rounded-lg border border-transparent p-2',
|
||||||
theme === 'dark' && 'border-black/5 bg-white/10 backdrop-blur-sm',
|
theme === 'dark' && 'border-black/5 bg-white/10 backdrop-blur-sm',
|
||||||
)}
|
)}
|
||||||
onClick={handleViewVersionHistory}
|
onClick={handleViewVersionHistory}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue