Skip to content

Commit

Permalink
Revert usage of function, but improve naming for readability
Browse files Browse the repository at this point in the history
Revert usage of function for code. Improved naming for readability.
  • Loading branch information
jorgenherje committed Oct 10, 2023
1 parent 4cbe645 commit 9fee1d9
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ export const ParameterListFilter: React.FC<ParameterListFilterProps> = (props: P
const [selectedNodes, setSelectedNodes] = React.useState<string[]>([]);
const [numberOfMatchingParameters, setNumberOfMatchingParameters] = React.useState<number>(0);
const [parameters, setParameters] = React.useState<Parameter[] | null>(null);
const [treeDataNodeList, setTreeDataNodeList] = React.useState<TreeDataNode[]>([]);
const [previousTreeDataNodeList, setPreviousTreeDataNodeList] = React.useState<TreeDataNode[]>([]);
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(
Expand Down Expand Up @@ -76,7 +74,7 @@ export const ParameterListFilter: React.FC<ParameterListFilterProps> = (props: P
<SmartNodeSelector
id={smartNodeSelectorId}
delimiter={smartNodeSelectorDelimiter}
data={computedTreeDataNodeList}
data={treeDataNodeList}
selectedTags={selectedTags}
label={props.showTitle ? "Parameter filtering" : undefined}
onChange={handleSmartNodeSelectorChange}
Expand Down

0 comments on commit 9fee1d9

Please sign in to comment.