balibabu commited on
Commit
ab13701
·
1 Parent(s): f711e2a

feat: The same query conditions on the search page should not request the interface every time the mind map drawer is opened. #2759 (#2760)

Browse files

### What problem does this PR solve?

feat: The same query conditions on the search page should not request
the interface every time the mind map drawer is opened. #2759

### 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):

Files changed (1) hide show
  1. web/src/pages/search/hooks.ts +10 -2
web/src/pages/search/hooks.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
  } from '@/hooks/logic-hooks';
8
  import { IAnswer } from '@/interfaces/database/chat';
9
  import api from '@/utils/api';
10
- import { get, isEmpty, trim } from 'lodash';
11
  import {
12
  ChangeEventHandler,
13
  useCallback,
@@ -188,6 +188,7 @@ export const useTestRetrieval = (
188
 
189
  export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
190
  const { visible, showModal, hideModal } = useSetModalState();
 
191
 
192
  const {
193
  fetchMindMap,
@@ -196,7 +197,14 @@ export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
196
  } = useFetchMindMap();
197
 
198
  const handleShowModal = useCallback(() => {
199
- fetchMindMap({ question: trim(question), kb_ids: kbIds });
 
 
 
 
 
 
 
200
  showModal();
201
  }, [fetchMindMap, showModal, question, kbIds]);
202
 
 
7
  } from '@/hooks/logic-hooks';
8
  import { IAnswer } from '@/interfaces/database/chat';
9
  import api from '@/utils/api';
10
+ import { get, isEmpty, isEqual, trim } from 'lodash';
11
  import {
12
  ChangeEventHandler,
13
  useCallback,
 
188
 
189
  export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
190
  const { visible, showModal, hideModal } = useSetModalState();
191
+ const ref = useRef<any>();
192
 
193
  const {
194
  fetchMindMap,
 
197
  } = useFetchMindMap();
198
 
199
  const handleShowModal = useCallback(() => {
200
+ const searchParams = { question: trim(question), kb_ids: kbIds };
201
+ if (
202
+ !isEmpty(searchParams.question) &&
203
+ !isEqual(searchParams, ref.current)
204
+ ) {
205
+ ref.current = searchParams;
206
+ fetchMindMap(searchParams);
207
+ }
208
  showModal();
209
  }, [fetchMindMap, showModal, question, kbIds]);
210