Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use Spin to wrap the chunk list on the search page #2247 #2409

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions web/src/pages/search/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,39 @@ export const useSendQuestion = (kbIds: string[]) => {
const [isFirstRender, setIsFirstRender] = useState(true);
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);

const { pagination } = useGetPaginationWithRouter();
const { pagination, setPagination } = useGetPaginationWithRouter();

const sendQuestion = useCallback(
(question: string) => {
const q = trim(question);
if (isEmpty(q)) return;
setPagination({ page: 1 });
setIsFirstRender(false);
setCurrentAnswer({} as IAnswer);
setSendingLoading(true);
send({ kb_ids: kbIds, question: q });
testChunk({ kb_id: kbIds, highlight: true, question: q });
testChunk({
kb_id: kbIds,
highlight: true,
question: q,
page: 1,
size: pagination.pageSize,
});
fetchMindMap({
question: q,
kb_ids: kbIds,
});
fetchRelatedQuestions(q);
},
[send, testChunk, kbIds, fetchRelatedQuestions, fetchMindMap],
[
send,
testChunk,
kbIds,
fetchRelatedQuestions,
fetchMindMap,
setPagination,
pagination.pageSize,
],
);

const handleSearchStrChange: ChangeEventHandler<HTMLInputElement> =
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/search/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
background-size: cover;
.card {
width: 100%;
cursor: pointer;
:global(.ant-card-body) {
padding: 14px;
}
Expand Down
72 changes: 37 additions & 35 deletions web/src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Popover,
Skeleton,
Space,
Spin,
Tag,
} from 'antd';
import { useMemo, useState } from 'react';
Expand Down Expand Up @@ -139,44 +140,45 @@ const SearchPage = () => {
onTesting={handleTestChunk}
></RetrievalDocuments>
<Divider></Divider>
{chunks.length > 0 && (
<List
dataSource={chunks}
loading={loading}
className={styles.chunks}
renderItem={(item) => (
<List.Item>
<Card
className={styles.card}
onClick={() =>
clickDocumentButton(item.doc_id, item as any)
}
>
<Space>
<ImageWithPopover
id={item.img_id}
></ImageWithPopover>
<Popover
content={
<div className={styles.popupMarkdown}>
<Spin spinning={loading}>
{chunks.length > 0 && (
<List
dataSource={chunks}
className={styles.chunks}
renderItem={(item) => (
<List.Item>
<Card
className={styles.card}
onClick={() =>
clickDocumentButton(item.doc_id, item as any)
}
>
<Space>
<ImageWithPopover
id={item.img_id}
></ImageWithPopover>
<Popover
content={
<div className={styles.popupMarkdown}>
<HightLightMarkdown>
{item.content_with_weight}
</HightLightMarkdown>
</div>
}
>
<div>
<HightLightMarkdown>
{item.content_with_weight}
{item.highlight}
</HightLightMarkdown>
</div>
}
>
<div>
<HightLightMarkdown>
{item.highlight}
</HightLightMarkdown>
</div>
</Popover>
</Space>
</Card>
</List.Item>
)}
/>
)}
</Popover>
</Space>
</Card>
</List.Item>
)}
/>
)}
</Spin>
{relatedQuestions?.length > 0 && (
<Card title={t('chat.relatedQuestion')}>
<Flex wrap="wrap" gap={'10px 0'}>
Expand Down