Fix: Clicking the checkbox of the pop-up window for editing chunk is invalid #3726 (#3727)

### What problem does this PR solve?

Fix: Clicking the checkbox of the pop-up window for editing chunk is
invalid #3726

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu 2024-11-28 20:08:06 +08:00 committed by GitHub
parent 80af3cc2d4
commit a3e0ac9c0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 9 deletions

View File

@ -296,7 +296,7 @@ export default {
search: '搜尋', search: '搜尋',
all: '所有', all: '所有',
enabled: '啟用', enabled: '啟用',
disabled: '禁用', disabled: '禁用',
keyword: '關鍵詞', keyword: '關鍵詞',
function: '函數', function: '函數',
chunkMessage: '請輸入值!', chunkMessage: '請輸入值!',

View File

@ -313,7 +313,7 @@ export default {
search: '搜索', search: '搜索',
all: '所有', all: '所有',
enabled: '启用', enabled: '启用',
disabled: '禁用', disabled: '禁用',
keyword: '关键词', keyword: '关键词',
function: '函数', function: '函数',
chunkMessage: '请输入值!', chunkMessage: '请输入值!',

View File

@ -2,7 +2,7 @@ import EditTag from '@/components/edit-tag';
import { useFetchChunk } from '@/hooks/chunk-hooks'; import { useFetchChunk } from '@/hooks/chunk-hooks';
import { IModalProps } from '@/interfaces/common'; import { IModalProps } from '@/interfaces/common';
import { DeleteOutlined } from '@ant-design/icons'; import { DeleteOutlined } from '@ant-design/icons';
import { Checkbox, Divider, Form, Input, Modal, Space } from 'antd'; import { Divider, Form, Input, Modal, Space, Switch } from 'antd';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useDeleteChunkByIds } from '../../hooks'; import { useDeleteChunkByIds } from '../../hooks';
@ -31,9 +31,14 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
useEffect(() => { useEffect(() => {
if (data?.code === 0) { if (data?.code === 0) {
const { content_with_weight, important_kwd = [] } = data.data; const {
content_with_weight,
important_kwd = [],
available_int,
} = data.data;
form.setFieldsValue({ content: content_with_weight }); form.setFieldsValue({ content: content_with_weight });
setKeywords(important_kwd); setKeywords(important_kwd);
setChecked(available_int === 1);
} }
if (!chunkId) { if (!chunkId) {
@ -48,6 +53,7 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
onOk?.({ onOk?.({
content: values.content, content: values.content,
keywords, // keywords keywords, // keywords
available_int: checked ? 1 : 0, // available_int
}); });
} catch (errorInfo) { } catch (errorInfo) {
console.log('Failed:', errorInfo); console.log('Failed:', errorInfo);
@ -82,16 +88,19 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
</Form.Item> </Form.Item>
</Form> </Form>
<section> <section>
<p>{t('chunk.keyword')} *</p> <p className="mb-2">{t('chunk.keyword')} *</p>
<EditTag tags={keywords} setTags={setKeywords} /> <EditTag tags={keywords} setTags={setKeywords} />
</section> </section>
{chunkId && ( {chunkId && (
<section> <section>
<Divider></Divider> <Divider></Divider>
<Space size={'large'}> <Space size={'large'}>
<Checkbox onChange={handleCheck} checked={checked}> <Switch
{t('chunk.enabled')} checkedChildren={t('chunk.enabled')}
</Checkbox> unCheckedChildren={t('chunk.disabled')}
onChange={handleCheck}
checked={checked}
/>
<span onClick={handleRemove}> <span onClick={handleRemove}>
<DeleteOutlined /> {t('common.delete')} <DeleteOutlined /> {t('common.delete')}

View File

@ -95,12 +95,21 @@ export const useUpdateChunk = () => {
const { documentId } = useGetKnowledgeSearchParams(); const { documentId } = useGetKnowledgeSearchParams();
const onChunkUpdatingOk = useCallback( const onChunkUpdatingOk = useCallback(
async ({ content, keywords }: { content: string; keywords: string }) => { async ({
content,
keywords,
available_int,
}: {
content: string;
keywords: string;
available_int: number;
}) => {
const code = await createChunk({ const code = await createChunk({
content_with_weight: content, content_with_weight: content,
doc_id: documentId, doc_id: documentId,
chunk_id: chunkId, chunk_id: chunkId,
important_kwd: keywords, // keywords important_kwd: keywords, // keywords
available_int,
}); });
if (code === 0) { if (code === 0) {