From d56c9e763007bb37291b786beeeeae3664bc9955 Mon Sep 17 00:00:00 2001 From: balibabu <cike8899@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:20:50 +0800 Subject: [PATCH] feat: add chunkText to messageText to distinguish table rows and when parsing, the delete and other buttons are set to disabled. (#130) * feat: when parsing, the delete and other buttons are set to disabled. * feat: add chunkText to messageText to distinguish table rows --- .../parsing-action-cell/index.less | 3 ++ .../parsing-action-cell/index.tsx | 54 +++++++++++++++---- .../parsing-status-cell/index.tsx | 3 +- .../components/knowledge-file/utils.ts | 6 +++ web/src/pages/chat/chat-container/index.less | 1 + web/src/pages/chat/chat-container/index.tsx | 4 +- 6 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.less create mode 100644 web/src/pages/add-knowledge/components/knowledge-file/utils.ts diff --git a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.less b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.less new file mode 100644 index 0000000..6353670 --- /dev/null +++ b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.less @@ -0,0 +1,3 @@ +.iconButton { + padding: 4px 8px; +} diff --git a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx index 4db9d39..186cc28 100644 --- a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx @@ -3,6 +3,9 @@ import { IKnowledgeFile } from '@/interfaces/database/knowledge'; import { DeleteOutlined, EditOutlined, ToolOutlined } from '@ant-design/icons'; import { Button, Dropdown, MenuProps, Space, Tooltip } from 'antd'; import { useDispatch } from 'umi'; +import { isParserRunning } from '../utils'; + +import styles from './index.less'; interface IProps { knowledgeBaseId: string; @@ -17,6 +20,7 @@ const ParsingActionCell = ({ }: IProps) => { const dispatch = useDispatch(); const documentId = record.id; + const isRunning = isParserRunning(record.run); const removeDocument = () => { dispatch({ @@ -29,7 +33,9 @@ const ParsingActionCell = ({ }; const onRmDocument = () => { - showDeleteConfirm({ onOk: removeDocument }); + if (!isRunning) { + showDeleteConfirm({ onOk: removeDocument }); + } }; const setCurrentRecord = () => { @@ -49,11 +55,13 @@ const ParsingActionCell = ({ }; const showRenameModal = () => { - setCurrentRecord(); - dispatch({ - type: 'kFModel/setIsShowRenameModal', - payload: true, - }); + if (!isRunning) { + setCurrentRecord(); + dispatch({ + type: 'kFModel/setIsShowRenameModal', + payload: true, + }); + } }; const chunkItems: MenuProps['items'] = [ @@ -70,14 +78,38 @@ const ParsingActionCell = ({ ]; return ( - <Space size={'middle'}> - <Dropdown menu={{ items: chunkItems }} trigger={['click']}> - <ToolOutlined size={20} onClick={setDocumentAndParserId} /> + <Space size={0}> + <Dropdown + menu={{ items: chunkItems }} + trigger={['click']} + disabled={isRunning} + > + <Button + type="text" + onClick={setDocumentAndParserId} + className={styles.iconButton} + > + <ToolOutlined size={20} /> + </Button> </Dropdown> <Tooltip title="Rename"> - <EditOutlined size={20} onClick={showRenameModal} /> + <Button + type="text" + disabled={isRunning} + onClick={showRenameModal} + className={styles.iconButton} + > + <EditOutlined size={20} /> + </Button> </Tooltip> - <DeleteOutlined size={20} onClick={onRmDocument} /> + <Button + type="text" + disabled={isRunning} + onClick={onRmDocument} + className={styles.iconButton} + > + <DeleteOutlined size={20} /> + </Button> </Space> ); }; diff --git a/web/src/pages/add-knowledge/components/knowledge-file/parsing-status-cell/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/parsing-status-cell/index.tsx index 6f21655..82b5ae3 100644 --- a/web/src/pages/add-knowledge/components/knowledge-file/parsing-status-cell/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-file/parsing-status-cell/index.tsx @@ -6,6 +6,7 @@ import { Badge, DescriptionsProps, Flex, Popover, Space, Tag } from 'antd'; import reactStringReplace from 'react-string-replace'; import { useDispatch } from 'umi'; import { RunningStatus, RunningStatusMap } from '../constant'; +import { isParserRunning } from '../utils'; import styles from './index.less'; const iconMap = { @@ -77,7 +78,7 @@ export const ParsingStatusCell = ({ record }: IProps) => { const text = record.run; const runningStatus = RunningStatusMap[text]; - const isRunning = text === RunningStatus.RUNNING; + const isRunning = isParserRunning(text); const OperationIcon = iconMap[text]; diff --git a/web/src/pages/add-knowledge/components/knowledge-file/utils.ts b/web/src/pages/add-knowledge/components/knowledge-file/utils.ts new file mode 100644 index 0000000..0965ffd --- /dev/null +++ b/web/src/pages/add-knowledge/components/knowledge-file/utils.ts @@ -0,0 +1,6 @@ +import { RunningStatus } from './constant'; + +export const isParserRunning = (text: RunningStatus) => { + const isRunning = text === RunningStatus.RUNNING; + return isRunning; +}; diff --git a/web/src/pages/chat/chat-container/index.less b/web/src/pages/chat/chat-container/index.less index 7a840f4..f74051b 100644 --- a/web/src/pages/chat/chat-container/index.less +++ b/web/src/pages/chat/chat-container/index.less @@ -25,6 +25,7 @@ flex-direction: row-reverse; } .messageText { + .chunkText(); padding: 0 14px; background-color: rgba(249, 250, 251, 1); word-break: break-all; diff --git a/web/src/pages/chat/chat-container/index.tsx b/web/src/pages/chat/chat-container/index.tsx index 575f06b..b0a3ca8 100644 --- a/web/src/pages/chat/chat-container/index.tsx +++ b/web/src/pages/chat/chat-container/index.tsx @@ -262,12 +262,12 @@ const ChatContainer = () => { if (!loading) { setValue(''); addNewestConversation(value); - sendMessage(value); + sendMessage(value.trim()); } }; const handleInputChange: ChangeEventHandler<HTMLInputElement> = (e) => { - const value = e.target.value.trim(); + const value = e.target.value; const nextValue = value.replaceAll('\\n', '\n').replaceAll('\\t', '\t'); setValue(nextValue); }; -- GitLab