fix(webhook): prevent SimpleSelect from resetting user selections (#25423)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
lyzno1 2025-09-09 17:11:11 +08:00 committed by GitHub
parent 249b62c9de
commit fbb7b02e90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 8 deletions

View File

@ -194,13 +194,18 @@ const SimpleSelect: FC<ISelectProps> = ({
const [selectedItem, setSelectedItem] = useState<Item | null>(null)
// Ensure selectedItem is properly set when defaultValue or items change
// Enhanced: Preserve user selection, only reset when necessary
useEffect(() => {
let defaultSelect = null
// Handle cases where defaultValue might be undefined, null, or empty string
defaultSelect = (defaultValue && items.find((item: Item) => item.value === defaultValue)) || null
setSelectedItem(defaultSelect)
}, [defaultValue, items])
// Only reset if no current selection or current selection is invalid
const isCurrentSelectionValid = selectedItem && items.some(item => item.value === selectedItem.value)
if (!isCurrentSelectionValid) {
let defaultSelect = null
// Handle cases where defaultValue might be undefined, null, or empty string
defaultSelect = items.find((item: Item) => item.value === defaultValue) ?? null
setSelectedItem(defaultSelect)
}
}, [defaultValue, items, selectedItem])
const listboxRef = useRef<HTMLDivElement>(null)

View File

@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
import React from 'react'
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import GenericTable from './generic-table'
import type { ColumnConfig, GenericTableRow } from './generic-table'
@ -31,7 +31,11 @@ const ParameterTable: FC<ParameterTableProps> = ({
}) => {
const { t } = useTranslation()
const typeOptions = createParameterTypeOptions(contentType, isRequestBody)
// Memoize typeOptions to prevent unnecessary re-renders that cause SimpleSelect state resets
const typeOptions = useMemo(() =>
createParameterTypeOptions(contentType, isRequestBody),
[contentType, isRequestBody],
)
// Define columns based on component type - matching prototype design
const columns: ColumnConfig[] = [