| 211 | }; |
| 212 | |
| 213 | function toggleNode(node: GraphNode) { |
| 214 | const data = node.data as GraphNodeData; |
| 215 | if (data.kind === "entity") { |
| 216 | const isExpanded = expandedEntityIdsRef.current.has(node.id); |
| 217 | setExpandedEntityIds((current) => { |
| 218 | const next = new Set(current); |
| 219 | if (isExpanded) { |
| 220 | next.delete(node.id); |
| 221 | } else { |
| 222 | next.add(node.id); |
| 223 | } |
| 224 | return next; |
| 225 | }); |
| 226 | if (isExpanded) { |
| 227 | const relatedEventIds = new Set(eventIdsByEntityId.get(node.id) ?? []); |
| 228 | setExpandedEventIds((current) => { |
| 229 | const next = new Set(current); |
| 230 | for (const eventId of relatedEventIds) { |
| 231 | next.delete(eventId); |
| 232 | } |
| 233 | return next; |
| 234 | }); |
| 235 | } |
| 236 | return; |
| 237 | } |
| 238 | setExpandedEventIds((current) => { |
| 239 | const next = new Set(current); |
| 240 | if (expandedEventIdsRef.current.has(node.id)) { |
| 241 | next.delete(node.id); |
| 242 | } else { |
| 243 | next.add(node.id); |
| 244 | } |
| 245 | return next; |
| 246 | }); |
| 247 | } |
| 248 | |
| 249 | function clearClickTimer() { |
| 250 | if (clickTimerRef.current == null) { |