Skip to content

Commit 6e080c6

Browse files
fix: initially show only commonly used comps
1 parent 436283f commit 6e080c6

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import {
1313
RightPanelContentWrapper,
1414
} from "pages/editor/right/styledComponent";
1515
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
16-
import React, { useContext, useMemo } from "react";
16+
import React, { useContext, useMemo, useState } from "react";
1717
import styled from "styled-components";
1818
import {
1919
BaseSection,
20+
PropertySectionContext,
21+
PropertySectionContextType,
22+
PropertySectionState,
2023
labelCss,
2124
} from "lowcoder-design";
2225
import { TransparentImg } from "../../../util/commonUtils";
@@ -83,8 +86,16 @@ const SectionWrapper = styled.div`
8386
}
8487
`;
8588

89+
const stateCompName = 'UICompSections';
90+
const initialState: PropertySectionState = { [stateCompName]: {}};
91+
Object.keys(uiCompCategoryNames).forEach((cat) => {
92+
const key = uiCompCategoryNames[cat as UICompCategory];
93+
initialState[stateCompName][key] = key === uiCompCategoryNames.common
94+
})
95+
8696
export const UICompPanel = () => {
8797
const { onDrag, searchValue } = useContext(RightContext);
98+
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);
8899

89100
const categories = useMemo(() => {
90101
const cats: Record<string, [string, UICompManifest][]> = Object.fromEntries(
@@ -98,6 +109,22 @@ export const UICompPanel = () => {
98109
return cats;
99110
}, []);
100111

112+
const propertySectionContextValue = useMemo<PropertySectionContextType>(() => {
113+
return {
114+
compName: stateCompName,
115+
state: propertySectionState,
116+
toggle: (compName: string, sectionName: string) => {
117+
setPropertySectionState((oldState) => {
118+
const nextSectionState: PropertySectionState = { ...oldState };
119+
const compState = nextSectionState[compName] || {};
120+
compState[sectionName] = compState[sectionName] === false;
121+
nextSectionState[compName] = compState;
122+
return nextSectionState;
123+
});
124+
},
125+
};
126+
}, [propertySectionState]);
127+
101128
const compList = useMemo(
102129
() =>
103130
Object.entries(categories)
@@ -149,9 +176,20 @@ export const UICompPanel = () => {
149176
[categories, searchValue, onDrag]
150177
);
151178

179+
if(!compList.length) return (
180+
<RightPanelContentWrapper>
181+
<EmptyCompContent />
182+
</RightPanelContentWrapper>
183+
)
184+
152185
return (
153186
<RightPanelContentWrapper>
154-
{compList.length > 0 ? compList : <EmptyCompContent />}
187+
{/* {compList.length > 0 ? compList : <EmptyCompContent />} */}
188+
<PropertySectionContext.Provider
189+
value={propertySectionContextValue}
190+
>
191+
{compList}
192+
</PropertySectionContext.Provider>
155193
</RightPanelContentWrapper>
156194
);
157195
};

0 commit comments

Comments
 (0)