Skip to content

Commit

Permalink
tidy up code
Browse files Browse the repository at this point in the history
Signed-off-by: Huong Nguyen <huongg1409@gmail>
  • Loading branch information
Huong Nguyen committed Aug 23, 2024
1 parent d0ba1dc commit d4c54eb
Showing 1 changed file with 3 additions and 34 deletions.
37 changes: 3 additions & 34 deletions src/selectors/sliced-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,7 @@ const sliceTree = (input, startId, endId) => {
return result;
};

/**
* Recursive function to find all linked nodes starting from a given node ID.
* @param {string} nodeID - The starting node ID.
* @param {Object} edgesByNode - A map of node IDs to their connected node IDs.
* @param {Object} visited - A map to keep track of visited nodes.
* @returns {Object} A map of visited nodes.
*/
const findLinkedNodes = (nodeID, edgesByNode, visited, names) => {
// Check if the current node has not been visited
if (!visited[nodeID]) {
// Mark the current node as visited
visited[nodeID] = true;
// If the current node has outgoing edges
if (edgesByNode[nodeID]) {
// Recursively visit all connected nodes
edgesByNode[nodeID].forEach((nodeID) =>
findLinkedNodes(nodeID, edgesByNode, visited)
);
}
}

// Return the map of visited nodes
return visited;
};

const findNodesInBetween = (
sourceEdges,
targetEdges,
startID,
endID,
names
) => {
const findNodesInBetween = (targetEdges, startID, endID) => {
if (!startID || !endID) {
return [startID, endID].filter(Boolean);
}
Expand Down Expand Up @@ -154,7 +123,7 @@ const findNodesInBetween = (

export const getSlicedPipeline = createSelector(
[getEdgesByNode, getFromNodes, getToNodes, getNames],
({ sourceEdges, targetEdges }, startID, endID, names) => {
return findNodesInBetween(sourceEdges, targetEdges, startID, endID, names);
({ sourceEdges, targetEdges }, startID, endID) => {
return findNodesInBetween(targetEdges, startID, endID);
}
);

0 comments on commit d4c54eb

Please sign in to comment.