1- import React , { FunctionComponent , useCallback , useRef , useState } from 'react' ;
1+ import React , { FunctionComponent , useCallback , useMemo , useRef , useState } from 'react' ;
22import Search from 'antd/lib/input/Search' ;
33import styles from './AppHeaderSearch.module.scss' ;
44import { AutoComplete , InputRef } from 'antd' ;
@@ -12,21 +12,12 @@ import { AutoCompleteProps } from 'antd/lib/auto-complete';
1212import classNames from 'classnames' ;
1313import { useKey } from 'rooks' ;
1414import { isEmpty } from 'lodash' ;
15+ import useAppSettings from '../../../../../../hooks/useAppSettings' ;
1516
1617interface OptionType extends DefaultOptionType {
1718 data : MenuRouteItem ;
1819}
1920
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-
3021const filterOption : FilterFunc < OptionType > = ( inputValue , option ) => {
3122 const query = inputValue . trim ( ) . toLocaleLowerCase ( ) ;
3223
@@ -49,11 +40,26 @@ interface Props extends Omit<AutoCompleteProps, 'options' | 'filterOption' | 'on
4940
5041const AppHeaderSearch : FunctionComponent < Props > = ( { className, inputClassName, ...props } ) => {
5142 const navigate = useNavigate ( ) ;
52-
53- const searchInputRef = useRef < InputRef > ( null ) ;
43+ const { doShowHiddenMenuItems } = useAppSettings ( ) ;
5444
5545 const [ query , setQuery ] = useState < string > ( '' ) ;
5646
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+
5763 const autoCompleteRef = useRef < BaseSelectRef > ( null ) ;
5864
5965 const selectOption = useCallback ( ( option : MenuRouteItem ) => {
0 commit comments