浏览代码

feat: Add autofill by default value in endpoint plugin setting page. (#21669)

tags/1.5.1
呆萌闷油瓶 4 个月前
父节点
当前提交
765adabb32
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13
    1
      web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx

+ 13
- 1
web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx 查看文件

onSaved: (value: Record<string, any>) => void onSaved: (value: Record<string, any>) => void
} }


const extractDefaultValues = (schemas: any[]) => {
const result: Record<string, any> = {}
for (const field of schemas) {
if (field.default !== undefined)
result[field.name] = field.default
}
return result
}

const EndpointModal: FC<Props> = ({ const EndpointModal: FC<Props> = ({
formSchemas, formSchemas,
defaultValues = {}, defaultValues = {},
}) => { }) => {
const getValueFromI18nObject = useRenderI18nObject() const getValueFromI18nObject = useRenderI18nObject()
const { t } = useTranslation() const { t } = useTranslation()
const [tempCredential, setTempCredential] = React.useState<any>(defaultValues)
const initialValues = Object.keys(defaultValues).length > 0
? defaultValues
: extractDefaultValues(formSchemas)
const [tempCredential, setTempCredential] = React.useState<any>(initialValues)


const handleSave = () => { const handleSave = () => {
for (const field of formSchemas) { for (const field of formSchemas) {

正在加载...
取消
保存