feat: remove KnowledgeSearching and add knowledge configuration page and add a run button to the document (#64)

* feat: add a run button to the document

* feat: add knowledge configuration page

* feat: remove KnowledgeSearching
This commit is contained in:
balibabu
2024-02-18 18:18:20 +08:00
committed by GitHub
parent 53be70c7a9
commit f3d0ebd293
22 changed files with 495 additions and 687 deletions

View File

@@ -1,8 +1,5 @@
import { KnowledgeRouteKey } from '@/constants/knowledge';
import {
useDeleteDocumentById,
useKnowledgeBaseId,
} from '@/hooks/knowledgeHook';
import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
import { Pagination } from '@/interfaces/common';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { getOneNamespaceEffectsLoading } from '@/utils/storeUtil';
@@ -40,7 +37,6 @@ const KnowledgeFile = () => {
const effects = useSelector((state: any) => state.loading.effects);
const { data, total } = kFModel;
const knowledgeBaseId = useKnowledgeBaseId();
const { removeDocument } = useDeleteDocumentById();
const loading = getOneNamespaceEffectsLoading('kFModel', effects, [
'getKfList',
@@ -132,9 +128,7 @@ const KnowledgeFile = () => {
},
});
};
const onRmDocument = () => {
removeDocument(doc_id);
};
const showCEFModal = () => {
dispatch({
type: 'kFModel/updateState',
@@ -144,15 +138,6 @@ const KnowledgeFile = () => {
});
};
const showSegmentSetModal = () => {
dispatch({
type: 'kFModel/updateState',
payload: {
isShowSegmentSetModal: true,
},
});
};
const actionItems: MenuProps['items'] = useMemo(() => {
return [
{
@@ -185,31 +170,6 @@ const KnowledgeFile = () => {
},
];
}, []);
const chunkItems: MenuProps['items'] = [
{
key: '1',
label: (
<div>
<Button type="link" onClick={showSegmentSetModal}>
{' '}
</Button>
</div>
),
},
{
key: '2',
label: (
<div>
<Button type="link" onClick={onRmDocument}>
{' '}
Delete
</Button>
</div>
),
// disabled: true,
},
];
const toChunk = (id: string) => {
navigate(

View File

@@ -55,33 +55,23 @@ const model: DvaModel<KFModelState> = {
return { ...state, pagination: { ...state.pagination, ...payload } };
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
},
},
effects: {
*createKf({ payload = {} }, { call, put }) {
const { data, response } = yield call(kbService.createKb, payload);
const { retcode, data: res, retmsg } = data;
*createKf({ payload = {} }, { call }) {
const { data } = yield call(kbService.createKb, payload);
const { retcode } = data;
if (retcode === 0) {
message.success('创建成功!');
}
},
*updateKf({ payload = {} }, { call, put }) {
const { data, response } = yield call(kbService.updateKb, payload);
const { retcode, data: res, retmsg } = data;
*updateKf({ payload = {} }, { call }) {
const { data } = yield call(kbService.updateKb, payload);
const { retcode } = data;
if (retcode === 0) {
message.success('修改成功!');
}
},
*getKfDetail({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(kbService.get_kb_detail, payload);
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
// localStorage.setItem('userInfo',res.)
callback && callback(res);
}
*getKfDetail({ payload = {} }, { call }) {
const { data } = yield call(kbService.get_kb_detail, payload);
},
*getKfList({ payload = {} }, { call, put, select }) {
const state: KFModelState = yield select((state: any) => state.kFModel);
@@ -119,11 +109,11 @@ const model: DvaModel<KFModelState> = {
{ type: 'poll', delay: 5000 }, // TODO: Provide type support for this effect
],
*updateDocumentStatus({ payload = {} }, { call, put }) {
const { data, response } = yield call(
const { data } = yield call(
kbService.document_change_status,
pick(payload, ['doc_id', 'status']),
);
const { retcode, data: res, retmsg } = data;
const { retcode } = data;
if (retcode === 0) {
message.success('修改成功!');
put({
@@ -133,10 +123,10 @@ const model: DvaModel<KFModelState> = {
}
},
*document_rm({ payload = {} }, { call, put }) {
const { data, response } = yield call(kbService.document_rm, {
const { data } = yield call(kbService.document_rm, {
doc_id: payload.doc_id,
});
const { retcode, data: res, retmsg } = data;
const { retcode } = data;
if (retcode === 0) {
message.success('删除成功!');
yield put({
@@ -151,7 +141,7 @@ const model: DvaModel<KFModelState> = {
kbService.document_rename,
omit(payload, ['kb_id']),
);
const { retcode, data: res, retmsg } = data;
const { retcode } = data;
if (retcode === 0) {
message.success('rename success');
yield put({
@@ -168,7 +158,7 @@ const model: DvaModel<KFModelState> = {
},
*document_create({ payload = {} }, { call, put }) {
const { data } = yield call(kbService.document_create, payload);
const { retcode, data: res } = data;
const { retcode } = data;
if (retcode === 0) {
put({
type: 'kFModel/updateState',
@@ -181,19 +171,25 @@ const model: DvaModel<KFModelState> = {
return retcode;
},
*document_run({ payload = {} }, { call, put }) {
const { data } = yield call(kbService.document_run, payload);
const { data } = yield call(
kbService.document_run,
omit(payload, ['knowledgeBaseId']),
);
const { retcode } = data;
if (retcode === 0) {
message.success('Run successfully ');
if (payload.knowledgeBaseId) {
yield put({
type: 'getKfList',
payload: { kb_id: payload.knowledgeBaseId },
});
}
message.success('Operation successfully ');
}
return retcode;
},
*document_change_parser({ payload = {} }, { call, put }) {
const { data, response } = yield call(
kbService.document_change_parser,
payload,
);
const { retcode, data: res, retmsg } = data;
const { data } = yield call(kbService.document_change_parser, payload);
const { retcode } = data;
if (retcode === 0) {
put({
type: 'updateState',

View File

@@ -1,3 +1,12 @@
.popover-content {
width: 300px;
}
.operationIcon {
text-align: center;
margin-right: 20%;
width: 20px;
&:hover {
cursor: pointer;
}
}

View File

@@ -1,9 +1,21 @@
import { ReactComponent as RefreshIcon } from '@/assets/svg/refresh.svg';
import { ReactComponent as RunIcon } from '@/assets/svg/run.svg';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { Badge, DescriptionsProps, Flex, Popover, Space, Tag } from 'antd';
import { RunningStatus, RunningStatusMap } from '../constant';
import { CloseCircleOutlined } from '@ant-design/icons';
import { useDispatch } from 'umi';
import styles from './index.less';
const iconMap = {
[RunningStatus.UNSTART]: RunIcon,
[RunningStatus.RUNNING]: CloseCircleOutlined,
[RunningStatus.CANCEL]: RefreshIcon,
[RunningStatus.DONE]: RefreshIcon,
[RunningStatus.FAIL]: RefreshIcon,
};
interface IProps {
record: IKnowledgeFile;
}
@@ -31,7 +43,7 @@ const PopoverContent = ({ record }: IProps) => {
<Flex vertical className={styles['popover-content']}>
{items.map((x) => {
return (
<div>
<div key={x.key}>
<b>{x.label}:</b>
<p>{x.children}</p>
</div>
@@ -42,27 +54,46 @@ const PopoverContent = ({ record }: IProps) => {
};
export const ParsingStatusCell = ({ record }: IProps) => {
const dispatch = useDispatch();
const text = record.run;
const runningStatus = RunningStatusMap[text];
const isRunning = text === RunningStatus.RUNNING;
const OperationIcon = iconMap[text];
const handleOperationIconClick = () => {
dispatch({
type: 'kFModel/document_run',
payload: {
doc_ids: [record.id],
run: isRunning ? 2 : 1,
knowledgeBaseId: record.kb_id,
},
});
};
return (
<Popover
content={isRunning && <PopoverContent record={record}></PopoverContent>}
>
<Tag color={runningStatus.color}>
{isRunning ? (
<Space>
<Badge color={runningStatus.color} />
{runningStatus.label}
<span>{record.progress * 100}%</span>
</Space>
) : (
runningStatus.label
)}
</Tag>
</Popover>
<Flex justify={'space-between'}>
<Popover
content={isRunning && <PopoverContent record={record}></PopoverContent>}
>
<Tag color={runningStatus.color}>
{isRunning ? (
<Space>
<Badge color={runningStatus.color} />
{runningStatus.label}
<span>{(record.progress * 100).toFixed(2)}%</span>
</Space>
) : (
runningStatus.label
)}
</Tag>
</Popover>
<div onClick={handleOperationIconClick} className={styles.operationIcon}>
<OperationIcon />
</div>
</Flex>
);
};