feat: Add autofill by default value in endpoint plugin setting page. (#21669)
This commit is contained in:
parent
37e19de7ab
commit
765adabb32
1 changed files with 13 additions and 1 deletions
|
|
@ -18,6 +18,15 @@ type Props = {
|
||||||
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 = {},
|
||||||
|
|
@ -26,7 +35,10 @@ const EndpointModal: FC<Props> = ({
|
||||||
}) => {
|
}) => {
|
||||||
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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue