mirror of https://github.com/langgenius/dify.git
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:
parent
249b62c9de
commit
fbb7b02e90
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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[] = [
|
||||
|
|
|
|||
Loading…
Reference in New Issue