mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-04 00:10:39 +08:00

### What problem does this PR solve? [https://github.com/infiniflow/ragflow/issues/7180](https://github.com/infiniflow/ragflow/issues/7180) When creating a knowledge base, support the enter key ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
|
import { Form, Input, Modal } from 'antd';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
type FieldType = {
|
|
name?: string;
|
|
};
|
|
|
|
interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
|
loading: boolean;
|
|
onOk: (name: string) => void;
|
|
}
|
|
|
|
const KnowledgeCreatingModal = ({
|
|
visible,
|
|
hideModal,
|
|
loading,
|
|
onOk,
|
|
}: IProps) => {
|
|
const [form] = Form.useForm();
|
|
|
|
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
|
|
|
const handleOk = async () => {
|
|
const ret = await form.validateFields();
|
|
onOk(ret.name);
|
|
};
|
|
|
|
const handleKeyDown = async (e) => {
|
|
if (e.key === 'Enter') {
|
|
await handleOk();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Modal
|
|
title={t('createKnowledgeBase')}
|
|
open={visible}
|
|
onOk={handleOk}
|
|
onCancel={hideModal}
|
|
okButtonProps={{ loading }}
|
|
>
|
|
<Form
|
|
name="Create"
|
|
labelCol={{ span: 4 }}
|
|
wrapperCol={{ span: 20 }}
|
|
style={{ maxWidth: 600 }}
|
|
autoComplete="off"
|
|
form={form}
|
|
>
|
|
<Form.Item<FieldType>
|
|
label={t('name')}
|
|
name="name"
|
|
rules={[{ required: true, message: t('namePlaceholder') }]}
|
|
>
|
|
<Input placeholder={t('namePlaceholder')} onKeyDown={handleKeyDown} />
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default KnowledgeCreatingModal;
|