mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
create & update endpoint
This commit is contained in:
parent
ebaf8766ef
commit
973cd126bb
|
@ -14,6 +14,7 @@ import {
|
||||||
deleteEndpoint,
|
deleteEndpoint,
|
||||||
disableEndpoint,
|
disableEndpoint,
|
||||||
enableEndpoint,
|
enableEndpoint,
|
||||||
|
updateEndpoint,
|
||||||
} from '@/service/plugins'
|
} from '@/service/plugins'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -94,6 +95,22 @@ const EndpointCard = ({
|
||||||
return addDefaultValue(data.settings, formSchemas)
|
return addDefaultValue(data.settings, formSchemas)
|
||||||
}, [data.settings, formSchemas])
|
}, [data.settings, formSchemas])
|
||||||
|
|
||||||
|
const handleUpdate = (state: any) => {
|
||||||
|
try {
|
||||||
|
updateEndpoint({
|
||||||
|
url: '/workspaces/current/endpoints',
|
||||||
|
body: {
|
||||||
|
endpoint_id: data.id,
|
||||||
|
settings: state,
|
||||||
|
name: state.name,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='p-0.5 bg-background-section-burn rounded-xl'>
|
<div className='p-0.5 bg-background-section-burn rounded-xl'>
|
||||||
<div className='group p-2.5 pl-3 bg-components-panel-on-panel-item-bg rounded-[10px] border-[0.5px] border-components-panel-border'>
|
<div className='group p-2.5 pl-3 bg-components-panel-on-panel-item-bg rounded-[10px] border-[0.5px] border-components-panel-border'>
|
||||||
|
@ -168,10 +185,10 @@ const EndpointCard = ({
|
||||||
)}
|
)}
|
||||||
{isShowEndpointModal && (
|
{isShowEndpointModal && (
|
||||||
<EndpointModal
|
<EndpointModal
|
||||||
id={data.id}
|
|
||||||
formSchemas={formSchemas}
|
formSchemas={formSchemas}
|
||||||
defaultValues={formValue}
|
defaultValues={formValue}
|
||||||
onCancel={hideEndpointModalConfirm}
|
onCancel={hideEndpointModalConfirm}
|
||||||
|
onSaved={handleUpdate}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,6 +8,9 @@ import EndpointCard from './endpoint-card'
|
||||||
import { toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
import { toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
|
import {
|
||||||
|
createEndpoint,
|
||||||
|
} from '@/service/plugins'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
pluginUniqueID: string
|
pluginUniqueID: string
|
||||||
|
@ -31,6 +34,22 @@ const EndpointList = ({
|
||||||
return toolCredentialToFormSchemas(declaration.settings)
|
return toolCredentialToFormSchemas(declaration.settings)
|
||||||
}, [declaration.settings])
|
}, [declaration.settings])
|
||||||
|
|
||||||
|
const handleCreate = (state: any) => {
|
||||||
|
try {
|
||||||
|
createEndpoint({
|
||||||
|
url: '/workspaces/current/endpoints',
|
||||||
|
body: {
|
||||||
|
plugin_unique_identifier: pluginUniqueID,
|
||||||
|
settings: state,
|
||||||
|
name: state.name,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='px-4 py-2 border-t border-divider-subtle'>
|
<div className='px-4 py-2 border-t border-divider-subtle'>
|
||||||
<div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'>
|
<div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'>
|
||||||
|
@ -59,9 +78,9 @@ const EndpointList = ({
|
||||||
</div>
|
</div>
|
||||||
{isShowEndpointModal && (
|
{isShowEndpointModal && (
|
||||||
<EndpointModal
|
<EndpointModal
|
||||||
id={pluginUniqueID}
|
|
||||||
formSchemas={formSchemas}
|
formSchemas={formSchemas}
|
||||||
onCancel={hideEndpointModal}
|
onCancel={hideEndpointModal}
|
||||||
|
onSaved={handleCreate}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,37 +7,35 @@ import ActionButton from '@/app/components/base/action-button'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
import Drawer from '@/app/components/base/drawer'
|
import Drawer from '@/app/components/base/drawer'
|
||||||
import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form'
|
import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form'
|
||||||
// import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string
|
|
||||||
formSchemas: any
|
formSchemas: any
|
||||||
defaultValues?: any
|
defaultValues?: any
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
// onSaved: (value: Record<string, any>) => void
|
onSaved: (value: Record<string, any>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const EndpointModal: FC<Props> = ({
|
const EndpointModal: FC<Props> = ({
|
||||||
id,
|
|
||||||
formSchemas,
|
formSchemas,
|
||||||
defaultValues = {},
|
defaultValues = {},
|
||||||
onCancel,
|
onCancel,
|
||||||
// onSaved,
|
onSaved,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
const [tempCredential, setTempCredential] = React.useState<any>(defaultValues)
|
const [tempCredential, setTempCredential] = React.useState<any>(defaultValues)
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
// for (const field of credentialSchema) {
|
for (const field of formSchemas) {
|
||||||
// if (field.required && !tempCredential[field.name]) {
|
if (field.required && !tempCredential[field.name]) {
|
||||||
// Toast.notify({ type: 'error', message: t('common.errorMsg.fieldRequired', { field: field.label[language] || field.label.en_US }) })
|
Toast.notify({ type: 'error', message: t('common.errorMsg.fieldRequired', { field: field.label[language] || field.label.en_US }) })
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// onSaved(tempCredential)
|
onSaved(tempCredential)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user