Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: show component sectios open in right panel in search state
  • Loading branch information
raheeliftikhar5 committed Nov 30, 2023
commit fe1affed2e14d874e7b717b7fae994e0c9b1a317
23 changes: 18 additions & 5 deletions client/packages/lowcoder/src/pages/editor/right/uiCompPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RightPanelContentWrapper,
} from "pages/editor/right/styledComponent";
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
import React, { useContext, useMemo, useState } from "react";
import React, { useContext, useEffect, useMemo, useState } from "react";
import styled from "styled-components";
import {
BaseSection,
Expand Down Expand Up @@ -99,6 +99,7 @@ Object.keys(uiCompCategoryNames).forEach((cat) => {
export const UICompPanel = () => {
const { onDrag, searchValue } = useContext(RightContext);
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);
const [searchedPropertySectionState, setSearchedPropertySectionState] = useState<PropertySectionState>({});

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

const propertySectionContextValue = useMemo<PropertySectionContextType>(() => {
const state = searchValue
? searchedPropertySectionState
: propertySectionState;
const setStateFn = searchValue
? setSearchedPropertySectionState
: setPropertySectionState;

return {
compName: stateCompName,
state: propertySectionState,
state,
toggle: (compName: string, sectionName: string) => {
setPropertySectionState((oldState) => {
setStateFn((oldState) => {
const nextSectionState: PropertySectionState = { ...oldState };
const compState = nextSectionState[compName] || {};
compState[sectionName] = compState[sectionName] === false;
Expand All @@ -126,7 +134,13 @@ export const UICompPanel = () => {
});
},
};
}, [propertySectionState]);
}, [searchValue, propertySectionState, searchedPropertySectionState]);

useEffect(() => {
if(!searchValue) {
setSearchedPropertySectionState({})
}
}, [searchValue])

const compList = useMemo(
() =>
Expand Down Expand Up @@ -187,7 +201,6 @@ export const UICompPanel = () => {

return (
<RightPanelContentWrapper>
{/* {compList.length > 0 ? compList : <EmptyCompContent />} */}
<PropertySectionContext.Provider
value={propertySectionContextValue}
>
Expand Down