mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-30 15:16:45 +08:00
### What problem does this PR solve? Feat: Allows users to search for models in the model selection drop-down box #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
91 lines
2.0 KiB
TypeScript
91 lines
2.0 KiB
TypeScript
import { useShowDeleteConfirm } from '@/hooks/common-hooks';
|
|
import { DeleteOutlined, MoreOutlined } from '@ant-design/icons';
|
|
import { Dropdown, MenuProps, Space } from 'antd';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import React, { useMemo } from 'react';
|
|
import styles from './index.less';
|
|
|
|
interface IProps {
|
|
deleteItem: () => Promise<any> | void;
|
|
iconFontSize?: number;
|
|
iconFontColor?: string;
|
|
items?: MenuProps['items'];
|
|
height?: number;
|
|
needsDeletionValidation?: boolean;
|
|
showDeleteItems?: boolean;
|
|
}
|
|
|
|
const OperateDropdown = ({
|
|
deleteItem,
|
|
children,
|
|
iconFontSize = 30,
|
|
iconFontColor = 'gray',
|
|
items: otherItems = [],
|
|
height = 24,
|
|
needsDeletionValidation = true,
|
|
showDeleteItems = true,
|
|
}: React.PropsWithChildren<IProps>) => {
|
|
const { t } = useTranslation();
|
|
const showDeleteConfirm = useShowDeleteConfirm();
|
|
|
|
const handleDelete = () => {
|
|
if (needsDeletionValidation) {
|
|
showDeleteConfirm({ onOk: deleteItem });
|
|
} else {
|
|
deleteItem();
|
|
}
|
|
};
|
|
|
|
const handleDropdownMenuClick: MenuProps['onClick'] = ({ domEvent, key }) => {
|
|
domEvent.preventDefault();
|
|
domEvent.stopPropagation();
|
|
if (key === '1') {
|
|
handleDelete();
|
|
}
|
|
};
|
|
|
|
const items: MenuProps['items'] = useMemo(() => {
|
|
const items = [];
|
|
|
|
if (showDeleteItems) {
|
|
items.push({
|
|
key: '1',
|
|
label: (
|
|
<Space>
|
|
{t('common.delete')}
|
|
<DeleteOutlined />
|
|
</Space>
|
|
),
|
|
});
|
|
}
|
|
|
|
return [...items, ...otherItems];
|
|
}, [showDeleteItems, otherItems, t]);
|
|
|
|
return (
|
|
<Dropdown
|
|
menu={{
|
|
items,
|
|
onClick: handleDropdownMenuClick,
|
|
}}
|
|
>
|
|
{children || (
|
|
<span className={styles.delete}>
|
|
<MoreOutlined
|
|
rotate={90}
|
|
style={{
|
|
fontSize: iconFontSize,
|
|
color: iconFontColor,
|
|
cursor: 'pointer',
|
|
height,
|
|
}}
|
|
/>
|
|
</span>
|
|
)}
|
|
</Dropdown>
|
|
);
|
|
};
|
|
|
|
export default OperateDropdown;
|