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

Add SelectNode and Remove method to JsonDynamicObject class #15509

Merged
merged 21 commits into from
Mar 24, 2024

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Mar 14, 2024

try to fix #15505

@hyzx86 hyzx86 changed the title try fix #15505 and #15497 add SelectNode and Remove method on JsonDynamicObject class Mar 14, 2024
@hyzx86 hyzx86 changed the title add SelectNode and Remove method on JsonDynamicObject class Add SelectNode and Remove method on JsonDynamicObject class Mar 14, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 14, 2024

Hi @hishamco @MikeAlhayek

Since the Content property could be of type JsonDynamicObject or JsonObject, do we need to migrate all functions that can be called from JsonObject here?

[JsonIgnore]
public dynamic Content => _dynamicObject ??= Data;
[JsonIgnore]
internal JsonObject Data { get; set; }

@hyzx86 hyzx86 changed the title Add SelectNode and Remove method on JsonDynamicObject class Add SelectNode and Remove method to JsonDynamicObject class Mar 14, 2024
@hyzx86

This comment was marked as off-topic.

@hyzx86 hyzx86 requested a review from hishamco March 14, 2024 14:21
@hyzx86 hyzx86 mentioned this pull request Mar 14, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 14, 2024

This PR can't to fix #15497 , because there was a logical error in the last change


// Couldn't find targeted menu item.
if (menuItem == null)
{
return NotFound();
}

menu.Content.Remove(menuItemId);
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to change the code if Remove is added in this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem here is not because of the Remove function, because menu.Content is a document object, so we can not directly remove a MenuItem from the document object based on the menuId
The code on the main branch here is wrong

@sebastienros
Copy link
Member

Fixes #15497 too?

@sebastienros sebastienros added this to the 1.9 milestone Mar 14, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 14, 2024

Fixes #15497 too? 

Yes , I have merged @hishamco 's PR

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@hishamco
Copy link
Member

Please resolve the conflict

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 22, 2024

@hyzx86 please resolve the conflict so we can merge this after @sarahelsaig approval

Resolved

Copy link
Contributor

@sarahelsaig sarahelsaig left a comment

Choose a reason for hiding this comment

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

Please only request a review when the checks are successful. You have these errors:
image

Also you didn't address this: https://github.com/OrchardCMS/OrchardCore/pull/15509/files/2e877408abb79e7f6613ce5a091cf918bb99d758#r1534515122

@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 22, 2024

@sarahelsaig updated .

@Piedone
Copy link
Member

Piedone commented Mar 22, 2024

Given that #15524 was merged, is this still needed?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 23, 2024

Given that #15524 was merged, is this still needed?

Yes, the PR just modify JsonObject. SelectNode function implementation, here will repair some direct call ContentItem.Content.Remove and ContentItem.Content.SelectNode

@@ -41,6 +41,10 @@ public class JsonDynamicArray : DynamicObject, IEnumerable<JsonNode?>
}
}

public bool Remove(JsonNode? item) => _jsonArray.Remove(item);
Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned Please update _dictionary in JsonDynamicArray.Remove as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@hyzx86 hyzx86 requested a review from sarahelsaig March 24, 2024 14:23
@hyzx86 hyzx86 requested a review from hishamco March 24, 2024 16:15
@hishamco
Copy link
Member

@sarahelsaig waiting for your approval if everything looks good for you

Copy link
Contributor

@sarahelsaig sarahelsaig left a comment

Choose a reason for hiding this comment

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

LGTM

@hishamco
Copy link
Member

@MikeAlhayek is there anything to add or shall we merge this

@MikeAlhayek
Copy link
Member

Merge it

@hishamco hishamco merged commit ba718ab into OrchardCMS:main Mar 24, 2024
4 checks passed
@hyzx86 hyzx86 deleted the fix_ContentActions branch June 13, 2024 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent JObject.SelectNode() behavior and feature loss
6 participants