From 9fee1d9da2479da73fe754cc4d510261ec6b9d72 Mon Sep 17 00:00:00 2001 From: jorgenherje Date: Tue, 10 Oct 2023 14:17:04 +0200 Subject: [PATCH] Revert usage of function, but improve naming for readability Revert usage of function for code. Improved naming for readability. --- .../ParameterListFilter/parameterListFilter.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/frontend/src/framework/components/ParameterListFilter/parameterListFilter.tsx b/frontend/src/framework/components/ParameterListFilter/parameterListFilter.tsx index 8acce053e..bacb53661 100644 --- a/frontend/src/framework/components/ParameterListFilter/parameterListFilter.tsx +++ b/frontend/src/framework/components/ParameterListFilter/parameterListFilter.tsx @@ -28,18 +28,16 @@ export const ParameterListFilter: React.FC = (props: P const [selectedNodes, setSelectedNodes] = React.useState([]); const [numberOfMatchingParameters, setNumberOfMatchingParameters] = React.useState(0); const [parameters, setParameters] = React.useState(null); - const [treeDataNodeList, setTreeDataNodeList] = React.useState([]); + const [previousTreeDataNodeList, setPreviousTreeDataNodeList] = React.useState([]); const smartNodeSelectorDelimiter = ":"; - function computeTreeDataNodeListAndUpdateStates(): TreeDataNode[] { - if (parameters !== null && isEqual(props.parameters, parameters)) return treeDataNodeList; - - const newTreeDataNodeList = createTreeDataNodeListFromParameters([...props.parameters], checkIcon, segmentIcon); + let newTreeDataNodeList: TreeDataNode[] | null = null; + if (parameters === null || !isEqual(props.parameters, parameters)) { + newTreeDataNodeList = createTreeDataNodeListFromParameters(props.parameters, checkIcon, segmentIcon); setParameters(props.parameters); - setTreeDataNodeList(newTreeDataNodeList); - return newTreeDataNodeList; + setPreviousTreeDataNodeList(newTreeDataNodeList); } - const computedTreeDataNodeList = computeTreeDataNodeListAndUpdateStates(); + const treeDataNodeList = newTreeDataNodeList ? newTreeDataNodeList : previousTreeDataNodeList; // Utilizing useEffect to prevent re-render of parent component during rendering of this component React.useEffect( @@ -76,7 +74,7 @@ export const ParameterListFilter: React.FC = (props: P