Skip to content

Commit 6985386

Browse files
committed
address more comments
1 parent cd4adf6 commit 6985386

File tree

1 file changed

+16
-10
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]

1 file changed

+16
-10
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,17 @@ function mapEdgesByNode(edges: Edge[], nodeIds: Set<string>): Map<string, Edge[]
169169

170170
/**
171171
* Syncs the panel editor with the current selection state.
172-
* Shows block details when exactly one block is selected, clears otherwise.
172+
* Shows the last selected block in the panel. Clears when nothing is selected.
173173
*/
174174
function syncPanelWithSelection(selectedIds: string[]) {
175175
const { currentBlockId, clearCurrentBlock, setCurrentBlockId } = usePanelEditorStore.getState()
176-
if (selectedIds.length === 1 && selectedIds[0] !== currentBlockId) {
177-
setCurrentBlockId(selectedIds[0])
178-
} else if (selectedIds.length === 0 && currentBlockId) {
179-
clearCurrentBlock()
180-
} else if (selectedIds.length > 1 && currentBlockId) {
181-
clearCurrentBlock()
176+
if (selectedIds.length === 0) {
177+
if (currentBlockId) clearCurrentBlock()
178+
} else {
179+
const lastSelectedId = selectedIds[selectedIds.length - 1]
180+
if (lastSelectedId !== currentBlockId) {
181+
setCurrentBlockId(lastSelectedId)
182+
}
182183
}
183184
}
184185

@@ -2477,10 +2478,15 @@ const WorkflowContent = React.memo(
24772478
// Local state for nodes - allows smooth drag without store updates on every frame
24782479
const [displayNodes, setDisplayNodes] = useState<Node[]>([])
24792480

2481+
const selectedNodeIds = useMemo(
2482+
() => displayNodes.filter((node) => node.selected).map((node) => node.id),
2483+
[displayNodes]
2484+
)
2485+
const selectedNodeIdsKey = selectedNodeIds.join(',')
2486+
24802487
useEffect(() => {
2481-
const selectedIds = displayNodes.filter((node) => node.selected).map((node) => node.id)
2482-
syncPanelWithSelection(selectedIds)
2483-
}, [displayNodes])
2488+
syncPanelWithSelection(selectedNodeIds)
2489+
}, [selectedNodeIdsKey])
24842490

24852491
useEffect(() => {
24862492
// Check for pending selection (from paste/duplicate), otherwise preserve existing selection

0 commit comments

Comments
 (0)