fix(web): Add unique instanceId & key for AgentStrategy component (#18053)

- Use schema.variable as the value for instanceId and key to ensure uniqueness and consistency
- Improved React rendering performance by adding the key attribute
pull/19386/head
zhujiruo 1 year ago
parent 163a76eb6e
commit 4c72fc72c2

@ -66,6 +66,7 @@ export const AgentStrategy = memo((props: AgentStrategyProps) => {
case FormTypeEnum.textInput: { case FormTypeEnum.textInput: {
const def = schema as CredentialFormSchemaTextInput const def = schema as CredentialFormSchemaTextInput
const value = props.value[schema.variable] || schema.default const value = props.value[schema.variable] || schema.default
const instanceId = schema.variable
const onChange = (value: string) => { const onChange = (value: string) => {
props.onChange({ ...props.value, [schema.variable]: value }) props.onChange({ ...props.value, [schema.variable]: value })
} }
@ -77,6 +78,8 @@ export const AgentStrategy = memo((props: AgentStrategyProps) => {
value={value} value={value}
onChange={onChange} onChange={onChange}
onGenerated={handleGenerated} onGenerated={handleGenerated}
instanceId={instanceId}
key={instanceId}
title={renderI18nObject(schema.label)} title={renderI18nObject(schema.label)}
headerClassName='bg-transparent px-0 text-text-secondary system-sm-semibold-uppercase' headerClassName='bg-transparent px-0 text-text-secondary system-sm-semibold-uppercase'
containerBackgroundClassName='bg-transparent' containerBackgroundClassName='bg-transparent'

Loading…
Cancel
Save