balibabu
commited on
Commit
·
bb69456
1
Parent(s):
77dbe3e
fix: after logging out and entering the knowledge base page again, the data before still exists #1306 (#1597)
Browse files### What problem does this PR solve?
fix: after logging out and entering the knowledge base page again, the
data before still exists #1306
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- web/package-lock.json +33 -7
- web/package.json +1 -0
- web/src/app.tsx +5 -4
- web/src/components/knowledge-base-item.tsx +2 -2
- web/src/hooks/flow-hooks.ts +1 -0
- web/src/hooks/knowledge-hooks.ts +55 -38
- web/src/locales/en.ts +1 -1
- web/src/pages/add-knowledge/components/knowledge-setting/model.ts +0 -8
- web/src/pages/file-manager/connect-to-knowledge-modal/index.tsx +3 -4
- web/src/pages/knowledge/hooks.ts +33 -5
- web/src/pages/knowledge/index.tsx +25 -25
- web/src/pages/knowledge/knowledge-card/index.tsx +5 -8
- web/src/pages/knowledge/knowledge-creating-modal/index.tsx +11 -36
web/package-lock.json
CHANGED
@@ -11,6 +11,7 @@
|
|
11 |
"@ant-design/pro-layout": "^7.17.16",
|
12 |
"@js-preview/excel": "^1.7.8",
|
13 |
"@tanstack/react-query": "^5.40.0",
|
|
|
14 |
"ahooks": "^3.7.10",
|
15 |
"antd": "^5.12.7",
|
16 |
"axios": "^1.6.3",
|
@@ -4257,12 +4258,21 @@
|
|
4257 |
"integrity": "sha512-DJSilV5+ytBP1FbFcEJovv4rnnm/CokuVvrBEtW/Va9DvuJ3HksbXUJEpI0aV1KtuL4ZoO9AVE6PyNLzF7tLeA==",
|
4258 |
"dev": true
|
4259 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4260 |
"node_modules/@tanstack/react-query": {
|
4261 |
-
"version": "5.
|
4262 |
-
"resolved": "https://registry.npmmirror.com/@tanstack/react-query/-/react-query-5.
|
4263 |
-
"integrity": "sha512-
|
4264 |
"dependencies": {
|
4265 |
-
"@tanstack/query-core": "5.
|
4266 |
},
|
4267 |
"funding": {
|
4268 |
"type": "github",
|
@@ -4272,10 +4282,26 @@
|
|
4272 |
"react": "^18.0.0"
|
4273 |
}
|
4274 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4275 |
"node_modules/@tanstack/react-query/node_modules/@tanstack/query-core": {
|
4276 |
-
"version": "5.
|
4277 |
-
"resolved": "https://registry.npmmirror.com/@tanstack/query-core/-/query-core-5.
|
4278 |
-
"integrity": "sha512-
|
4279 |
"funding": {
|
4280 |
"type": "github",
|
4281 |
"url": "https://github.com/sponsors/tannerlinsley"
|
|
|
11 |
"@ant-design/pro-layout": "^7.17.16",
|
12 |
"@js-preview/excel": "^1.7.8",
|
13 |
"@tanstack/react-query": "^5.40.0",
|
14 |
+
"@tanstack/react-query-devtools": "^5.51.5",
|
15 |
"ahooks": "^3.7.10",
|
16 |
"antd": "^5.12.7",
|
17 |
"axios": "^1.6.3",
|
|
|
4258 |
"integrity": "sha512-DJSilV5+ytBP1FbFcEJovv4rnnm/CokuVvrBEtW/Va9DvuJ3HksbXUJEpI0aV1KtuL4ZoO9AVE6PyNLzF7tLeA==",
|
4259 |
"dev": true
|
4260 |
},
|
4261 |
+
"node_modules/@tanstack/query-devtools": {
|
4262 |
+
"version": "5.51.1",
|
4263 |
+
"resolved": "https://registry.npmmirror.com/@tanstack/query-devtools/-/query-devtools-5.51.1.tgz",
|
4264 |
+
"integrity": "sha512-rehG0WmL3EXER6MAI2uHQia/n0b5c3ZROohpYm7u3G7yg4q+HsfQy6nuAo6uy40NzHUe3FmnfWCZQ0Vb/3lE6g==",
|
4265 |
+
"funding": {
|
4266 |
+
"type": "github",
|
4267 |
+
"url": "https://github.com/sponsors/tannerlinsley"
|
4268 |
+
}
|
4269 |
+
},
|
4270 |
"node_modules/@tanstack/react-query": {
|
4271 |
+
"version": "5.51.8",
|
4272 |
+
"resolved": "https://registry.npmmirror.com/@tanstack/react-query/-/react-query-5.51.8.tgz",
|
4273 |
+
"integrity": "sha512-MQ6LhvOabxtNfxv47IkbI6cQy5PUte2CWSv8GVBCoTLE3iBjw22Nkv2171m+vNkveL+udH7n+R7WDal6I95RCA==",
|
4274 |
"dependencies": {
|
4275 |
+
"@tanstack/query-core": "5.51.8"
|
4276 |
},
|
4277 |
"funding": {
|
4278 |
"type": "github",
|
|
|
4282 |
"react": "^18.0.0"
|
4283 |
}
|
4284 |
},
|
4285 |
+
"node_modules/@tanstack/react-query-devtools": {
|
4286 |
+
"version": "5.51.5",
|
4287 |
+
"resolved": "https://registry.npmmirror.com/@tanstack/react-query-devtools/-/react-query-devtools-5.51.5.tgz",
|
4288 |
+
"integrity": "sha512-Gu2jSgFuCGnD8tGCJpwpkmrQ3F2j13dgxjKRY+yGN7aN5W7Wxo9jEUctlKotGvXDn/iFE/uscTRsE1Au7wBWPQ==",
|
4289 |
+
"dependencies": {
|
4290 |
+
"@tanstack/query-devtools": "5.51.1"
|
4291 |
+
},
|
4292 |
+
"funding": {
|
4293 |
+
"type": "github",
|
4294 |
+
"url": "https://github.com/sponsors/tannerlinsley"
|
4295 |
+
},
|
4296 |
+
"peerDependencies": {
|
4297 |
+
"@tanstack/react-query": "^5.51.5",
|
4298 |
+
"react": "^18 || ^19"
|
4299 |
+
}
|
4300 |
+
},
|
4301 |
"node_modules/@tanstack/react-query/node_modules/@tanstack/query-core": {
|
4302 |
+
"version": "5.51.8",
|
4303 |
+
"resolved": "https://registry.npmmirror.com/@tanstack/query-core/-/query-core-5.51.8.tgz",
|
4304 |
+
"integrity": "sha512-Gp9UmHMgewLrz9m7egdpPZDywftgXSSvcRRr2UKA1r0w/OJ0CrS556sj4bMNQs2m5hQOsj/7o8lSoGr5ce1D6Q==",
|
4305 |
"funding": {
|
4306 |
"type": "github",
|
4307 |
"url": "https://github.com/sponsors/tannerlinsley"
|
web/package.json
CHANGED
@@ -22,6 +22,7 @@
|
|
22 |
"@ant-design/pro-layout": "^7.17.16",
|
23 |
"@js-preview/excel": "^1.7.8",
|
24 |
"@tanstack/react-query": "^5.40.0",
|
|
|
25 |
"ahooks": "^3.7.10",
|
26 |
"antd": "^5.12.7",
|
27 |
"axios": "^1.6.3",
|
|
|
22 |
"@ant-design/pro-layout": "^7.17.16",
|
23 |
"@js-preview/excel": "^1.7.8",
|
24 |
"@tanstack/react-query": "^5.40.0",
|
25 |
+
"@tanstack/react-query-devtools": "^5.51.5",
|
26 |
"ahooks": "^3.7.10",
|
27 |
"antd": "^5.12.7",
|
28 |
"axios": "^1.6.3",
|
web/src/app.tsx
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import i18n from '@/locales/config';
|
|
|
|
|
2 |
import { App, ConfigProvider, ConfigProviderProps } from 'antd';
|
3 |
import enUS from 'antd/locale/en_US';
|
4 |
import zhCN from 'antd/locale/zh_CN';
|
5 |
import zh_HK from 'antd/locale/zh_HK';
|
6 |
-
import React, { ReactNode, useEffect, useState } from 'react';
|
7 |
-
import storage from './utils/authorizationUtil';
|
8 |
-
|
9 |
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
10 |
import dayjs from 'dayjs';
|
11 |
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
12 |
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
@@ -14,6 +12,8 @@ import localeData from 'dayjs/plugin/localeData';
|
|
14 |
import weekOfYear from 'dayjs/plugin/weekOfYear';
|
15 |
import weekYear from 'dayjs/plugin/weekYear';
|
16 |
import weekday from 'dayjs/plugin/weekday';
|
|
|
|
|
17 |
|
18 |
dayjs.extend(customParseFormat);
|
19 |
dayjs.extend(advancedFormat);
|
@@ -63,6 +63,7 @@ const RootProvider = ({ children }: React.PropsWithChildren) => {
|
|
63 |
>
|
64 |
<App> {children}</App>
|
65 |
</ConfigProvider>
|
|
|
66 |
</QueryClientProvider>
|
67 |
);
|
68 |
};
|
|
|
1 |
import i18n from '@/locales/config';
|
2 |
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
3 |
+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
4 |
import { App, ConfigProvider, ConfigProviderProps } from 'antd';
|
5 |
import enUS from 'antd/locale/en_US';
|
6 |
import zhCN from 'antd/locale/zh_CN';
|
7 |
import zh_HK from 'antd/locale/zh_HK';
|
|
|
|
|
|
|
|
|
8 |
import dayjs from 'dayjs';
|
9 |
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
10 |
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
|
12 |
import weekOfYear from 'dayjs/plugin/weekOfYear';
|
13 |
import weekYear from 'dayjs/plugin/weekYear';
|
14 |
import weekday from 'dayjs/plugin/weekday';
|
15 |
+
import React, { ReactNode, useEffect, useState } from 'react';
|
16 |
+
import storage from './utils/authorizationUtil';
|
17 |
|
18 |
dayjs.extend(customParseFormat);
|
19 |
dayjs.extend(advancedFormat);
|
|
|
63 |
>
|
64 |
<App> {children}</App>
|
65 |
</ConfigProvider>
|
66 |
+
<ReactQueryDevtools buttonPosition={'top-left'} />
|
67 |
</QueryClientProvider>
|
68 |
);
|
69 |
};
|
web/src/components/knowledge-base-item.tsx
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import { useTranslate } from '@/hooks/common-hooks';
|
2 |
-
import {
|
3 |
import { Form, Select } from 'antd';
|
4 |
|
5 |
const KnowledgeBaseItem = () => {
|
6 |
const { t } = useTranslate('chat');
|
7 |
|
8 |
-
const { list: knowledgeList } =
|
9 |
|
10 |
const knowledgeOptions = knowledgeList.map((x) => ({
|
11 |
label: x.name,
|
|
|
1 |
import { useTranslate } from '@/hooks/common-hooks';
|
2 |
+
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
3 |
import { Form, Select } from 'antd';
|
4 |
|
5 |
const KnowledgeBaseItem = () => {
|
6 |
const { t } = useTranslate('chat');
|
7 |
|
8 |
+
const { list: knowledgeList } = useNextFetchKnowledgeList(true);
|
9 |
|
10 |
const knowledgeOptions = knowledgeList.map((x) => ({
|
11 |
label: x.name,
|
web/src/hooks/flow-hooks.ts
CHANGED
@@ -96,6 +96,7 @@ export const useFetchFlow = (): {
|
|
96 |
refetchOnReconnect: false,
|
97 |
refetchOnMount: false,
|
98 |
refetchOnWindowFocus: false,
|
|
|
99 |
queryFn: async () => {
|
100 |
const { data } = await flowService.getCanvas({}, id);
|
101 |
|
|
|
96 |
refetchOnReconnect: false,
|
97 |
refetchOnMount: false,
|
98 |
refetchOnWindowFocus: false,
|
99 |
+
gcTime: 0,
|
100 |
queryFn: async () => {
|
101 |
const { data } = await flowService.getCanvas({}, id);
|
102 |
|
web/src/hooks/knowledge-hooks.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import { useShowDeleteConfirm } from '@/hooks/common-hooks';
|
2 |
import { IKnowledge } from '@/interfaces/database/knowledge';
|
|
|
3 |
import kbService from '@/services/knowledge-service';
|
4 |
-
import { useQuery } from '@tanstack/react-query';
|
5 |
-
import {
|
|
|
6 |
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
7 |
import { useGetKnowledgeSearchParams } from './route-hook';
|
8 |
-
import { useOneNamespaceEffectsLoading } from './store-hooks';
|
9 |
|
10 |
export const useKnowledgeBaseId = (): string => {
|
11 |
const [searchParams] = useSearchParams();
|
@@ -127,54 +128,70 @@ export const useFetchKnowledgeBaseConfiguration = () => {
|
|
127 |
}, [fetchKnowledgeBaseConfiguration]);
|
128 |
};
|
129 |
|
130 |
-
export const
|
131 |
-
const knowledgeModel = useSelector((state) => state.knowledgeModel);
|
132 |
-
const { data = [] } = knowledgeModel;
|
133 |
-
return data;
|
134 |
-
};
|
135 |
-
|
136 |
-
export const useFetchKnowledgeList = (
|
137 |
shouldFilterListWithoutDocument: boolean = false,
|
138 |
-
)
|
139 |
-
|
140 |
-
const loading = useOneNamespaceEffectsLoading('knowledgeModel', ['getList']);
|
141 |
-
|
142 |
-
const knowledgeModel = useSelector((state) => state.knowledgeModel);
|
143 |
-
const { data = [] } = knowledgeModel;
|
144 |
-
const list: IKnowledge[] = useMemo(() => {
|
145 |
-
return shouldFilterListWithoutDocument
|
146 |
-
? data.filter((x: IKnowledge) => x.chunk_num > 0)
|
147 |
-
: data;
|
148 |
-
}, [data, shouldFilterListWithoutDocument]);
|
149 |
-
|
150 |
-
const fetchList = useCallback(() => {
|
151 |
-
dispatch({
|
152 |
-
type: 'knowledgeModel/getList',
|
153 |
-
});
|
154 |
-
}, [dispatch]);
|
155 |
-
|
156 |
-
useEffect(() => {
|
157 |
-
fetchList();
|
158 |
-
}, [fetchList]);
|
159 |
-
|
160 |
-
return { list, loading, fetchList };
|
161 |
-
};
|
162 |
-
|
163 |
-
export const useNextFetchKnowledgeList = (): {
|
164 |
-
data: any[];
|
165 |
loading: boolean;
|
166 |
} => {
|
167 |
const { data, isFetching: loading } = useQuery({
|
168 |
queryKey: ['fetchKnowledgeList'],
|
169 |
initialData: [],
|
|
|
170 |
queryFn: async () => {
|
171 |
const { data } = await kbService.getList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
return data?.data ?? [];
|
174 |
},
|
175 |
});
|
176 |
|
177 |
-
return { data, loading };
|
178 |
};
|
179 |
|
180 |
export const useSelectFileThumbnails = () => {
|
|
|
1 |
import { useShowDeleteConfirm } from '@/hooks/common-hooks';
|
2 |
import { IKnowledge } from '@/interfaces/database/knowledge';
|
3 |
+
import i18n from '@/locales/config';
|
4 |
import kbService from '@/services/knowledge-service';
|
5 |
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
6 |
+
import { message } from 'antd';
|
7 |
+
import { useCallback, useEffect } from 'react';
|
8 |
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
9 |
import { useGetKnowledgeSearchParams } from './route-hook';
|
|
|
10 |
|
11 |
export const useKnowledgeBaseId = (): string => {
|
12 |
const [searchParams] = useSearchParams();
|
|
|
128 |
}, [fetchKnowledgeBaseConfiguration]);
|
129 |
};
|
130 |
|
131 |
+
export const useNextFetchKnowledgeList = (
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
shouldFilterListWithoutDocument: boolean = false,
|
133 |
+
): {
|
134 |
+
list: any[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
loading: boolean;
|
136 |
} => {
|
137 |
const { data, isFetching: loading } = useQuery({
|
138 |
queryKey: ['fetchKnowledgeList'],
|
139 |
initialData: [],
|
140 |
+
gcTime: 0, // https://tanstack.com/query/latest/docs/framework/react/guides/caching?from=reactQueryV3
|
141 |
queryFn: async () => {
|
142 |
const { data } = await kbService.getList();
|
143 |
+
const list = data?.data ?? [];
|
144 |
+
return shouldFilterListWithoutDocument
|
145 |
+
? list.filter((x: IKnowledge) => x.chunk_num > 0)
|
146 |
+
: list;
|
147 |
+
},
|
148 |
+
});
|
149 |
+
|
150 |
+
return { list: data, loading };
|
151 |
+
};
|
152 |
+
|
153 |
+
export const useCreateKnowledge = () => {
|
154 |
+
const queryClient = useQueryClient();
|
155 |
+
const {
|
156 |
+
data,
|
157 |
+
isPending: loading,
|
158 |
+
mutateAsync,
|
159 |
+
} = useMutation({
|
160 |
+
mutationKey: ['createKnowledge'],
|
161 |
+
mutationFn: async (params: { id?: string; name: string }) => {
|
162 |
+
const { data = {} } = await kbService.createKb(params);
|
163 |
+
if (data.retcode === 0) {
|
164 |
+
message.success(
|
165 |
+
i18n.t(`message.${params?.id ? 'modified' : 'created'}`),
|
166 |
+
);
|
167 |
+
queryClient.invalidateQueries({ queryKey: ['fetchKnowledgeList'] });
|
168 |
+
}
|
169 |
+
return data;
|
170 |
+
},
|
171 |
+
});
|
172 |
+
|
173 |
+
return { data, loading, createKnowledge: mutateAsync };
|
174 |
+
};
|
175 |
|
176 |
+
export const useDeleteKnowledge = () => {
|
177 |
+
const queryClient = useQueryClient();
|
178 |
+
const {
|
179 |
+
data,
|
180 |
+
isPending: loading,
|
181 |
+
mutateAsync,
|
182 |
+
} = useMutation({
|
183 |
+
mutationKey: ['deleteKnowledge'],
|
184 |
+
mutationFn: async (id: string) => {
|
185 |
+
const { data } = await kbService.rmKb({ kb_id: id });
|
186 |
+
if (data.retcode === 0) {
|
187 |
+
message.success(i18n.t(`message.deleted`));
|
188 |
+
queryClient.invalidateQueries({ queryKey: ['fetchKnowledgeList'] });
|
189 |
+
}
|
190 |
return data?.data ?? [];
|
191 |
},
|
192 |
});
|
193 |
|
194 |
+
return { data, loading, deleteKnowledge: mutateAsync };
|
195 |
};
|
196 |
|
197 |
export const useSelectFileThumbnails = () => {
|
web/src/locales/en.ts
CHANGED
@@ -124,7 +124,7 @@ export default {
|
|
124 |
fromMessage: 'Missing start page number',
|
125 |
toPlaceholder: 'to',
|
126 |
toMessage: 'Missing end page number(excluded)',
|
127 |
-
layoutRecognize: 'Layout
|
128 |
layoutRecognizeTip:
|
129 |
'Use visual models for layout analysis to better identify document structure, find where the titles, text blocks, images, and tables are. Without this feature, only the plain text of the PDF can be obtained.',
|
130 |
taskPageSize: 'Task page size',
|
|
|
124 |
fromMessage: 'Missing start page number',
|
125 |
toPlaceholder: 'to',
|
126 |
toMessage: 'Missing end page number(excluded)',
|
127 |
+
layoutRecognize: 'Layout recognition',
|
128 |
layoutRecognizeTip:
|
129 |
'Use visual models for layout analysis to better identify document structure, find where the titles, text blocks, images, and tables are. Without this feature, only the plain text of the PDF can be obtained.',
|
130 |
taskPageSize: 'Task page size',
|
web/src/pages/add-knowledge/components/knowledge-setting/model.ts
CHANGED
@@ -29,14 +29,6 @@ const model: DvaModel<KSModelState> = {
|
|
29 |
},
|
30 |
},
|
31 |
effects: {
|
32 |
-
*createKb({ payload = {} }, { call }) {
|
33 |
-
const { data } = yield call(kbService.createKb, payload);
|
34 |
-
const { retcode } = data;
|
35 |
-
if (retcode === 0) {
|
36 |
-
message.success(i18n.t('message.created'));
|
37 |
-
}
|
38 |
-
return data;
|
39 |
-
},
|
40 |
*updateKb({ payload = {} }, { call, put }) {
|
41 |
const { data } = yield call(kbService.updateKb, payload);
|
42 |
const { retcode } = data;
|
|
|
29 |
},
|
30 |
},
|
31 |
effects: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
*updateKb({ payload = {} }, { call, put }) {
|
33 |
const { data } = yield call(kbService.updateKb, payload);
|
34 |
const { retcode } = data;
|
web/src/pages/file-manager/connect-to-knowledge-modal/index.tsx
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import { useTranslate } from '@/hooks/common-hooks';
|
2 |
-
import {
|
3 |
import { IModalProps } from '@/interfaces/common';
|
4 |
import { filterOptionsByInput } from '@/utils/commonUtil';
|
5 |
import { Form, Modal, Select } from 'antd';
|
@@ -13,7 +13,7 @@ const ConnectToKnowledgeModal = ({
|
|
13 |
loading,
|
14 |
}: IModalProps<string[]> & { initialValue: string[] }) => {
|
15 |
const [form] = Form.useForm();
|
16 |
-
const { list
|
17 |
const { t } = useTranslate('fileManager');
|
18 |
|
19 |
const options = list?.map((item) => ({
|
@@ -30,9 +30,8 @@ const ConnectToKnowledgeModal = ({
|
|
30 |
useEffect(() => {
|
31 |
if (visible) {
|
32 |
form.setFieldValue('knowledgeIds', initialValue);
|
33 |
-
fetchList();
|
34 |
}
|
35 |
-
}, [visible,
|
36 |
|
37 |
return (
|
38 |
<Modal
|
|
|
1 |
import { useTranslate } from '@/hooks/common-hooks';
|
2 |
+
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
3 |
import { IModalProps } from '@/interfaces/common';
|
4 |
import { filterOptionsByInput } from '@/utils/commonUtil';
|
5 |
import { Form, Modal, Select } from 'antd';
|
|
|
13 |
loading,
|
14 |
}: IModalProps<string[]> & { initialValue: string[] }) => {
|
15 |
const [form] = Form.useForm();
|
16 |
+
const { list } = useNextFetchKnowledgeList();
|
17 |
const { t } = useTranslate('fileManager');
|
18 |
|
19 |
const options = list?.map((item) => ({
|
|
|
30 |
useEffect(() => {
|
31 |
if (visible) {
|
32 |
form.setFieldValue('knowledgeIds', initialValue);
|
|
|
33 |
}
|
34 |
+
}, [visible, initialValue, form]);
|
35 |
|
36 |
return (
|
37 |
<Modal
|
web/src/pages/knowledge/hooks.ts
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
-
import {
|
2 |
-
import {
|
|
|
|
|
|
|
3 |
|
4 |
export const useSearchKnowledge = () => {
|
5 |
const [searchString, setSearchString] = useState<string>('');
|
@@ -13,7 +16,32 @@ export const useSearchKnowledge = () => {
|
|
13 |
};
|
14 |
};
|
15 |
|
16 |
-
export const
|
17 |
-
const
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
};
|
|
|
1 |
+
import { KnowledgeRouteKey } from '@/constants/knowledge';
|
2 |
+
import { useSetModalState } from '@/hooks/common-hooks';
|
3 |
+
import { useCreateKnowledge } from '@/hooks/knowledge-hooks';
|
4 |
+
import { useCallback, useState } from 'react';
|
5 |
+
import { useNavigate } from 'umi';
|
6 |
|
7 |
export const useSearchKnowledge = () => {
|
8 |
const [searchString, setSearchString] = useState<string>('');
|
|
|
16 |
};
|
17 |
};
|
18 |
|
19 |
+
export const useSaveKnowledge = () => {
|
20 |
+
const { visible: visible, hideModal, showModal } = useSetModalState();
|
21 |
+
const { loading, createKnowledge } = useCreateKnowledge();
|
22 |
+
const navigate = useNavigate();
|
23 |
+
|
24 |
+
const onCreateOk = useCallback(
|
25 |
+
async (name: string) => {
|
26 |
+
const ret = await createKnowledge({
|
27 |
+
name,
|
28 |
+
});
|
29 |
+
|
30 |
+
if (ret?.retcode === 0) {
|
31 |
+
hideModal();
|
32 |
+
navigate(
|
33 |
+
`/knowledge/${KnowledgeRouteKey.Configuration}?id=${ret.data.kb_id}`,
|
34 |
+
);
|
35 |
+
}
|
36 |
+
},
|
37 |
+
[createKnowledge, hideModal, navigate],
|
38 |
+
);
|
39 |
+
|
40 |
+
return {
|
41 |
+
loading,
|
42 |
+
onCreateOk,
|
43 |
+
visible,
|
44 |
+
hideModal,
|
45 |
+
showModal,
|
46 |
+
};
|
47 |
};
|
web/src/pages/knowledge/index.tsx
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
-
import
|
2 |
-
import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
3 |
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
4 |
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
|
5 |
import { Button, Empty, Flex, Input, Space, Spin } from 'antd';
|
@@ -7,15 +6,22 @@ import KnowledgeCard from './knowledge-card';
|
|
7 |
import KnowledgeCreatingModal from './knowledge-creating-modal';
|
8 |
|
9 |
import { useTranslation } from 'react-i18next';
|
10 |
-
import {
|
11 |
import styles from './index.less';
|
12 |
|
13 |
const KnowledgeList = () => {
|
14 |
const { searchString, handleInputChange } = useSearchKnowledge();
|
15 |
-
const { loading } =
|
16 |
-
const list =
|
17 |
const userInfo = useSelectUserInfo();
|
18 |
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
return (
|
21 |
<Flex className={styles.knowledge} vertical flex={1}>
|
@@ -36,26 +42,14 @@ const KnowledgeList = () => {
|
|
36 |
prefix={<SearchOutlined />}
|
37 |
/>
|
38 |
|
39 |
-
<
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
}}
|
48 |
-
className={styles.topButton}
|
49 |
-
>
|
50 |
-
{t('createKnowledgeBase')}
|
51 |
-
</Button>
|
52 |
-
<KnowledgeCreatingModal
|
53 |
-
visible={visible}
|
54 |
-
hideModal={hideModal}
|
55 |
-
></KnowledgeCreatingModal>
|
56 |
-
</>
|
57 |
-
)}
|
58 |
-
</ModalManager>
|
59 |
</Space>
|
60 |
</div>
|
61 |
<Spin spinning={loading}>
|
@@ -75,6 +69,12 @@ const KnowledgeList = () => {
|
|
75 |
)}
|
76 |
</Flex>
|
77 |
</Spin>
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
</Flex>
|
79 |
);
|
80 |
};
|
|
|
1 |
+
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
|
|
2 |
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
3 |
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
|
4 |
import { Button, Empty, Flex, Input, Space, Spin } from 'antd';
|
|
|
6 |
import KnowledgeCreatingModal from './knowledge-creating-modal';
|
7 |
|
8 |
import { useTranslation } from 'react-i18next';
|
9 |
+
import { useSaveKnowledge, useSearchKnowledge } from './hooks';
|
10 |
import styles from './index.less';
|
11 |
|
12 |
const KnowledgeList = () => {
|
13 |
const { searchString, handleInputChange } = useSearchKnowledge();
|
14 |
+
const { loading, list: data } = useNextFetchKnowledgeList();
|
15 |
+
const list = data.filter((x) => x.name.includes(searchString));
|
16 |
const userInfo = useSelectUserInfo();
|
17 |
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
18 |
+
const {
|
19 |
+
visible,
|
20 |
+
hideModal,
|
21 |
+
showModal,
|
22 |
+
onCreateOk,
|
23 |
+
loading: creatingLoading,
|
24 |
+
} = useSaveKnowledge();
|
25 |
|
26 |
return (
|
27 |
<Flex className={styles.knowledge} vertical flex={1}>
|
|
|
42 |
prefix={<SearchOutlined />}
|
43 |
/>
|
44 |
|
45 |
+
<Button
|
46 |
+
type="primary"
|
47 |
+
icon={<PlusOutlined />}
|
48 |
+
onClick={showModal}
|
49 |
+
className={styles.topButton}
|
50 |
+
>
|
51 |
+
{t('createKnowledgeBase')}
|
52 |
+
</Button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
</Space>
|
54 |
</div>
|
55 |
<Spin spinning={loading}>
|
|
|
69 |
)}
|
70 |
</Flex>
|
71 |
</Spin>
|
72 |
+
<KnowledgeCreatingModal
|
73 |
+
loading={creatingLoading}
|
74 |
+
visible={visible}
|
75 |
+
hideModal={hideModal}
|
76 |
+
onOk={onCreateOk}
|
77 |
+
></KnowledgeCreatingModal>
|
78 |
</Flex>
|
79 |
);
|
80 |
};
|
web/src/pages/knowledge/knowledge-card/index.tsx
CHANGED
@@ -8,9 +8,10 @@ import {
|
|
8 |
} from '@ant-design/icons';
|
9 |
import { Avatar, Card, Space } from 'antd';
|
10 |
import { useTranslation } from 'react-i18next';
|
11 |
-
import {
|
12 |
|
13 |
import OperateDropdown from '@/components/operate-dropdown';
|
|
|
14 |
import styles from './index.less';
|
15 |
|
16 |
interface IProps {
|
@@ -19,16 +20,12 @@ interface IProps {
|
|
19 |
|
20 |
const KnowledgeCard = ({ item }: IProps) => {
|
21 |
const navigate = useNavigate();
|
22 |
-
const dispatch = useDispatch();
|
23 |
const { t } = useTranslation();
|
24 |
|
|
|
|
|
25 |
const removeKnowledge = async () => {
|
26 |
-
return
|
27 |
-
type: 'knowledgeModel/rmKb',
|
28 |
-
payload: {
|
29 |
-
kb_id: item.id,
|
30 |
-
},
|
31 |
-
});
|
32 |
};
|
33 |
|
34 |
const handleCardClick = () => {
|
|
|
8 |
} from '@ant-design/icons';
|
9 |
import { Avatar, Card, Space } from 'antd';
|
10 |
import { useTranslation } from 'react-i18next';
|
11 |
+
import { useNavigate } from 'umi';
|
12 |
|
13 |
import OperateDropdown from '@/components/operate-dropdown';
|
14 |
+
import { useDeleteKnowledge } from '@/hooks/knowledge-hooks';
|
15 |
import styles from './index.less';
|
16 |
|
17 |
interface IProps {
|
|
|
20 |
|
21 |
const KnowledgeCard = ({ item }: IProps) => {
|
22 |
const navigate = useNavigate();
|
|
|
23 |
const { t } = useTranslation();
|
24 |
|
25 |
+
const { deleteKnowledge } = useDeleteKnowledge();
|
26 |
+
|
27 |
const removeKnowledge = async () => {
|
28 |
+
return deleteKnowledge(item.id);
|
|
|
|
|
|
|
|
|
|
|
29 |
};
|
30 |
|
31 |
const handleCardClick = () => {
|
web/src/pages/knowledge/knowledge-creating-modal/index.tsx
CHANGED
@@ -1,53 +1,30 @@
|
|
1 |
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
2 |
-
import { KnowledgeRouteKey } from '@/constants/knowledge';
|
3 |
import { Form, Input, Modal } from 'antd';
|
4 |
import { useTranslation } from 'react-i18next';
|
5 |
-
import { useDispatch, useNavigate, useSelector } from 'umi';
|
6 |
|
7 |
type FieldType = {
|
8 |
name?: string;
|
9 |
};
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
const KnowledgeCreatingModal = ({
|
12 |
visible,
|
13 |
hideModal,
|
14 |
-
|
|
|
|
|
15 |
const [form] = Form.useForm();
|
16 |
-
|
17 |
-
const loading = useSelector(
|
18 |
-
(state: any) => state.loading.effects['kSModel/createKb'],
|
19 |
-
);
|
20 |
-
const navigate = useNavigate();
|
21 |
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
22 |
|
23 |
const handleOk = async () => {
|
24 |
const ret = await form.validateFields();
|
25 |
|
26 |
-
|
27 |
-
type: 'kSModel/createKb',
|
28 |
-
payload: {
|
29 |
-
name: ret.name,
|
30 |
-
},
|
31 |
-
});
|
32 |
-
|
33 |
-
if (data.retcode === 0) {
|
34 |
-
navigate(
|
35 |
-
`/knowledge/${KnowledgeRouteKey.Configuration}?id=${data.data.kb_id}`,
|
36 |
-
);
|
37 |
-
hideModal();
|
38 |
-
}
|
39 |
-
};
|
40 |
-
|
41 |
-
const handleCancel = () => {
|
42 |
-
hideModal();
|
43 |
-
};
|
44 |
-
|
45 |
-
const onFinish = (values: any) => {
|
46 |
-
console.log('Success:', values);
|
47 |
-
};
|
48 |
-
|
49 |
-
const onFinishFailed = (errorInfo: any) => {
|
50 |
-
console.log('Failed:', errorInfo);
|
51 |
};
|
52 |
|
53 |
return (
|
@@ -55,7 +32,7 @@ const KnowledgeCreatingModal = ({
|
|
55 |
title={t('createKnowledgeBase')}
|
56 |
open={visible}
|
57 |
onOk={handleOk}
|
58 |
-
onCancel={
|
59 |
okButtonProps={{ loading }}
|
60 |
>
|
61 |
<Form
|
@@ -63,8 +40,6 @@ const KnowledgeCreatingModal = ({
|
|
63 |
labelCol={{ span: 4 }}
|
64 |
wrapperCol={{ span: 20 }}
|
65 |
style={{ maxWidth: 600 }}
|
66 |
-
onFinish={onFinish}
|
67 |
-
onFinishFailed={onFinishFailed}
|
68 |
autoComplete="off"
|
69 |
form={form}
|
70 |
>
|
|
|
1 |
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
|
|
2 |
import { Form, Input, Modal } from 'antd';
|
3 |
import { useTranslation } from 'react-i18next';
|
|
|
4 |
|
5 |
type FieldType = {
|
6 |
name?: string;
|
7 |
};
|
8 |
|
9 |
+
interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
10 |
+
loading: boolean;
|
11 |
+
onOk: (name: string) => void;
|
12 |
+
}
|
13 |
+
|
14 |
const KnowledgeCreatingModal = ({
|
15 |
visible,
|
16 |
hideModal,
|
17 |
+
loading,
|
18 |
+
onOk,
|
19 |
+
}: IProps) => {
|
20 |
const [form] = Form.useForm();
|
21 |
+
|
|
|
|
|
|
|
|
|
22 |
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
23 |
|
24 |
const handleOk = async () => {
|
25 |
const ret = await form.validateFields();
|
26 |
|
27 |
+
onOk(ret.name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
};
|
29 |
|
30 |
return (
|
|
|
32 |
title={t('createKnowledgeBase')}
|
33 |
open={visible}
|
34 |
onOk={handleOk}
|
35 |
+
onCancel={hideModal}
|
36 |
okButtonProps={{ loading }}
|
37 |
>
|
38 |
<Form
|
|
|
40 |
labelCol={{ span: 4 }}
|
41 |
wrapperCol={{ span: 20 }}
|
42 |
style={{ maxWidth: 600 }}
|
|
|
|
|
43 |
autoComplete="off"
|
44 |
form={form}
|
45 |
>
|