Skip to content

Commit

Permalink
add node ID when duplicate node names
Browse files Browse the repository at this point in the history
  • Loading branch information
sc420 committed Jan 21, 2024
1 parent 1d5e570 commit 29d62dd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions interactive-computational-graph/src/components/GraphToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ const GraphToolbar: FunctionComponent<GraphToolbarProps> = ({
onDerivativeTargetChange,
}) => {
const options: AutocompleteOption[] = useMemo(() => {
return nodeIds.map((nodeId, index) => ({
label: nodeNames[index],
id: nodeId,
}));
const seenNodeNames = new Set<string>();
return nodeIds.map((nodeId, index) => {
const nodeName = nodeNames[index];
const label = seenNodeNames.has(nodeName)
? `${nodeName} (${nodeId})`
: nodeName;

seenNodeNames.add(nodeName);
return {
label,
id: nodeId,
};
});
}, [nodeIds, nodeNames]);

const selectedValue: AutocompleteOption | null = useMemo(() => {
Expand Down

0 comments on commit 29d62dd

Please sign in to comment.