Skip to content

Commit 1dcd439

Browse files
authored
feat: add file icon to table of FileManager #345 (#543)
### What problem does this PR solve? feat: add file icon to table of FileManager #345 fix: modify datasetDescription ### Type of change - [x] New Feature (non-breaking change which adds functionality)
1 parent 26003b5 commit 1dcd439

File tree

19 files changed

+318
-155
lines changed

19 files changed

+318
-155
lines changed
Lines changed: 18 additions & 0 deletions
Loading

web/src/base.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import isObject from 'lodash/isObject';
2+
import { DvaModel } from 'umi';
3+
import { BaseState } from './interfaces/common';
4+
5+
type State = Record<string, any>;
6+
type DvaModelKey<T> = keyof DvaModel<T>;
7+
8+
export const modelExtend = <T>(
9+
baseModel: Partial<DvaModel<any>>,
10+
extendModel: DvaModel<any>,
11+
): DvaModel<T> => {
12+
return Object.keys(extendModel).reduce<DvaModel<T>>((pre, cur) => {
13+
const baseValue = baseModel[cur as DvaModelKey<State>];
14+
const value = extendModel[cur as DvaModelKey<State>];
15+
16+
if (isObject(value) && isObject(baseValue) && typeof value !== 'string') {
17+
const key = cur as Exclude<DvaModelKey<State>, 'namespace'>;
18+
19+
pre[key] = {
20+
...baseValue,
21+
...value,
22+
} as any;
23+
} else {
24+
pre[cur as DvaModelKey<State>] = value as any;
25+
}
26+
27+
return pre;
28+
}, {} as DvaModel<T>);
29+
};
30+
31+
export const paginationModel: Partial<DvaModel<BaseState>> = {
32+
state: {
33+
searchString: '',
34+
pagination: {
35+
total: 0,
36+
current: 1,
37+
pageSize: 10,
38+
},
39+
},
40+
reducers: {
41+
setSearchString(state, { payload }) {
42+
return { ...state, searchString: payload };
43+
},
44+
setPagination(state, { payload }) {
45+
return { ...state, pagination: { ...state.pagination, ...payload } };
46+
},
47+
},
48+
};

web/src/hooks/fileManagerHooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ export const useUploadFile = () => {
103103
const dispatch = useDispatch();
104104

105105
const uploadFile = useCallback(
106-
(file: UploadFile, parentId: string, path: string) => {
106+
(fileList: UploadFile[], parentId: string) => {
107107
try {
108108
return dispatch<any>({
109109
type: 'fileManager/uploadFile',
110110
payload: {
111-
file,
111+
file: fileList,
112112
parentId,
113-
path,
113+
path: fileList.map((file) => (file as any).webkitRelativePath),
114114
},
115115
});
116116
} catch (errorInfo) {

web/src/hooks/knowledgeHook.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ export const useFetchKnowledgeBaseConfiguration = () => {
127127

128128
export const useFetchKnowledgeList = (
129129
shouldFilterListWithoutDocument: boolean = false,
130-
): { list: IKnowledge[]; loading: boolean } => {
130+
) => {
131131
const dispatch = useDispatch();
132132
const loading = useOneNamespaceEffectsLoading('knowledgeModel', ['getList']);
133133

134134
const knowledgeModel = useSelector((state: any) => state.knowledgeModel);
135135
const { data = [] } = knowledgeModel;
136-
const list = useMemo(() => {
136+
const list: IKnowledge[] = useMemo(() => {
137137
return shouldFilterListWithoutDocument
138138
? data.filter((x: IKnowledge) => x.chunk_num > 0)
139139
: data;
@@ -149,7 +149,7 @@ export const useFetchKnowledgeList = (
149149
fetchList();
150150
}, [fetchList]);
151151

152-
return { list, loading };
152+
return { list, loading, fetchList };
153153
};
154154

155155
export const useSelectFileThumbnails = () => {

web/src/hooks/logicHooks.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { LanguageTranslationMap } from '@/constants/common';
2+
import { Pagination } from '@/interfaces/common';
23
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
34
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
4-
import { useCallback, useState } from 'react';
5+
import { PaginationProps } from 'antd';
6+
import { useCallback, useMemo, useState } from 'react';
57
import { useTranslation } from 'react-i18next';
6-
import { useSetModalState } from './commonHooks';
8+
import { useDispatch } from 'umi';
9+
import { useSetModalState, useTranslate } from './commonHooks';
710
import { useSetDocumentParser } from './documentHooks';
811
import { useOneNamespaceEffectsLoading } from './storeHooks';
912
import { useSaveSetting } from './userSettingHook';
@@ -62,3 +65,51 @@ export const useChangeLanguage = () => {
6265

6366
return changeLanguage;
6467
};
68+
69+
export const useGetPagination = (
70+
total: number,
71+
page: number,
72+
pageSize: number,
73+
onPageChange: PaginationProps['onChange'],
74+
) => {
75+
const { t } = useTranslate('common');
76+
77+
const pagination: PaginationProps = useMemo(() => {
78+
return {
79+
showQuickJumper: true,
80+
total,
81+
showSizeChanger: true,
82+
current: page,
83+
pageSize: pageSize,
84+
pageSizeOptions: [1, 2, 10, 20, 50, 100],
85+
onChange: onPageChange,
86+
showTotal: (total) => `${t('total')} ${total}`,
87+
};
88+
}, [t, onPageChange, page, pageSize, total]);
89+
90+
return {
91+
pagination,
92+
};
93+
};
94+
95+
export const useSetPagination = (namespace: string) => {
96+
const dispatch = useDispatch();
97+
98+
const setPagination = useCallback(
99+
(pageNumber = 1, pageSize?: number) => {
100+
const pagination: Pagination = {
101+
current: pageNumber,
102+
} as Pagination;
103+
if (pageSize) {
104+
pagination.pageSize = pageSize;
105+
}
106+
dispatch({
107+
type: `${namespace}/setPagination`,
108+
payload: pagination,
109+
});
110+
},
111+
[dispatch, namespace],
112+
);
113+
114+
return setPagination;
115+
};

web/src/interfaces/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface Pagination {
22
current: number;
33
pageSize: number;
4+
total: number;
45
}
56

67
export interface BaseState {

web/src/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
namePlaceholder: 'Please input name!',
7171
doc: 'Docs',
7272
datasetDescription:
73-
"Hey, don't forget to adjust the chunk after adding the dataset! 😉",
73+
'😉 Questions and answers can only be answered after the parsing is successful.',
7474
addFile: 'Add file',
7575
searchFiles: 'Search your files',
7676
localFiles: 'Local files',

web/src/locales/zh-traditional.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default {
6969
name: '名稱',
7070
namePlaceholder: '請輸入名稱',
7171
doc: '文件',
72-
datasetDescription: '嘿,添加數據集後別忘了調整解析塊!😉',
72+
datasetDescription: '😉 解析成功後才能問答哦。',
7373
addFile: '新增文件',
7474
searchFiles: '搜索文件',
7575
localFiles: '本地文件',

web/src/locales/zh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default {
6969
name: '名称',
7070
namePlaceholder: '请输入名称',
7171
doc: '文档',
72-
datasetDescription: '嘿,添加数据集后别忘了调整解析块! 😉',
72+
datasetDescription: '😉 解析成功后才能问答哦。',
7373
addFile: '新增文件',
7474
searchFiles: '搜索文件',
7575
localFiles: '本地文件',

web/src/pages/file-manager/action-cell/index.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@ interface IProps {
1717
record: IFile;
1818
setCurrentRecord: (record: any) => void;
1919
showRenameModal: (record: IFile) => void;
20-
showConnectToKnowledgeModal: (ids: string[]) => void;
20+
showConnectToKnowledgeModal: (record: IFile) => void;
21+
setSelectedRowKeys(keys: string[]): void;
2122
}
2223

2324
const ActionCell = ({
2425
record,
2526
setCurrentRecord,
2627
showRenameModal,
2728
showConnectToKnowledgeModal,
29+
setSelectedRowKeys,
2830
}: IProps) => {
2931
const documentId = record.id;
3032
const beingUsed = false;
3133
const { t } = useTranslate('knowledgeDetails');
32-
const { handleRemoveFile } = useHandleDeleteFile([documentId]);
34+
const { handleRemoveFile } = useHandleDeleteFile(
35+
[documentId],
36+
setSelectedRowKeys,
37+
);
3338

3439
const onDownloadDocument = () => {
3540
downloadFile({
@@ -48,7 +53,7 @@ const ActionCell = ({
4853
};
4954

5055
const onShowConnectToKnowledgeModal = () => {
51-
showConnectToKnowledgeModal([documentId]);
56+
showConnectToKnowledgeModal(record);
5257
};
5358

5459
return (
@@ -79,14 +84,16 @@ const ActionCell = ({
7984
>
8085
<DeleteOutlined size={20} />
8186
</Button>
82-
<Button
83-
type="text"
84-
disabled={beingUsed}
85-
onClick={onDownloadDocument}
86-
className={styles.iconButton}
87-
>
88-
<DownloadOutlined size={20} />
89-
</Button>
87+
{record.type !== 'folder' && (
88+
<Button
89+
type="text"
90+
disabled={beingUsed}
91+
onClick={onDownloadDocument}
92+
className={styles.iconButton}
93+
>
94+
<DownloadOutlined size={20} />
95+
</Button>
96+
)}
9097
</Space>
9198
);
9299
};

0 commit comments

Comments
 (0)