From 39581ca59d4beac49da6635680196e26c85064d9 Mon Sep 17 00:00:00 2001 From: vhu-axelor <146069039+vhu-axelor@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:16:35 +0100 Subject: [PATCH] fix: issue with defaultParent on SearchTreeView (#831) * RM#87641 --- .../templates/SearchTreeView/SearchTreeView.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx b/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx index f15d49431..5631428c1 100644 --- a/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx +++ b/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx @@ -115,10 +115,12 @@ const SearchTreeView = ({ const isFocused = useIsFocused(); const [filter, setFilter] = useState(null); - const [parent, setParent] = useState([]); + const [parent, setParent] = useState( + defaultParent ? [EMPTY_PARENT, defaultParent] : [], + ); useEffect(() => { - if (defaultParent != null && isFocused) { + if (isFocused && defaultParent != null) { setParent([EMPTY_PARENT, defaultParent]); } }, [defaultParent, isFocused]); @@ -192,10 +194,10 @@ const SearchTreeView = ({ ); useEffect(() => { - if (isFocused) { + if (isFocused && defaultParent == null) { fetchListAPI(); } - }, [fetchListAPI, isFocused]); + }, [defaultParent, fetchListAPI, isFocused]); const renderParentSearchBar = useCallback(() => { return (