@@ -13,7 +13,7 @@ import {
13
13
RightPanelContentWrapper ,
14
14
} from "pages/editor/right/styledComponent" ;
15
15
import { tableDragClassName } from "pages/tutorials/tutorialsConstant" ;
16
- import React , { useContext , useMemo , useState } from "react" ;
16
+ import React , { useContext , useEffect , useMemo , useState } from "react" ;
17
17
import styled from "styled-components" ;
18
18
import {
19
19
BaseSection ,
@@ -99,6 +99,7 @@ Object.keys(uiCompCategoryNames).forEach((cat) => {
99
99
export const UICompPanel = ( ) => {
100
100
const { onDrag, searchValue } = useContext ( RightContext ) ;
101
101
const [ propertySectionState , setPropertySectionState ] = useState < PropertySectionState > ( initialState ) ;
102
+ const [ searchedPropertySectionState , setSearchedPropertySectionState ] = useState < PropertySectionState > ( { } ) ;
102
103
103
104
const categories = useMemo ( ( ) => {
104
105
const cats : Record < string , [ string , UICompManifest ] [ ] > = Object . fromEntries (
@@ -113,11 +114,18 @@ export const UICompPanel = () => {
113
114
} , [ ] ) ;
114
115
115
116
const propertySectionContextValue = useMemo < PropertySectionContextType > ( ( ) => {
117
+ const state = searchValue
118
+ ? searchedPropertySectionState
119
+ : propertySectionState ;
120
+ const setStateFn = searchValue
121
+ ? setSearchedPropertySectionState
122
+ : setPropertySectionState ;
123
+
116
124
return {
117
125
compName : stateCompName ,
118
- state : propertySectionState ,
126
+ state,
119
127
toggle : ( compName : string , sectionName : string ) => {
120
- setPropertySectionState ( ( oldState ) => {
128
+ setStateFn ( ( oldState ) => {
121
129
const nextSectionState : PropertySectionState = { ...oldState } ;
122
130
const compState = nextSectionState [ compName ] || { } ;
123
131
compState [ sectionName ] = compState [ sectionName ] === false ;
@@ -126,7 +134,13 @@ export const UICompPanel = () => {
126
134
} ) ;
127
135
} ,
128
136
} ;
129
- } , [ propertySectionState ] ) ;
137
+ } , [ searchValue , propertySectionState , searchedPropertySectionState ] ) ;
138
+
139
+ useEffect ( ( ) => {
140
+ if ( ! searchValue ) {
141
+ setSearchedPropertySectionState ( { } )
142
+ }
143
+ } , [ searchValue ] )
130
144
131
145
const compList = useMemo (
132
146
( ) =>
@@ -187,7 +201,6 @@ export const UICompPanel = () => {
187
201
188
202
return (
189
203
< RightPanelContentWrapper >
190
- { /* {compList.length > 0 ? compList : <EmptyCompContent />} */ }
191
204
< PropertySectionContext . Provider
192
205
value = { propertySectionContextValue }
193
206
>
0 commit comments