feat: set chunk to available state and select all chunk (#57)

* feat: set chunk to available state

* feat: select all chunk
This commit is contained in:
balibabu
2024-02-06 18:45:20 +08:00
committed by GitHub
parent eb381963b3
commit 97d4387982
15 changed files with 471 additions and 259 deletions

View File

@ -1,13 +1,19 @@
import { BaseState } from '@/interfaces/common';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import kbService from '@/services/kbService';
import { message } from 'antd';
// import { delay } from '@/utils/storeUtil';
import { DvaModel } from 'umi';
export interface ChunkModelState {
export interface ChunkModelState extends BaseState {
data: any[];
total: number;
isShowCreateModal: boolean;
chunk_id: string;
doc_id: string;
chunkInfo: any;
documentInfo: Partial<IKnowledgeFile>;
available?: number;
}
const model: DvaModel<ChunkModelState> = {
@ -19,6 +25,13 @@ const model: DvaModel<ChunkModelState> = {
chunk_id: '',
doc_id: '',
chunkInfo: {},
documentInfo: {},
pagination: {
current: 1,
pageSize: 10,
},
searchString: '',
available: undefined, // set to undefined to select all
},
reducers: {
updateState(state, { payload }) {
@ -27,33 +40,56 @@ const model: DvaModel<ChunkModelState> = {
...payload,
};
},
setAvailable(state, { payload }) {
return { ...state, available: payload };
},
setSearchString(state, { payload }) {
return { ...state, searchString: payload };
},
setPagination(state, { payload }) {
return { ...state, pagination: { ...state.pagination, ...payload } };
},
resetFilter(state, { payload }) {
return {
...state,
pagination: {
current: 1,
pageSize: 10,
},
searchString: '',
available: undefined,
};
},
},
// subscriptions: {
// setup({ dispatch, history }) {
// history.listen(location => {
// console.log(location)
// });
// }
// },
effects: {
*chunk_list({ payload = {} }, { call, put }) {
const { data, response } = yield call(kbService.chunk_list, payload);
const { retcode, data: res, retmsg } = data;
*chunk_list({ payload = {} }, { call, put, select }) {
const { available, searchString, pagination }: ChunkModelState =
yield select((state: any) => state.chunkModel);
const { data } = yield call(kbService.chunk_list, {
...payload,
available_int: available,
keywords: searchString,
page: pagination.current,
size: pagination.pageSize,
});
const { retcode, data: res } = data;
if (retcode === 0) {
console.log(res);
yield put({
type: 'updateState',
payload: {
data: res.chunks,
total: res.total,
documentInfo: res.doc,
},
});
}
},
*switch_chunk({ payload = {} }, { call, put }) {
const { data, response } = yield call(kbService.switch_chunk, payload);
const { retcode, data: res, retmsg } = data;
const { data } = yield call(kbService.switch_chunk, payload);
const { retcode } = data;
if (retcode === 0) {
message.success('Modified successfully ');
}
return retcode;
},
*rm_chunk({ payload = {} }, { call, put }) {