diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx index 20157cfcb..de1baaf9d 100644 --- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx +++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx @@ -19,7 +19,6 @@ import { Switch } from '@/components/ui/switch'; import { Textarea } from '@/components/ui/textarea'; import { useFetchChunk } from '@/hooks/chunk-hooks'; import { IModalProps } from '@/interfaces/common'; -import { Trash2 } from 'lucide-react'; import React, { useCallback, useEffect, useState } from 'react'; import { FieldValues, FormProvider, useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; @@ -194,9 +193,9 @@ const ChunkCreatingModal: React.FC & kFProps> = ({ {t('chunk.enabled')} -
+ {/*
{t('common.delete')} -
+
*/} )} diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx index d90147819..033e83d5b 100644 --- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx +++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/index.tsx @@ -40,7 +40,7 @@ import { useNavigatePage, } from '@/hooks/logic-hooks/navigate-hooks'; import { useFetchKnowledgeBaseConfiguration } from '@/hooks/use-knowledge-request'; -import { useGetDocumentUrl } from '../../../knowledge-chunk/components/document-preview/hooks'; +import { useGetDocumentUrl } from './components/document-preview/hooks'; import styles from './index.less'; const Chunk = () => { diff --git a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-card/index.less b/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-card/index.less deleted file mode 100644 index 127a5c790..000000000 --- a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-card/index.less +++ /dev/null @@ -1,34 +0,0 @@ -.image { - width: 100px !important; - object-fit: contain; -} - -.imagePreview { - max-width: 50vw; - max-height: 50vh; - object-fit: contain; -} - -.content { - flex: 1; - .chunkText; -} - -.contentEllipsis { - .multipleLineEllipsis(3); -} - -.contentText { - word-break: break-all !important; -} - -.chunkCard { - width: 100%; -} - -.cardSelected { - background-color: @selectedBackgroundColor; -} -.cardSelectedDark { - background-color: #ffffff2f; -} diff --git a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-card/index.tsx b/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-card/index.tsx deleted file mode 100644 index b7e61e06a..000000000 --- a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-card/index.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import Image from '@/components/image'; -import { IChunk } from '@/interfaces/database/knowledge'; -import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd'; -import classNames from 'classnames'; -import DOMPurify from 'dompurify'; -import { useEffect, useState } from 'react'; - -import { useTheme } from '@/components/theme-provider'; -import { ChunkTextMode } from '../../constant'; -import styles from './index.less'; - -interface IProps { - item: IChunk; - checked: boolean; - switchChunk: (available?: number, chunkIds?: string[]) => void; - editChunk: (chunkId: string) => void; - handleCheckboxClick: (chunkId: string, checked: boolean) => void; - selected: boolean; - clickChunkCard: (chunkId: string) => void; - textMode: ChunkTextMode; -} - -const ChunkCard = ({ - item, - checked, - handleCheckboxClick, - editChunk, - switchChunk, - selected, - clickChunkCard, - textMode, -}: IProps) => { - const available = Number(item.available_int); - const [enabled, setEnabled] = useState(false); - const { theme } = useTheme(); - - const onChange = (checked: boolean) => { - setEnabled(checked); - switchChunk(available === 0 ? 1 : 0, [item.chunk_id]); - }; - - const handleCheck: CheckboxProps['onChange'] = (e) => { - handleCheckboxClick(item.chunk_id, e.target.checked); - }; - - const handleContentDoubleClick = () => { - editChunk(item.chunk_id); - }; - - const handleContentClick = () => { - clickChunkCard(item.chunk_id); - }; - - useEffect(() => { - setEnabled(available === 1); - }, [available]); - - return ( - - - - {item.image_id && ( - - } - > - - - )} - -
-
-
- -
- -
-
-
- ); -}; - -export default ChunkCard; diff --git a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-creating-modal/index.tsx b/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-creating-modal/index.tsx deleted file mode 100644 index abcf1742c..000000000 --- a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-creating-modal/index.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import EditTag from '@/components/edit-tag'; -import { useFetchChunk } from '@/hooks/chunk-hooks'; -import { IModalProps } from '@/interfaces/common'; -import { IChunk } from '@/interfaces/database/knowledge'; -import { DeleteOutlined } from '@ant-design/icons'; -import { Divider, Form, Input, Modal, Space, Switch } from 'antd'; -import React, { useCallback, useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { useDeleteChunkByIds } from '../../hooks'; -import { - transformTagFeaturesArrayToObject, - transformTagFeaturesObjectToArray, -} from '../../utils'; -import { TagFeatureItem } from './tag-feature-item'; - -type FieldType = Pick< - IChunk, - 'content_with_weight' | 'tag_kwd' | 'question_kwd' | 'important_kwd' ->; - -interface kFProps { - doc_id: string; - chunkId: string | undefined; - parserId: string; -} - -const ChunkCreatingModal: React.FC & kFProps> = ({ - doc_id, - chunkId, - hideModal, - onOk, - loading, - parserId, -}) => { - const [form] = Form.useForm(); - const [checked, setChecked] = useState(false); - const { removeChunk } = useDeleteChunkByIds(); - const { data } = useFetchChunk(chunkId); - const { t } = useTranslation(); - - const isTagParser = parserId === 'tag'; - - const handleOk = useCallback(async () => { - try { - const values = await form.validateFields(); - console.log('🚀 ~ handleOk ~ values:', values); - - onOk?.({ - ...values, - tag_feas: transformTagFeaturesArrayToObject(values.tag_feas), - available_int: checked ? 1 : 0, // available_int - }); - } catch (errorInfo) { - console.log('Failed:', errorInfo); - } - }, [checked, form, onOk]); - - const handleRemove = useCallback(() => { - if (chunkId) { - return removeChunk([chunkId], doc_id); - } - }, [chunkId, doc_id, removeChunk]); - - const handleCheck = useCallback(() => { - setChecked(!checked); - }, [checked]); - - useEffect(() => { - if (data?.code === 0) { - const { available_int, tag_feas } = data.data; - form.setFieldsValue({ - ...(data.data || {}), - tag_feas: transformTagFeaturesObjectToArray(tag_feas), - }); - - setChecked(available_int !== 0); - } - }, [data, form, chunkId]); - - return ( - -
- - label={t('chunk.chunk')} - name="content_with_weight" - rules={[{ required: true, message: t('chunk.chunkMessage') }]} - > - - - - label={t('chunk.keyword')} name="important_kwd"> - - - - label={t('chunk.question')} - name="question_kwd" - tooltip={t('chunk.questionTip')} - > - - - {isTagParser && ( - - label={t('knowledgeConfiguration.tagName')} - name="tag_kwd" - > - - - )} - - {!isTagParser && } - - - {chunkId && ( -
- - - - - - {t('common.delete')} - - -
- )} -
- ); -}; -export default ChunkCreatingModal; diff --git a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-creating-modal/tag-feature-item.tsx b/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-creating-modal/tag-feature-item.tsx deleted file mode 100644 index 64c192eb7..000000000 --- a/web/src/pages/chunk/parsed-result/knowledge-chunk/components/chunk-creating-modal/tag-feature-item.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import { - useFetchKnowledgeBaseConfiguration, - useFetchTagListByKnowledgeIds, -} from '@/hooks/knowledge-hooks'; -import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; -import { Button, Form, InputNumber, Select } from 'antd'; -import { useCallback, useEffect, useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import { FormListItem } from '../../utils'; - -const FieldKey = 'tag_feas'; - -export const TagFeatureItem = () => { - const form = Form.useFormInstance(); - const { t } = useTranslation(); - const { data: knowledgeConfiguration } = useFetchKnowledgeBaseConfiguration(); - - const { setKnowledgeIds, list } = useFetchTagListByKnowledgeIds(); - - const tagKnowledgeIds = useMemo(() => { - return knowledgeConfiguration?.parser_config?.tag_kb_ids ?? []; - }, [knowledgeConfiguration?.parser_config?.tag_kb_ids]); - - const options = useMemo(() => { - return list.map((x) => ({ - value: x[0], - label: x[0], - })); - }, [list]); - - const filterOptions = useCallback( - (index: number) => { - const tags: FormListItem[] = form.getFieldValue(FieldKey) ?? []; - - // Exclude it's own current data - const list = tags - .filter((x, idx) => x && index !== idx) - .map((x) => x.tag); - - // Exclude the selected data from other options from one's own options. - return options.filter((x) => !list.some((y) => x.value === y)); - }, - [form, options], - ); - - useEffect(() => { - setKnowledgeIds(tagKnowledgeIds); - }, [setKnowledgeIds, tagKnowledgeIds]); - - return ( - - - {(fields, { add, remove }) => ( - <> - {fields.map(({ key, name, ...restField }) => ( -
-
- - } - allowClear - onChange={handleInputChange} - onBlur={handleSearchBlur} - value={searchString} - /> - ) : ( -