-
Notifications
You must be signed in to change notification settings - Fork 5
Fix tree cross-tab navigation : sync tree model globally #3831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,11 +7,20 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import type { UUID } from 'node:crypto'; | ||||||||||||||||||||||||||||||
| import type { NodeSelectionForCopy } from 'redux/reducer.type'; | ||||||||||||||||||||||||||||||
| import type { NodeCreatedEventData, NodeMovedEventData } from 'types/notification-types'; | ||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||
| NodeCreatedEventData, | ||||||||||||||||||||||||||||||
| NodeMovedEventData, | ||||||||||||||||||||||||||||||
| NodesColumnPositionsChangedEventData, | ||||||||||||||||||||||||||||||
| StudyUpdateEventData, | ||||||||||||||||||||||||||||||
| } from 'types/notification-types'; | ||||||||||||||||||||||||||||||
| import { NotificationType } from 'types/notification-types'; | ||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||
| networkModificationHandleSubtree, | ||||||||||||||||||||||||||||||
| networkModificationTreeNodeAdded, | ||||||||||||||||||||||||||||||
| networkModificationTreeNodeMoved, | ||||||||||||||||||||||||||||||
| networkModificationTreeNodesRemoved, | ||||||||||||||||||||||||||||||
| networkModificationTreeNodesUpdated, | ||||||||||||||||||||||||||||||
| reorderNetworkModificationTreeNodes, | ||||||||||||||||||||||||||||||
| } from '../redux/actions'; | ||||||||||||||||||||||||||||||
| import type { AppDispatch } from '../redux/store'; | ||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||
|
|
@@ -97,3 +106,63 @@ export const fetchAndHandleSubtree = ( | |||||||||||||||||||||||||||||
| dispatch(networkModificationHandleSubtree(nodes, parentNode)); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const fetchAndDispatchUpdatedNodes = ( | ||||||||||||||||||||||||||||||
| dispatch: AppDispatch, | ||||||||||||||||||||||||||||||
| studyUuid: UUID, | ||||||||||||||||||||||||||||||
| rootNetworkUuid: UUID, | ||||||||||||||||||||||||||||||
| nodeIds: UUID[] | ||||||||||||||||||||||||||||||
| ): void => { | ||||||||||||||||||||||||||||||
| Promise.allSettled( | ||||||||||||||||||||||||||||||
| nodeIds.map((nodeId) => fetchNetworkModificationTreeNode(studyUuid, nodeId, rootNetworkUuid)) | ||||||||||||||||||||||||||||||
| ).then((results) => { | ||||||||||||||||||||||||||||||
| const values = results.flatMap((result) => (result.status === 'fulfilled' ? [result.value] : [])); | ||||||||||||||||||||||||||||||
| if (values.length > 0) { | ||||||||||||||||||||||||||||||
| dispatch(networkModificationTreeNodesUpdated(values)); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export const handleTreeModelUpdate = ( | ||||||||||||||||||||||||||||||
| dispatch: AppDispatch, | ||||||||||||||||||||||||||||||
| studyUuid: UUID, | ||||||||||||||||||||||||||||||
| rootNetworkUuid: UUID, | ||||||||||||||||||||||||||||||
| eventData: StudyUpdateEventData | ||||||||||||||||||||||||||||||
| ): void => { | ||||||||||||||||||||||||||||||
| switch (eventData.headers.updateType) { | ||||||||||||||||||||||||||||||
| case NotificationType.NODE_BUILD_STATUS_UPDATED: | ||||||||||||||||||||||||||||||
| if (eventData.headers.rootNetworkUuid !== rootNetworkUuid) break; | ||||||||||||||||||||||||||||||
| fetchAndDispatchUpdatedNodes(dispatch, studyUuid, rootNetworkUuid, eventData.headers.nodes); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.NODE_CREATED: | ||||||||||||||||||||||||||||||
| fetchAndDispatchAddedNode(dispatch, studyUuid, rootNetworkUuid, eventData as NodeCreatedEventData); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.SUBTREE_CREATED: | ||||||||||||||||||||||||||||||
| fetchAndHandleSubtree(dispatch, studyUuid, eventData.headers.newNode, eventData.headers.parentNode); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.NODE_MOVED: | ||||||||||||||||||||||||||||||
| fetchAndDispatchMovedNode(dispatch, studyUuid, rootNetworkUuid, eventData as NodeMovedEventData); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.SUBTREE_MOVED: | ||||||||||||||||||||||||||||||
| fetchAndHandleSubtree(dispatch, studyUuid, eventData.headers.movedNode, eventData.headers.parentNode); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.NODES_COLUMN_POSITION_CHANGED: { | ||||||||||||||||||||||||||||||
| const { headers, payload } = eventData as NodesColumnPositionsChangedEventData; | ||||||||||||||||||||||||||||||
| dispatch(reorderNetworkModificationTreeNodes(headers.parentNode, JSON.parse(payload))); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+149
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap If 🛡️ Proposed defensive fix case NotificationType.NODES_COLUMN_POSITION_CHANGED: {
const { headers, payload } = eventData as NodesColumnPositionsChangedEventData;
- dispatch(reorderNetworkModificationTreeNodes(headers.parentNode, JSON.parse(payload)));
+ try {
+ dispatch(reorderNetworkModificationTreeNodes(headers.parentNode, JSON.parse(payload)));
+ } catch (e) {
+ console.warn('NODES_COLUMN_POSITION_CHANGED: failed to parse payload', e);
+ }
break;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| case NotificationType.NODES_DELETED: | ||||||||||||||||||||||||||||||
| dispatch(networkModificationTreeNodesRemoved(eventData.headers.nodes)); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.NODES_UPDATED: | ||||||||||||||||||||||||||||||
| fetchAndDispatchUpdatedNodes(dispatch, studyUuid, rootNetworkUuid, eventData.headers.nodes); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| case NotificationType.NODE_EDITED: | ||||||||||||||||||||||||||||||
| fetchNetworkModificationTreeNode(studyUuid, eventData.headers.node, rootNetworkUuid).then((node) => | ||||||||||||||||||||||||||||||
| dispatch(networkModificationTreeNodesUpdated([node])) | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
|
Comment on lines
+132
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filter root-scoped events before mutating the active tree. The store only holds the tree for the current root network, but this centralized handler now runs for every study notification and only the build-status branch checks 🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tree is shared across all root networks by design these events correctly apply globally. Only NODE_BUILD_STATUS_UPDATED is per-root-network-scoped, and it is already filtered There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
✏️ Learnings added
|
||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.