-
Notifications
You must be signed in to change notification settings - Fork 635
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
Dyn 5497 markdown not loading #13703
Dyn 5497 markdown not loading #13703
Conversation
Adding code for dynamically create virtual directories and load images based in if is a dynamo node or is a package node.
Fix done by Deyan
@@ -132,6 +140,8 @@ public bool ShowBrowser | |||
|
|||
internal UIElement DynamoView { get; set; } | |||
|
|||
internal NodeInfo CurrentNodeInfo { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think carrying around this state is ideal - at the minimum it should have some comments...
I'm not sure if it's possible, but it seems simpler to keep track of where this data is used if it's passed in an event or binding (or something similar) to the View.
Just a thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjkkirschner removed the NodeInfo class and I just added a new internal property, check the next commit:
fdd337c
Can we write a test for this regression? |
what does this mean |
I've removed the NodeInfo class instead I just added the Name property and that one will be used for creating the virtual directory.
It was sending an exception when the md file was not found and the Link is null so I added a try catch (Link != null doesn't work) so the system won't crash and will show the default md file (when documentation is not found).
@mjkkirschner The next Jira task was just created for that purpose. |
@mjkkirschner please confirm that this a list of steps for the test expected for validating this functionality.
|
what about mocking most of that - for example, just set the view model data with some fake data that should come from a package, open the docs browser, and then check that the virtual folder is setup correctly using that data - we just want to ensure it does not regress later. |
/// <summary> | ||
/// Package Name | ||
/// </summary> | ||
internal string Name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a more intuitive name would be PackageName... What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or graph name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@filipeotero yes, I think is a better idea to use PackageName, then updated in the next commit: 0e3c928
The Name property was named to packageName A new test was added that is validating that the virtual folder will be created in the packages/package/doc folder so when the documentation for a node is loaded the images are loaded successfully. Also the code for setting the VirtualFolderPath property was moved before WebView2.EnsureCoreWebView2Async() call because otherwise we were not reaching the code.
@mjkkirschner I've added a unit test for validating that the WebView2 Virtual Directory is created in the right place (so images will be loaded correctly) when displaying documentation for package nodes. When implementing the unit test I found that the call to await WebView2.EnsureCoreWebView2Async() was returning the execution to the unit test (instead of executing the next code), then I had to move the Virtual Folder code creation before EnsureCoreWebView2Async() call also I've added a property for VirtualDirectory so it can be checked in the unit test., please let me know is the test should be enough Here is the commit with the changes: |
{ | ||
if (viewModel.Link != null && !string.IsNullOrEmpty(viewModel.PackageName)) | ||
{ | ||
VirtualFolderPath = HttpUtility.UrlDecode(viewModel.Link.AbsolutePath).Replace(viewModel.PackageName + ".md", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is about getting the package folder, might be better to call Path.GetDirectoryName(HttpUtility.UrlDecode(viewModel.Link.AbsolutePath))
instead of Replace(viewModel.PackageName + ".md", "")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @pinzart90 I've done the change in the next commit: ad5209f
Fixed change for not using hardcoded ".md" when creating the virtual directory
There are some Orchid nodes in the Math category that are receiving a number of parameters variable and seems that node documentation (md files) is not supported for this kind of nodes (DSVarArgFunction), then a fix was applied for loading the package info and md files for this kind of nodes. Also I fixed a test that was replacing slashes but in some cases the slashes were already inverted.
else | ||
VirtualFolderPath = FallbackDirectoryName; | ||
} | ||
catch (Exception ex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exception do you think will be caught here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjkkirschner I found a case that viewModel.Link = "{}"
so it was crashing when trying the next line viewModel.Link.AbsolutePath
so I added this try catch because I didn't found any other way to validate the viewModel.Link
content.
With the fix added related to DSVarArgFunction now I expect that viewModel.Link always will contain something valid but just in case I think we should keep this code or if you have any other idea in how to validate viewModel.Link = "{}"
please let me know (Link is Uri type, Uri.IsWellFormedUriString returns true).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good practice to log something including the exception if possible to the dynamo console - if some unanticipated exception starts showing up here atleast we'll know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjkkirschner I've added some code for logging the exception in the dynamo console, see the next commit: 5980d15
/// <summary> | ||
/// Package Name | ||
/// </summary> | ||
internal string PackageName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it still feels pretty odd to me that the DocumentationBrowserViewModel has a single piece of state like this that it has to hold on to.
If I am understanding correctly, can we at least name it something like:
CurrentPackageName
or something like that and add a comment describing when it will be null and when it will be valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjkkirschner notice that the dependency on PackageName was added in the next PR:
#13414
Renamed to CurrentPackageName in the next commit: f00db5b
@@ -2120,9 +2120,9 @@ internal AssemblyName GetNameOfAssemblyReferencedByNode(NodeModel node) | |||
{ | |||
AssemblyName assemblyName = null; | |||
// Get zerotouch assembly | |||
if (node is DSFunction) | |||
if (node is DSFunction || node is DSVarArgFunction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unnecessary, is
will check that the instance inherits from the type in question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am incorrect, DSVarArgFunction
inherits from DSFunctionBase
not DSFunction
- apologies for the confusion.
{ | ||
var descriptor = (node as DSFunction).Controller.Definition; | ||
var descriptor = node is DSFunction function ? function.Controller.Definition : (node as DSVarArgFunction).Controller.Definition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get rid of all these cases and the if statement above - just check if the type is DSFunctionBase
- it has a Controller.Definition
property you can access and you don't need to check any types, it's safer an faster - unless you need special behavior for each type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if is DSFunctionBase type I've simplified the code in the next way:
Please let me know if it sounds good to you. Thanks
commit: f00db5b
|
||
docBrowserviewExtension.HandleRequestOpenDocumentationLink(nodeAnnotationEventArgs); | ||
var htmlContent = GetSidebarDocsBrowserContents(); | ||
htmlContent = htmlContent.Replace(@"%5C", "/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment, please check the next commit: f00db5b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see inline comments
Renaming PackageName to CurrentPackageName. Rewriting code for loading documentation correctly for DSVarArgFunction nodes Adding comments to the test
thanks @RobertGlobant20 ! |
Adding log in case we reach the exception when the Uri is empty.
Thanks for addressing the review comments @RobertGlobant20 I will merge the PR as soon as the self serve job completes |
|
@RobertGlobant20 seems there is a conflicted file. |
Purpose
Fixing bug about markdown files not loading for node packages documentation.
There was a code change that was preventing for loading md files for packages node documentation, so after this fix was done in a different pull request (#13693), now it is loading the md file but the images were not loading due that WebView2 was using virtual folder fixed to fallback_docs folder then in this fix we are allowing to create the virtual folder dynamic depending if is a dynamo node or package node.
For some nodes of the Orchid package is working there is another bug with some specific nodes (like Math.Addition).
Declarations
Check these if you believe they are true
*.resx
filesRelease Notes
Fixing bug about markdown files not loading for node packages documentation.
Reviewers
@QilongTang @reddyashish @dnenov
FYIs