Feat: Add NextLLMSelect with shadcn-ui. #3221 (#5542)

### What problem does this PR solve?
Feat: Add NextLLMSelect with shadcn-ui. #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu 2025-03-03 13:54:06 +08:00 committed by GitHub
parent 7a81fa00e9
commit 5d89a8010b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 8 deletions

View File

@ -1,7 +1,10 @@
import { LlmModelType } from '@/constants/knowledge'; import { LlmModelType } from '@/constants/knowledge';
import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks'; import { useComposeLlmOptionsByModelTypes } from '@/hooks/llm-hooks';
import { Popover, Select } from 'antd'; import { Popover as AntPopover, Select as AntSelect } from 'antd';
import { useState } from 'react';
import LlmSettingItems from '../llm-setting-items'; import LlmSettingItems from '../llm-setting-items';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
import { Select, SelectTrigger, SelectValue } from '../ui/select';
interface IProps { interface IProps {
id?: string; id?: string;
@ -25,14 +28,14 @@ const LLMSelect = ({ id, value, onChange, disabled }: IProps) => {
); );
return ( return (
<Popover <AntPopover
content={content} content={content}
trigger="click" trigger="click"
placement="left" placement="left"
arrow={false} arrow={false}
destroyTooltipOnHide destroyTooltipOnHide
> >
<Select <AntSelect
options={modelOptions} options={modelOptions}
style={{ width: '100%' }} style={{ width: '100%' }}
dropdownStyle={{ display: 'none' }} dropdownStyle={{ display: 'none' }}
@ -41,8 +44,37 @@ const LLMSelect = ({ id, value, onChange, disabled }: IProps) => {
onChange={onChange} onChange={onChange}
disabled={disabled} disabled={disabled}
/> />
</Popover> </AntPopover>
); );
}; };
export default LLMSelect; export default LLMSelect;
export function NextLLMSelect({ value, onChange, disabled }: IProps) {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
return (
<Select value={value} onValueChange={onChange} disabled={disabled}>
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
<PopoverTrigger asChild>
<SelectTrigger
onClick={(e) => {
e.preventDefault();
setIsPopoverOpen(true);
}}
>
<SelectValue placeholder="xxx" />
</SelectTrigger>
</PopoverTrigger>
<PopoverContent side={'left'}>
<LlmSettingItems
formItemLayout={{
labelCol: { span: 10 },
wrapperCol: { span: 14 },
}}
></LlmSettingItems>
</PopoverContent>
</Popover>
</Select>
);
}

View File

@ -186,11 +186,12 @@ export type RAGFlowSelectGroupOptionType = {
options: RAGFlowSelectOptionType[]; options: RAGFlowSelectOptionType[];
}; };
type RAGFlowSelectProps = Partial<ControllerRenderProps> & { export type RAGFlowSelectProps = Partial<ControllerRenderProps> & {
FormControlComponent?: typeof FormControl; FormControlComponent?: typeof FormControl;
options?: (RAGFlowSelectOptionType | RAGFlowSelectGroupOptionType)[]; options?: (RAGFlowSelectOptionType | RAGFlowSelectGroupOptionType)[];
allowClear?: boolean; allowClear?: boolean;
placeholder?: React.ReactNode; placeholder?: React.ReactNode;
contentProps?: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>;
} & SelectPrimitive.SelectProps; } & SelectPrimitive.SelectProps;
/** /**
@ -220,6 +221,7 @@ export const RAGFlowSelect = forwardRef<
options = [], options = [],
allowClear, allowClear,
placeholder, placeholder,
contentProps = {},
}, },
ref, ref,
) { ) {
@ -265,7 +267,7 @@ export const RAGFlowSelect = forwardRef<
<SelectValue placeholder={placeholder} /> <SelectValue placeholder={placeholder} />
</SelectTrigger> </SelectTrigger>
</FormControlWidget> </FormControlWidget>
<SelectContent> <SelectContent {...contentProps}>
{options.map((o, idx) => { {options.map((o, idx) => {
if ('value' in o) { if ('value' in o) {
return ( return (

View File

@ -1,4 +1,4 @@
import LLMSelect from '@/components/llm-select'; import { NextLLMSelect } from '@/components/llm-select';
import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item'; import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item';
import { PromptEditor } from '@/components/prompt-editor'; import { PromptEditor } from '@/components/prompt-editor';
import { import {
@ -33,7 +33,7 @@ const GenerateForm = ({ form }: INextOperatorForm) => {
{t('chat.model')} {t('chat.model')}
</FormLabel> </FormLabel>
<FormControl> <FormControl>
<LLMSelect {...field} /> <NextLLMSelect {...field} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>