@@ -14,10 +14,19 @@ import {
14
14
fetchDirectoryContent ,
15
15
} from '@gridsuite/commons-ui' ;
16
16
import { useDispatch , useSelector } from 'react-redux' ;
17
- import { setSelectedDirectory , setTreeData } from '../../redux/actions' ;
17
+ import {
18
+ setSearchedElement ,
19
+ setSelectedDirectory ,
20
+ setTreeData ,
21
+ } from '../../redux/actions' ;
18
22
import { updatedTree } from '../tree-views-container' ;
19
- import { MatchingElementProps , SearchItem } from './search-item' ;
20
- import { IDirectory , ITreeData , ReduxState } from '../../redux/reducer.type' ;
23
+ import { SearchItem } from './search-item' ;
24
+ import {
25
+ ElementAttributesES ,
26
+ IDirectory ,
27
+ ITreeData ,
28
+ ReduxState ,
29
+ } from '../../redux/reducer.type' ;
21
30
import { RenderElementProps } from '@gridsuite/commons-ui/dist/components/ElementSearchDialog/element-search-input' ;
22
31
import { TextFieldProps } from '@mui/material' ;
23
32
import { SearchBarRenderInput } from './search-bar-render-input' ;
@@ -29,9 +38,8 @@ interface SearchBarProps {
29
38
inputRef : RefObject < TextFieldProps > ;
30
39
}
31
40
32
- const fetchElements : (
33
- newSearchTerm : string
34
- ) => Promise < MatchingElementProps [ ] > = searchElementsInfos ;
41
+ const fetchElements : ( newSearchTerm : string ) => Promise < ElementAttributesES [ ] > =
42
+ searchElementsInfos ;
35
43
36
44
export const SearchBar : FunctionComponent < SearchBarProps > = ( { inputRef } ) => {
37
45
const dispatch = useDispatch ( ) ;
@@ -46,7 +54,7 @@ export const SearchBar: FunctionComponent<SearchBarProps> = ({ inputRef }) => {
46
54
} ) ;
47
55
48
56
const renderOptionItem = useCallback (
49
- ( props : RenderElementProps < MatchingElementProps > ) => {
57
+ ( props : RenderElementProps < ElementAttributesES > ) => {
50
58
const { element, inputValue } = props ;
51
59
const matchingElement = elementsFound . find (
52
60
( e ) => e . id === element . id
@@ -97,9 +105,9 @@ export const SearchBar: FunctionComponent<SearchBarProps> = ({ inputRef }) => {
97
105
) ;
98
106
99
107
const handleMatchingElement = useCallback (
100
- async ( data : MatchingElementProps | string | null ) => {
108
+ async ( data : ElementAttributesES | string | null ) => {
101
109
const matchingElement = elementsFound . find (
102
- ( element : MatchingElementProps ) => element === data
110
+ ( element : ElementAttributesES ) => element === data
103
111
) ;
104
112
if ( matchingElement !== undefined ) {
105
113
const elementUuidPath = matchingElement ?. pathUuid ;
@@ -121,9 +129,16 @@ export const SearchBar: FunctionComponent<SearchBarProps> = ({ inputRef }) => {
121
129
}
122
130
const lastElement = elementUuidPath . pop ( ) ;
123
131
handleDispatchDirectory ( lastElement ) ;
132
+ dispatch ( setSearchedElement ( data ) ) ;
124
133
}
125
134
} ,
126
- [ elementsFound , handleDispatchDirectory , updateMapData , snackError ]
135
+ [
136
+ elementsFound ,
137
+ handleDispatchDirectory ,
138
+ updateMapData ,
139
+ snackError ,
140
+ dispatch ,
141
+ ]
127
142
) ;
128
143
129
144
return (
0 commit comments