Skip to content
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

Insert unique GUIDs update #13751

Merged
merged 7 commits into from
Feb 21, 2023

Conversation

dnenov
Copy link
Collaborator

@dnenov dnenov commented Feb 15, 2023

Purpose

This PR addresses an outstanding issue with the Insert functionality introduced a while back. Previously, it wasn't possible for users to insert the same graph or derivatives of the same graph inside the workspace. That was due to the identical GUIDs present in the graphs (attached current state of affairs comparison between 3 derivative dynamo graphs).

Logic to recreate all element GUIDs that make up the workspace prior to inserting them into the current workspace is introduced with this PR to handle these cases.

Side-by-side derivative comparison

Insert

Insert multiple of the same

insert_multiple

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Release Notes

  • assign new GUIDs for all workspace elements
  • now correctly inserts groups and notes
  • now correctly inserts pinned notes
  • added new tests for Insert functionality
  • change to old test to account for the ability to insert multiple of the same graph

Reviewers

@QilongTang
@mjkkirschner
@Amoursol

FYIs

@sm6srw

- assign new GUIDs for all elements
- initial workflow, to be optimized and tested
- now correctly inserts groups and notes
- now correctly inserts pinned notes
- code refactor
- created a separate region for all the new code related to the Insert functionality
- added 2 new tests for Insert functionality
- change old test to account for the ability to insert multiple of the same graph
- removed unused method inside the Insert function
src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs Outdated Show resolved Hide resolved
/// <param name="nodesGuids">Nodes [old,new] GUID values</param>
/// <param name="notesGuids">Annotations [old,new] GUID values</param>
/// <param name="connectorsGuids">Connectors [old,new] GUID values</param>
private void PropagateUpdatesToViewInfo(ExtraWorkspaceViewInfo viewInfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this function, it seems we are only replacing Guids, I feel the function maybe can be simplified further. After some deeper look, it seems these elements do not share same interface, we cant really write utility method to avoid repeating code. So good for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same, but they are ever so slightly different to make me not do it. They do share the same base class, but that class does not have the GUID we are after. Also, the GUID is sometimes a Guid, sometimes a string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All code is now reworked in favor of a much simpler method that operates directly on the json string, as discussed on Friday. It works great to on my side, but let me know if that's not ideal for whatever reason and I can update as needed.

@QilongTang QilongTang added this to the 2.18.0 milestone Feb 17, 2023
@QilongTang QilongTang marked this pull request as ready for review February 17, 2023 17:18
@QilongTang
Copy link
Contributor

LGTM with couple comments

src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs Outdated Show resolved Hide resolved
src/DynamoCore/Models/DynamoModel.cs Outdated Show resolved Hide resolved
src/DynamoCore/Models/DynamoModel.cs Outdated Show resolved Hide resolved
src/DynamoCore/Models/DynamoModel.cs Outdated Show resolved Hide resolved
src/DynamoCore/Models/DynamoModel.cs Outdated Show resolved Hide resolved

// Assign new annotation models new GUIDs
// We need two separate runs to first create the new GUIDs and second work with the new GUIDS
if (notes != null)
Copy link
Member

@mjkkirschner mjkkirschner Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this entire approach a bit complicated...

I am just curious what you think of an approach that modifies the json. I would usually shy away from that approach but I believe you could select all IDS BEFORE deserialization or as jtokens and transform them...

I think it would be much less code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Great call and while I didn't get the idea immediately, I tested it today and it works great and simplifies this whole thing. Committed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if that doesn't look good to you and I will rework as needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjkkirschner Previously I feel the approach was OK also because we have another task to update Guids while Dynamo users save the current workspace as a new one, then a JSON block of the graph is not guaranteed to be there for a simplified approach. But after second thought, if this approach is preferred, maybe we can do the same for save as - touch the JSON instead of in-memory workspace representation.

Assert.AreEqual(currentCount * 2, updatedCount);
}

[Test]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these tests cover ALL your new methods? It would be good to cover each new method you add with a unit test.

Copy link
Collaborator Author

@dnenov dnenov Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 things to worry about, the way I see it:

  • the Nodes being appropriately inserted, and us being able to get them over and over again
  • the Groups working correctly, both nested and non-nested
  • the Notes are working correctly, both pinned and not pinned
    I think these tests cover the scenarios above. I can try adding unit tests too though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will follow up on save as in a new PR and add test as well

- code rework to massively reduce the logic of updating the Guids of the inserted workspace
- more detail explanation to why the Guid update is necessary
@QilongTang QilongTang merged commit 5570cde into DynamoDS:master Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants