From a4bccc1ae73341ebbb9cc8c629c47d48ca067a26 Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 23 Dec 2024 15:17:56 +0800 Subject: [PATCH] Feat: If there is no result in the recall test, an empty data image will be displayed. #4182 (#4183) ### What problem does this PR solve? Feat: If there is no result in the recall test, an empty data image will be displayed. #4182 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/hooks/knowledge-hooks.ts | 10 ++++ .../testing-result/index.tsx | 51 +++++++++++-------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/web/src/hooks/knowledge-hooks.ts b/web/src/hooks/knowledge-hooks.ts index 6f972f5b9..23ca80e9f 100644 --- a/web/src/hooks/knowledge-hooks.ts +++ b/web/src/hooks/knowledge-hooks.ts @@ -248,4 +248,14 @@ export const useSelectTestingResult = (): ITestingResult => { total: 0, }) as ITestingResult; }; + +export const useSelectIsTestingSuccess = () => { + const status = useMutationState({ + filters: { mutationKey: ['testChunk'] }, + select: (mutation) => { + return mutation.state.status; + }, + }); + return status.at(-1) === 'success'; +}; //#endregion diff --git a/web/src/pages/add-knowledge/components/knowledge-testing/testing-result/index.tsx b/web/src/pages/add-knowledge/components/knowledge-testing/testing-result/index.tsx index 36a19f286..f016eb5c8 100644 --- a/web/src/pages/add-knowledge/components/knowledge-testing/testing-result/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-testing/testing-result/index.tsx @@ -5,6 +5,7 @@ import { ITestingChunk } from '@/interfaces/database/knowledge'; import { Card, Collapse, + Empty, Flex, Pagination, PaginationProps, @@ -14,7 +15,10 @@ import { import camelCase from 'lodash/camelCase'; import SelectFiles from './select-files'; -import { useSelectTestingResult } from '@/hooks/knowledge-hooks'; +import { + useSelectIsTestingSuccess, + useSelectTestingResult, +} from '@/hooks/knowledge-hooks'; import { useGetPaginationWithRouter } from '@/hooks/logic-hooks'; import { useCallback, useState } from 'react'; import styles from './index.less'; @@ -50,6 +54,7 @@ const TestingResult = ({ handleTesting }: IProps) => { const { documents, chunks, total } = useSelectTestingResult(); const { t } = useTranslate('knowledgeDetails'); const { pagination, setPagination } = useGetPaginationWithRouter(); + const isSuccess = useSelectIsTestingSuccess(); const onChange: PaginationProps['onChange'] = (pageNumber, pageSize) => { pagination.onChange?.(pageNumber, pageSize); @@ -105,26 +110,30 @@ const TestingResult = ({ handleTesting }: IProps) => { flex={1} className={styles.selectFilesCollapse} > - {chunks?.map((x) => ( - }> - - {x.img_id && ( - - } - > - - - )} -
{x.content_with_weight}
-
-
- ))} + {isSuccess && chunks.length > 0 ? ( + chunks?.map((x) => ( + }> + + {x.img_id && ( + + } + > + + + )} +
{x.content_with_weight}
+
+
+ )) + ) : isSuccess && chunks.length === 0 ? ( + + ) : null}