From de0dbdd4203563aae1f0bec0dc2f8671d3529c8a 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 d6f24dbb3..f8b43fb7f 100644 --- a/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx +++ b/packages/core/src/components/templates/SearchTreeView/SearchTreeView.tsx @@ -113,10 +113,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]); @@ -190,10 +192,10 @@ const SearchTreeView = ({ ); useEffect(() => { - if (isFocused) { + if (isFocused && defaultParent == null) { fetchListAPI(); } - }, [fetchListAPI, isFocused]); + }, [defaultParent, fetchListAPI, isFocused]); const renderParentSearchBar = useCallback(() => { return (