1
- import React , { FunctionComponent , useCallback , useRef , useState } from 'react' ;
1
+ import React , { FunctionComponent , useCallback , useMemo , useRef , useState } from 'react' ;
2
2
import Search from 'antd/lib/input/Search' ;
3
3
import styles from './AppHeaderSearch.module.scss' ;
4
4
import { AutoComplete , InputRef } from 'antd' ;
@@ -12,21 +12,12 @@ import { AutoCompleteProps } from 'antd/lib/auto-complete';
12
12
import classNames from 'classnames' ;
13
13
import { useKey } from 'rooks' ;
14
14
import { isEmpty } from 'lodash' ;
15
+ import useAppSettings from '../../../../../../hooks/useAppSettings' ;
15
16
16
17
interface OptionType extends DefaultOptionType {
17
18
data : MenuRouteItem ;
18
19
}
19
20
20
- const allSearchOptions : OptionType [ ] = menuRouteItems . map ( ( item ) => {
21
- const title = item . title ?? item . route . title ;
22
-
23
- return {
24
- label : title ,
25
- value : title ,
26
- data : item
27
- } ;
28
- } ) ;
29
-
30
21
const filterOption : FilterFunc < OptionType > = ( inputValue , option ) => {
31
22
const query = inputValue . trim ( ) . toLocaleLowerCase ( ) ;
32
23
@@ -49,11 +40,26 @@ interface Props extends Omit<AutoCompleteProps, 'options' | 'filterOption' | 'on
49
40
50
41
const AppHeaderSearch : FunctionComponent < Props > = ( { className, inputClassName, ...props } ) => {
51
42
const navigate = useNavigate ( ) ;
52
-
53
- const searchInputRef = useRef < InputRef > ( null ) ;
43
+ const { doShowHiddenMenuItems } = useAppSettings ( ) ;
54
44
55
45
const [ query , setQuery ] = useState < string > ( '' ) ;
56
46
47
+ const allSearchOptions = useMemo < OptionType [ ] > ( ( ) => {
48
+ return menuRouteItems
49
+ . filter ( ( item ) => doShowHiddenMenuItems || ! item . isHidden )
50
+ . map ( ( item ) => {
51
+ const title = item . title ?? item . route . title ;
52
+
53
+ return {
54
+ label : title ,
55
+ value : title ,
56
+ data : item
57
+ } ;
58
+ } ) ;
59
+ } , [ doShowHiddenMenuItems ] ) ;
60
+
61
+ const searchInputRef = useRef < InputRef > ( null ) ;
62
+
57
63
const autoCompleteRef = useRef < BaseSelectRef > ( null ) ;
58
64
59
65
const selectOption = useCallback ( ( option : MenuRouteItem ) => {
0 commit comments