Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export default {
search: '搜尋',
all: '所有',
enabled: '啟用',
disabled: '禁用的',
disabled: '禁用',
keyword: '關鍵詞',
function: '函數',
chunkMessage: '請輸入值!',
Expand Down
2 changes: 1 addition & 1 deletion web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export default {
search: '搜索',
all: '所有',
enabled: '启用',
disabled: '禁用的',
disabled: '禁用',
keyword: '关键词',
function: '函数',
chunkMessage: '请输入值!',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import EditTag from '@/components/edit-tag';
import { useFetchChunk } from '@/hooks/chunk-hooks';
import { IModalProps } from '@/interfaces/common';
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 { useTranslation } from 'react-i18next';
import { useDeleteChunkByIds } from '../../hooks';
Expand Down Expand Up @@ -31,9 +31,14 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({

useEffect(() => {
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 });
setKeywords(important_kwd);
setChecked(available_int === 1);
}

if (!chunkId) {
Expand All @@ -48,6 +53,7 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
onOk?.({
content: values.content,
keywords, // keywords
available_int: checked ? 1 : 0, // available_int
});
} catch (errorInfo) {
console.log('Failed:', errorInfo);
Expand Down Expand Up @@ -82,16 +88,19 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
</Form.Item>
</Form>
<section>
<p>{t('chunk.keyword')} *</p>
<p className="mb-2">{t('chunk.keyword')} *</p>
<EditTag tags={keywords} setTags={setKeywords} />
</section>
{chunkId && (
<section>
<Divider></Divider>
<Space size={'large'}>
<Checkbox onChange={handleCheck} checked={checked}>
{t('chunk.enabled')}
</Checkbox>
<Switch
checkedChildren={t('chunk.enabled')}
unCheckedChildren={t('chunk.disabled')}
onChange={handleCheck}
checked={checked}
/>

<span onClick={handleRemove}>
<DeleteOutlined /> {t('common.delete')}
Expand Down
11 changes: 10 additions & 1 deletion web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,21 @@ export const useUpdateChunk = () => {
const { documentId } = useGetKnowledgeSearchParams();

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({
content_with_weight: content,
doc_id: documentId,
chunk_id: chunkId,
important_kwd: keywords, // keywords
available_int,
});

if (code === 0) {
Expand Down