Skip to content

Commit fe1affe

Browse files
fix: show component sectios open in right panel in search state
1 parent 2bf6d87 commit fe1affe

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

client/packages/lowcoder/src/pages/editor/right/uiCompPanel.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
RightPanelContentWrapper,
1414
} from "pages/editor/right/styledComponent";
1515
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
16-
import React, { useContext, useMemo, useState } from "react";
16+
import React, { useContext, useEffect, useMemo, useState } from "react";
1717
import styled from "styled-components";
1818
import {
1919
BaseSection,
@@ -99,6 +99,7 @@ Object.keys(uiCompCategoryNames).forEach((cat) => {
9999
export const UICompPanel = () => {
100100
const { onDrag, searchValue } = useContext(RightContext);
101101
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);
102+
const [searchedPropertySectionState, setSearchedPropertySectionState] = useState<PropertySectionState>({});
102103

103104
const categories = useMemo(() => {
104105
const cats: Record<string, [string, UICompManifest][]> = Object.fromEntries(
@@ -113,11 +114,18 @@ export const UICompPanel = () => {
113114
}, []);
114115

115116
const propertySectionContextValue = useMemo<PropertySectionContextType>(() => {
117+
const state = searchValue
118+
? searchedPropertySectionState
119+
: propertySectionState;
120+
const setStateFn = searchValue
121+
? setSearchedPropertySectionState
122+
: setPropertySectionState;
123+
116124
return {
117125
compName: stateCompName,
118-
state: propertySectionState,
126+
state,
119127
toggle: (compName: string, sectionName: string) => {
120-
setPropertySectionState((oldState) => {
128+
setStateFn((oldState) => {
121129
const nextSectionState: PropertySectionState = { ...oldState };
122130
const compState = nextSectionState[compName] || {};
123131
compState[sectionName] = compState[sectionName] === false;
@@ -126,7 +134,13 @@ export const UICompPanel = () => {
126134
});
127135
},
128136
};
129-
}, [propertySectionState]);
137+
}, [searchValue, propertySectionState, searchedPropertySectionState]);
138+
139+
useEffect(() => {
140+
if(!searchValue) {
141+
setSearchedPropertySectionState({})
142+
}
143+
}, [searchValue])
130144

131145
const compList = useMemo(
132146
() =>
@@ -187,7 +201,6 @@ export const UICompPanel = () => {
187201

188202
return (
189203
<RightPanelContentWrapper>
190-
{/* {compList.length > 0 ? compList : <EmptyCompContent />} */}
191204
<PropertySectionContext.Provider
192205
value={propertySectionContextValue}
193206
>

0 commit comments

Comments
 (0)