Skip to content

Commit

Permalink
fix: remove unused libraries #1306 (#1649)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
fix: remove unused libraries  #1306


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
cike8899 authored Jul 23, 2024
1 parent 792a1a9 commit 022afbb
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 147 deletions.
83 changes: 0 additions & 83 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
"lodash": "^4.17.21",
"mammoth": "^1.7.2",
"rc-tween-one": "^3.0.6",
"react-chat-elements": "^12.0.13",
"react-copy-to-clipboard": "^5.1.0",
"react-i18next": "^14.0.0",
"react-infinite-scroll-component": "^6.1.0",
"react-markdown": "^9.0.1",
"react-pdf-highlighter": "^6.1.0",
"react-string-replace": "^1.1.1",
Expand Down
39 changes: 33 additions & 6 deletions web/src/hooks/file-manager-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
IFileListRequestBody,
} from '@/interfaces/request/file-manager';
import fileManagerService from '@/services/file-manager-service';
import { useQuery } from '@tanstack/react-query';
import { useMutation, useQuery } from '@tanstack/react-query';
import { PaginationProps, UploadFile } from 'antd';
import React, { useCallback } from 'react';
import { useDispatch, useSearchParams, useSelector } from 'umi';
import { useGetNextPagination, useHandleSearchChange } from './logic-hooks';
import { useSetPaginationParams } from './route-hook';

export const useGetFolderId = () => {
const [searchParams] = useSearchParams();
Expand Down Expand Up @@ -48,13 +49,19 @@ export const useFetchNextFileList = (): ResponseType<any> & IListResult => {
const { data } = useQuery({
queryKey: [
'fetchFileList',
id,
pagination.current,
pagination.pageSize,
searchString,
// pagination.current,
// id,
// pagination.pageSize,
// searchString,
{
id,
searchString,
...pagination,
},
],
initialData: {},
queryFn: async () => {
queryFn: async (params: any) => {
console.info(params);
const { data } = await fileManagerService.listFile({
parent_id: id,
keywords: searchString,
Expand Down Expand Up @@ -99,6 +106,26 @@ export const useRemoveFile = () => {
return removeFile;
};

export const useDeleteFile = () => {
const { setPaginationParams } = useSetPaginationParams();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['deleteFile'],
mutationFn: async (params: { fileIds: string[]; parentId: string }) => {
const { data } = await fileManagerService.removeFile(params);
if (data.retcode === 0) {
setPaginationParams(1);
}
return data?.data ?? {};
},
});

return { data, loading, deleteFile: mutateAsync };
};

export const useRenameFile = () => {
const dispatch = useDispatch();

Expand Down
18 changes: 10 additions & 8 deletions web/src/hooks/logic-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useDispatch } from 'umi';
import { useSetModalState, useTranslate } from './common-hooks';
import { useSetDocumentParser } from './document-hooks';
import { useFetchLlmList } from './llm-hooks';
import { useSetPaginationParams } from './route-hook';
import { useOneNamespaceEffectsLoading } from './store-hooks';
import {
useFetchTenantInfo,
Expand Down Expand Up @@ -101,23 +102,24 @@ export const useChangeLanguage = () => {

export const useGetNextPagination = () => {
const { t } = useTranslate('common');
const [{ page, pageSize }, setPagination] = useState({
page: 1,
pageSize: 10,
});
const {
setPaginationParams,
page,
size: pageSize,
} = useSetPaginationParams();

const onPageChange: PaginationProps['onChange'] = useCallback(
(pageNumber: number, pageSize: number) => {
setPagination({ page: pageNumber, pageSize });
setPaginationParams(pageNumber, pageSize);
},
[setPagination],
[setPaginationParams],
);

const setCurrentPagination = useCallback(
(pagination: { page: number; pageSize?: number }) => {
setPagination((p) => ({ ...p, ...pagination }));
setPaginationParams(pagination.page, pagination.pageSize);
},
[setPagination],
[setPaginationParams],
);

const pagination: PaginationProps = useMemo(() => {
Expand Down
34 changes: 34 additions & 0 deletions web/src/hooks/route-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,37 @@ export const useNavigateToDataset = () => {
navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${knowledgeId}`);
}, [knowledgeId, navigate]);
};

export const useGetPaginationParams = () => {
const [currentQueryParameters] = useSearchParams();

return {
page: currentQueryParameters.get('page') || 1,
size: currentQueryParameters.get('size') || 10,
};
};

export const useSetPaginationParams = () => {
const [queryParameters, setSearchParams] = useSearchParams();
// const newQueryParameters: URLSearchParams = useMemo(
// () => new URLSearchParams(queryParameters.toString()),
// [queryParameters],
// );

const setPaginationParams = useCallback(
(page: number = 1, pageSize?: number) => {
queryParameters.set('page', page.toString());
if (pageSize) {
queryParameters.set('size', pageSize.toString());
}
setSearchParams(queryParameters);
},
[setSearchParams, queryParameters],
);

return {
setPaginationParams,
page: Number(queryParameters.get('page')) || 1,
size: Number(queryParameters.get('size')) || 10,
};
};
45 changes: 0 additions & 45 deletions web/src/pages/chat/message-box.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions web/src/pages/file-manager/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useSetModalState, useShowDeleteConfirm } from '@/hooks/common-hooks';
import {
useConnectToKnowledge,
useCreateFolder,
useDeleteFile,
useFetchFileList,
useFetchParentFolderList,
useRemoveFile,
useRenameFile,
useSelectFileList,
useSelectParentFolderList,
Expand Down Expand Up @@ -215,14 +215,14 @@ export const useHandleDeleteFile = (
fileIds: string[],
setSelectedRowKeys: (keys: string[]) => void,
) => {
const removeDocument = useRemoveFile();
const { deleteFile: removeDocument } = useDeleteFile();
const showDeleteConfirm = useShowDeleteConfirm();
const parentId = useGetFolderId();

const handleRemoveFile = () => {
showDeleteConfirm({
onOk: async () => {
const retcode = await removeDocument(fileIds, parentId);
const retcode = await removeDocument({ fileIds, parentId });
if (retcode === 0) {
setSelectedRowKeys([]);
}
Expand Down

0 comments on commit 022afbb

Please sign in to comment.