balibabu
commited on
Commit
·
189ed3a
1
Parent(s):
5ac16f5
feat: Use Spin to wrap the chunk list on the search page #2247 (#2409)
Browse files### What problem does this PR solve?
feat: Use Spin to wrap the chunk list on the search page #2247
### Type of change
- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
- web/src/pages/search/hooks.ts +18 -3
- web/src/pages/search/index.less +1 -0
- web/src/pages/search/index.tsx +37 -35
web/src/pages/search/hooks.ts
CHANGED
|
@@ -25,24 +25,39 @@ export const useSendQuestion = (kbIds: string[]) => {
|
|
| 25 |
const [isFirstRender, setIsFirstRender] = useState(true);
|
| 26 |
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
| 27 |
|
| 28 |
-
const { pagination } = useGetPaginationWithRouter();
|
| 29 |
|
| 30 |
const sendQuestion = useCallback(
|
| 31 |
(question: string) => {
|
| 32 |
const q = trim(question);
|
| 33 |
if (isEmpty(q)) return;
|
|
|
|
| 34 |
setIsFirstRender(false);
|
| 35 |
setCurrentAnswer({} as IAnswer);
|
| 36 |
setSendingLoading(true);
|
| 37 |
send({ kb_ids: kbIds, question: q });
|
| 38 |
-
testChunk({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
fetchMindMap({
|
| 40 |
question: q,
|
| 41 |
kb_ids: kbIds,
|
| 42 |
});
|
| 43 |
fetchRelatedQuestions(q);
|
| 44 |
},
|
| 45 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
);
|
| 47 |
|
| 48 |
const handleSearchStrChange: ChangeEventHandler<HTMLInputElement> =
|
|
|
|
| 25 |
const [isFirstRender, setIsFirstRender] = useState(true);
|
| 26 |
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
| 27 |
|
| 28 |
+
const { pagination, setPagination } = useGetPaginationWithRouter();
|
| 29 |
|
| 30 |
const sendQuestion = useCallback(
|
| 31 |
(question: string) => {
|
| 32 |
const q = trim(question);
|
| 33 |
if (isEmpty(q)) return;
|
| 34 |
+
setPagination({ page: 1 });
|
| 35 |
setIsFirstRender(false);
|
| 36 |
setCurrentAnswer({} as IAnswer);
|
| 37 |
setSendingLoading(true);
|
| 38 |
send({ kb_ids: kbIds, question: q });
|
| 39 |
+
testChunk({
|
| 40 |
+
kb_id: kbIds,
|
| 41 |
+
highlight: true,
|
| 42 |
+
question: q,
|
| 43 |
+
page: 1,
|
| 44 |
+
size: pagination.pageSize,
|
| 45 |
+
});
|
| 46 |
fetchMindMap({
|
| 47 |
question: q,
|
| 48 |
kb_ids: kbIds,
|
| 49 |
});
|
| 50 |
fetchRelatedQuestions(q);
|
| 51 |
},
|
| 52 |
+
[
|
| 53 |
+
send,
|
| 54 |
+
testChunk,
|
| 55 |
+
kbIds,
|
| 56 |
+
fetchRelatedQuestions,
|
| 57 |
+
fetchMindMap,
|
| 58 |
+
setPagination,
|
| 59 |
+
pagination.pageSize,
|
| 60 |
+
],
|
| 61 |
);
|
| 62 |
|
| 63 |
const handleSearchStrChange: ChangeEventHandler<HTMLInputElement> =
|
web/src/pages/search/index.less
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
background-size: cover;
|
| 4 |
.card {
|
| 5 |
width: 100%;
|
|
|
|
| 6 |
:global(.ant-card-body) {
|
| 7 |
padding: 14px;
|
| 8 |
}
|
|
|
|
| 3 |
background-size: cover;
|
| 4 |
.card {
|
| 5 |
width: 100%;
|
| 6 |
+
cursor: pointer;
|
| 7 |
:global(.ant-card-body) {
|
| 8 |
padding: 14px;
|
| 9 |
}
|
web/src/pages/search/index.tsx
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
| 22 |
Popover,
|
| 23 |
Skeleton,
|
| 24 |
Space,
|
|
|
|
| 25 |
Tag,
|
| 26 |
} from 'antd';
|
| 27 |
import { useMemo, useState } from 'react';
|
|
@@ -139,44 +140,45 @@ const SearchPage = () => {
|
|
| 139 |
onTesting={handleTestChunk}
|
| 140 |
></RetrievalDocuments>
|
| 141 |
<Divider></Divider>
|
| 142 |
-
{
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
<HightLightMarkdown>
|
| 163 |
-
{item.
|
| 164 |
</HightLightMarkdown>
|
| 165 |
</div>
|
| 166 |
-
|
| 167 |
-
>
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
</Space>
|
| 175 |
-
</Card>
|
| 176 |
-
</List.Item>
|
| 177 |
-
)}
|
| 178 |
-
/>
|
| 179 |
-
)}
|
| 180 |
{relatedQuestions?.length > 0 && (
|
| 181 |
<Card title={t('chat.relatedQuestion')}>
|
| 182 |
<Flex wrap="wrap" gap={'10px 0'}>
|
|
|
|
| 22 |
Popover,
|
| 23 |
Skeleton,
|
| 24 |
Space,
|
| 25 |
+
Spin,
|
| 26 |
Tag,
|
| 27 |
} from 'antd';
|
| 28 |
import { useMemo, useState } from 'react';
|
|
|
|
| 140 |
onTesting={handleTestChunk}
|
| 141 |
></RetrievalDocuments>
|
| 142 |
<Divider></Divider>
|
| 143 |
+
<Spin spinning={loading}>
|
| 144 |
+
{chunks.length > 0 && (
|
| 145 |
+
<List
|
| 146 |
+
dataSource={chunks}
|
| 147 |
+
className={styles.chunks}
|
| 148 |
+
renderItem={(item) => (
|
| 149 |
+
<List.Item>
|
| 150 |
+
<Card
|
| 151 |
+
className={styles.card}
|
| 152 |
+
onClick={() =>
|
| 153 |
+
clickDocumentButton(item.doc_id, item as any)
|
| 154 |
+
}
|
| 155 |
+
>
|
| 156 |
+
<Space>
|
| 157 |
+
<ImageWithPopover
|
| 158 |
+
id={item.img_id}
|
| 159 |
+
></ImageWithPopover>
|
| 160 |
+
<Popover
|
| 161 |
+
content={
|
| 162 |
+
<div className={styles.popupMarkdown}>
|
| 163 |
+
<HightLightMarkdown>
|
| 164 |
+
{item.content_with_weight}
|
| 165 |
+
</HightLightMarkdown>
|
| 166 |
+
</div>
|
| 167 |
+
}
|
| 168 |
+
>
|
| 169 |
+
<div>
|
| 170 |
<HightLightMarkdown>
|
| 171 |
+
{item.highlight}
|
| 172 |
</HightLightMarkdown>
|
| 173 |
</div>
|
| 174 |
+
</Popover>
|
| 175 |
+
</Space>
|
| 176 |
+
</Card>
|
| 177 |
+
</List.Item>
|
| 178 |
+
)}
|
| 179 |
+
/>
|
| 180 |
+
)}
|
| 181 |
+
</Spin>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
{relatedQuestions?.length > 0 && (
|
| 183 |
<Card title={t('chat.relatedQuestion')}>
|
| 184 |
<Flex wrap="wrap" gap={'10px 0'}>
|