diff --git a/packages/dify-ui/src/autocomplete/index.tsx b/packages/dify-ui/src/autocomplete/index.tsx index fb25700a51b..af8d5ca6767 100644 --- a/packages/dify-ui/src/autocomplete/index.tsx +++ b/packages/dify-ui/src/autocomplete/index.tsx @@ -17,7 +17,30 @@ import { parsePlacement } from '../placement' export type { Placement } -export const Autocomplete = BaseAutocomplete.Root +export type AutocompleteRootProps = BaseAutocomplete.Root.Props +export type AutocompleteRootGroupedProps< + Items extends readonly { items: readonly unknown[] }[], +> = Omit, 'items'> & { + items: Items +} +export type AutocompleteRootFlatProps + = Omit, 'items'> + & { + items?: readonly ItemValue[] + } + +export function Autocomplete( + props: AutocompleteRootGroupedProps, +): React.JSX.Element +export function Autocomplete( + props: AutocompleteRootFlatProps, +): React.JSX.Element +export function Autocomplete( + props: AutocompleteRootProps, +): React.JSX.Element { + return +} + export const AutocompleteValue = BaseAutocomplete.Value export const AutocompleteGroup = BaseAutocomplete.Group export const AutocompleteCollection = BaseAutocomplete.Collection @@ -25,7 +48,6 @@ export const AutocompleteRow = BaseAutocomplete.Row export const useAutocompleteFilter = BaseAutocomplete.useFilter export const useAutocompleteFilteredItems = BaseAutocomplete.useFilteredItems -export type AutocompleteRootProps = BaseAutocomplete.Root.Props export type AutocompleteRootChangeEventDetails = BaseAutocomplete.Root.ChangeEventDetails export type AutocompleteRootHighlightEventDetails = BaseAutocomplete.Root.HighlightEventDetails diff --git a/packages/dify-ui/src/combobox/index.tsx b/packages/dify-ui/src/combobox/index.tsx index d1d9204f977..7504d684b61 100644 --- a/packages/dify-ui/src/combobox/index.tsx +++ b/packages/dify-ui/src/combobox/index.tsx @@ -17,7 +17,15 @@ import { parsePlacement } from '../placement' export type { Placement } -export const Combobox = BaseCombobox.Root +export type ComboboxRootProps + = BaseCombobox.Root.Props + +export function Combobox( + props: ComboboxRootProps, +): React.JSX.Element { + return +} + export const ComboboxValue = BaseCombobox.Value export const ComboboxGroup = BaseCombobox.Group export const ComboboxCollection = BaseCombobox.Collection @@ -25,8 +33,6 @@ export const ComboboxRow = BaseCombobox.Row export const useComboboxFilter = BaseCombobox.useFilter export const useComboboxFilteredItems = BaseCombobox.useFilteredItems -export type ComboboxRootProps - = BaseCombobox.Root.Props export type ComboboxRootChangeEventDetails = BaseCombobox.Root.ChangeEventDetails export type ComboboxRootHighlightEventDetails = BaseCombobox.Root.HighlightEventDetails diff --git a/packages/dify-ui/src/select/index.tsx b/packages/dify-ui/src/select/index.tsx index 60c026342d0..58b73bd8b54 100644 --- a/packages/dify-ui/src/select/index.tsx +++ b/packages/dify-ui/src/select/index.tsx @@ -16,7 +16,17 @@ import { parsePlacement } from '../placement' export type { Placement } -export const Select = BaseSelect.Root +export type SelectRootProps< + Value, + Multiple extends boolean | undefined = false, +> = BaseSelect.Root.Props + +export function Select( + props: SelectRootProps, +): React.JSX.Element { + return +} + export const SelectValue = BaseSelect.Value export const SelectGroup = BaseSelect.Group diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/range-selector.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/range-selector.tsx index 18def9308eb..c94169190ec 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/range-selector.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/range-selector.tsx @@ -36,9 +36,9 @@ const RangeSelector: FC = ({ name: t(`filter.period.${range.name}`, { ns: 'appLog' }), })) }, [ranges, t]) - const [value, setValue] = useState('0') + const [value, setValue] = useState(0) const selectedItem = useMemo(() => { - return items.find(item => String(item.value) === value) ?? null + return items.find(item => item.value === value) ?? null }, [items, value]) const handleSelectRange = useCallback((item: TimePeriodOption) => { @@ -50,20 +50,20 @@ const RangeSelector: FC = ({ period = { start: startOfToday, end: endOfToday } } else { - period = { start: today.subtract(item.value as number, 'day').startOf('day'), end: today.endOf('day') } + period = { start: today.subtract(item.value, 'day').startOf('day'), end: today.endOf('day') } } onSelect({ query: period!, name }) }, [onSelect]) return ( - key={`default-select-${options.join('-')}`} - value={tempPayload.default ? String(tempPayload.default) : EMPTY_SELECT_VALUE} - onValueChange={value => onPayloadChange('default')(value === EMPTY_SELECT_VALUE ? undefined : value)} + value={typeof tempPayload.default === 'string' ? tempPayload.default : EMPTY_SELECT_VALUE} + onValueChange={(value) => { + if (value == null) + return + onPayloadChange('default')(value === EMPTY_SELECT_VALUE ? undefined : value) + }} > diff --git a/web/app/components/app/configuration/debug/chat-user-input.tsx b/web/app/components/app/configuration/debug/chat-user-input.tsx index 251cf819e5d..ff08429faad 100644 --- a/web/app/components/app/configuration/debug/chat-user-input.tsx +++ b/web/app/components/app/configuration/debug/chat-user-input.tsx @@ -105,17 +105,17 @@ const ChatUserInput = ({ /> )} {type === 'select' && ( - + value={typeof inputs[key] === 'string' && inputs[key] !== '' ? inputs[key] : null} disabled={debugInputReadonly} onValueChange={(nextValue) => { - if (!nextValue) + if (nextValue == null || nextValue === '') return handleInputValueChange(key, nextValue) }} > - {String(inputs[key] || t('placeholder.select', { ns: 'common' }))} + {typeof inputs[key] === 'string' && inputs[key] !== '' ? inputs[key] : t('placeholder.select', { ns: 'common' })} {(options || []).map(option => ( diff --git a/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx b/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx index b3f85a225a6..d54ed160c7e 100644 --- a/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx +++ b/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx @@ -21,7 +21,7 @@ import { useAppVoices } from '@/service/use-apps' import { TtsAutoPlay } from '@/types/app' type SelectOption = { - value: string | number + value: string name: string } @@ -40,7 +40,7 @@ const VoiceParamConfig = ({ const text2speech = useFeatures(state => state.features.text2speech) const featuresStore = useFeaturesStore() const formatLanguageName = (item: SelectOption) => { - return t(`voice.language.${replace(String(item.value), '-', '')}`, item.name, { ns: 'common' as const }) + return t(`voice.language.${replace(item.value, '-', '')}`, item.name, { ns: 'common' as const }) } let languageItem = languages.find(item => item.value === text2speech?.language) @@ -101,9 +101,9 @@ const VoiceParamConfig = ({ { - if (!nextValue) + if (nextValue == null || nextValue === '') return handleChange({ voice: nextValue, @@ -147,7 +147,7 @@ const VoiceParamConfig = ({ {voiceItems?.map((item: SelectOption) => ( - + {item.name} diff --git a/web/app/components/datasets/documents/detail/completed/components/__tests__/menu-bar.spec.tsx b/web/app/components/datasets/documents/detail/completed/components/__tests__/menu-bar.spec.tsx index 25ecded3493..666c5a673b2 100644 --- a/web/app/components/datasets/documents/detail/completed/components/__tests__/menu-bar.spec.tsx +++ b/web/app/components/datasets/documents/detail/completed/components/__tests__/menu-bar.spec.tsx @@ -1,3 +1,4 @@ +import type { ComponentProps } from 'react' import { CheckboxGroup } from '@langgenius/dify-ui/checkbox-group' import { fireEvent, render, screen } from '@testing-library/react' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -12,7 +13,7 @@ vi.mock('../../display-toggle', () => ({ })) describe('MenuBar', () => { - const defaultProps = { + const defaultProps: ComponentProps = { hasSelectableSegments: true, isLoading: false, totalText: '10 Chunks', @@ -21,7 +22,7 @@ describe('MenuBar', () => { { value: 0, name: 'Enabled' }, { value: 1, name: 'Disabled' }, ], - selectDefaultValue: 'all' as const, + selectDefaultValue: 'all', onChangeStatus: vi.fn(), inputValue: '', onInputChange: vi.fn(), diff --git a/web/app/components/datasets/documents/detail/completed/components/menu-bar.tsx b/web/app/components/datasets/documents/detail/completed/components/menu-bar.tsx index 89372464063..816e65c868b 100644 --- a/web/app/components/datasets/documents/detail/completed/components/menu-bar.tsx +++ b/web/app/components/datasets/documents/detail/completed/components/menu-bar.tsx @@ -1,4 +1,5 @@ 'use client' +import type { SegmentStatusFilterOption, SegmentStatusFilterValue } from '../hooks/use-search-filter' import { Checkbox } from '@langgenius/dify-ui/checkbox' import { Select, SelectContent, SelectItem, SelectItemIndicator, SelectItemText, SelectTrigger } from '@langgenius/dify-ui/select' import { useTranslation } from 'react-i18next' @@ -7,18 +8,13 @@ import Input from '@/app/components/base/input' import DisplayToggle from '../display-toggle' import s from '../style.module.css' -type Item = { - value: number | string - name: string -} & Record - type MenuBarProps = { hasSelectableSegments: boolean isLoading: boolean totalText: string - statusList: Item[] - selectDefaultValue: 'all' | 0 | 1 - onChangeStatus: (item: Item) => void + statusList: SegmentStatusFilterOption[] + selectDefaultValue: SegmentStatusFilterValue + onChangeStatus: (item: SegmentStatusFilterOption) => void inputValue: string onInputChange: (value: string) => void isCollapsed: boolean @@ -55,12 +51,12 @@ function MenuBar({ )}
{totalText}
- { if (!nextValue) return - const nextItem = timezones.find(item => String(item.value) === nextValue) + const nextItem = timezones.find(item => item.value === nextValue) if (nextItem) handleSelectTimezone(nextItem) }} @@ -157,7 +157,7 @@ export default function PreferencePage() { {timezones.map(item => ( - + {item.name} diff --git a/web/app/components/plugins/install-plugin/install-from-github/index.tsx b/web/app/components/plugins/install-plugin/install-from-github/index.tsx index 4ba76384ed7..6dd1c202a4d 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/index.tsx @@ -24,7 +24,7 @@ import SelectPackage from './steps/selectPackage' const i18nPrefix = 'installFromGitHub' type SelectOption = { - value: string | number + value: string name: string } diff --git a/web/app/components/plugins/install-plugin/install-from-github/steps/__tests__/selectPackage.spec.tsx b/web/app/components/plugins/install-plugin/install-from-github/steps/__tests__/selectPackage.spec.tsx index 352dad7136d..6c990722262 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/steps/__tests__/selectPackage.spec.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/steps/__tests__/selectPackage.spec.tsx @@ -5,7 +5,7 @@ import { PluginCategoryEnum } from '../../../../types' import SelectPackage from '../selectPackage' type SelectOption = { - value: string | number + value: string name: string } diff --git a/web/app/components/plugins/install-plugin/install-from-github/steps/selectPackage.tsx b/web/app/components/plugins/install-plugin/install-from-github/steps/selectPackage.tsx index dc7d8f75afe..02d229f2c26 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/steps/selectPackage.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/steps/selectPackage.tsx @@ -12,7 +12,7 @@ import { handleUpload } from '../../hooks' const i18nPrefix = 'installFromGitHub' type SelectOption = { - value: string | number + value: string name: string } @@ -49,8 +49,8 @@ const SelectPackage: React.FC = ({ const { t } = useTranslation() const isEdit = Boolean(updatePayload) const [isUploading, setIsUploading] = React.useState(false) - const selectedVersionOption = versions.find(item => String(item.value) === selectedVersion) ?? null - const selectedPackageOption = packages.find(item => String(item.value) === selectedPackage) ?? null + const selectedVersionOption = versions.find(item => item.value === selectedVersion) ?? null + const selectedPackageOption = packages.find(item => item.value === selectedPackage) ?? null const handleUploadPackage = async () => { if (isUploading) @@ -80,11 +80,11 @@ const SelectPackage: React.FC = ({ <> { - if (!value) + if (value == null) return - const selectedItem = packages.find(item => String(item.value) === value) + const selectedItem = packages.find(item => item.value === value) if (selectedItem) onSelectPackage(selectedItem) }} @@ -141,7 +141,7 @@ const SelectPackage: React.FC = ({ {packages.map(item => ( - + {item.name} diff --git a/web/app/components/plugins/plugin-detail-panel/tool-selector/components/reasoning-config-form.tsx b/web/app/components/plugins/plugin-detail-panel/tool-selector/components/reasoning-config-form.tsx index b2b4a9b2794..437cb303ef7 100644 --- a/web/app/components/plugins/plugin-detail-panel/tool-selector/components/reasoning-config-form.tsx +++ b/web/app/components/plugins/plugin-detail-panel/tool-selector/components/reasoning-config-form.tsx @@ -156,8 +156,9 @@ const ReasoningConfigForm: React.FC = ({ language, schema, }) + const selectValue = typeof varInput?.value === 'string' ? varInput.value : null const selectedOption = isSelect && options - ? pickerProps.selectItems.find(item => item.value === (varInput?.value as string | number | undefined)) ?? null + ? pickerProps.selectItems.find(item => item.value === selectValue) ?? null : null return ( @@ -230,13 +231,20 @@ const ReasoningConfigForm: React.FC = ({ /> )} {isSelect && options && ( - + )} + {item.type === 'string' && ( + ) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }} + maxLength={item.max_length} + /> + )} + {item.type === 'paragraph' && ( +