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

Avoid cloning the AutoroutePart pattern in the localized content #15810

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

hishamco
Copy link
Member

@hishamco hishamco commented Apr 23, 2024

Fixes #15805

Summary by CodeRabbit

  • New Features

    • Enhanced content localization by automatically regenerating permalinks when localizing content.
    • Expanded service configurations to support new localization features across content culture pickers and sitemaps.
  • Refactor

    • Introduced new handlers and services for improved content localization management.
  • Documentation

    • Updated project references to support new localization functionalities.

@hishamco
Copy link
Member Author

There's might be a better solution, but this the quick one that I go with, @MichaelPetrinolis could you please try the PR

Copy link
Contributor

@MichaelPetrinolis MichaelPetrinolis left a comment

Choose a reason for hiding this comment

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

If adding a dependency to Autoroute Core is ok, clearing the autoroutepart path does the job. Either it is draftable or not, the localized version has empty path and the user is able to update eg. the localized title and create a localized route. Thanx!

@hishamco
Copy link
Member Author

I tried to avoid depending on OC.Autoroute module, but still looking for a better solution if there's

/cc @Skrypt

@hishamco
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Apr 24, 2024

Walkthrough

Walkthrough

The update involves improving the content localization process in OrchardCore by automatically regenerating permalinks when content is localized. This enhancement ensures that the autoroute path is correctly handled during localization, addressing a specific issue related to culture names in the path pattern.

Changes

File Path Change Summary
.../DefaultContentLocalizationManager.cs Added logic to clear AutoroutePart path for permalink regeneration during content localization.
.../OrchardCore.ContentLocalization.csproj Added a project reference to OrchardCore.Autoroute.Core.csproj to support the new localization functionality.
.../AutoPartContentLocalizationHandler.cs Introduced a new class AutoPartContentLocalizationHandler implementing IContentLocalizationHandler methods.
.../Startup.cs Various changes including namespace additions and method modifications to support content localization features.

Assessment against linked issues

Objective Addressed Explanation
Content Localization Autoroute problem with culture name in path (#15805) The changes address the issue by enhancing the content localization process to handle autoroute paths correctly.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hishamco
Copy link
Member Author

Seems coderabbitai ignores my PR :)

@Piedone
Copy link
Member

Piedone commented Apr 24, 2024

Hmm, it seems it didn't actually do a review. I've asked the CR team about this.

@hishamco
Copy link
Member Author

hishamco commented May 1, 2024

@MichaelPetrinolis the new update might much better

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Out of diff range and nitpick comments (1)
src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/AutoPartContentLocalizationHandler.cs (1)

11-19: The logic to clear the AutoroutePart path is correctly implemented to support automatic permalink regeneration.

Consider adding a comment explaining why the path is set to null, for future maintainability.

@hishamco hishamco requested a review from Piedone May 2, 2024 10:49
@hishamco hishamco requested a review from Piedone May 2, 2024 16:49
@hishamco hishamco requested a review from Piedone May 2, 2024 17:42
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't fix the issue:

2024-05-02_20h06_41.mp4

Copy link
Member Author

@hishamco hishamco May 2, 2024

Choose a reason for hiding this comment

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

Please try it without your last suggestion - Using Alter - I'm 100% percentage sure it was working as expected

Copy link
Member Author

Choose a reason for hiding this comment

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

This is weird I don't know why the

context.ContentItem.Alter<AutoroutePart>(p => p.Path = null);

doesn't work as expected here?!! Do you have any idea or shall I revert the last change

Copy link
Member

Choose a reason for hiding this comment

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

That's good, but please make it work in a statically typed way. We don't need dynamic for this.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know, sorry, I'd also need to get into debugging this to figure it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

We might need to revise this, using CloningAsync() might resolve the issue but not make sense while LocalizingAsync() should be the suited event for that

Copy link
Member

Choose a reason for hiding this comment

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

if that is the case, then call _session.SaveAsync() after calling LocalizingAsync. But honestly, this sounds like a bad idea to me. IContentHandler should be the right event to hook into at that point. LocalizingAsync should not be used to alter the content item.

Copy link
Member Author

Choose a reason for hiding this comment

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

LocalizingAsync should not be used to alter the content item.

For that I alert the autoroute path without using Alter() just to solve the above issue

Copy link
Member

Choose a reason for hiding this comment

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

Can you create a test case for the Alter method to make sure STJ isn't causing a problem? Alter should work.

Copy link
Member Author

@hishamco hishamco May 3, 2024

Choose a reason for hiding this comment

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

This is #15714 a recent PR that I merged, the Alter was working fine

@MikeAlhayek
Copy link
Member

@hishamco is this something you want to finish up soon? The longer these PR's stay open the higher the change for conflicts (like the one I just fixed). Also, the longer this take, the less interest from reviewers you'll get in your PRs. I suggest addressing and following up on these PR, otherwise close them.

@hishamco
Copy link
Member Author

hishamco commented Jun 6, 2024

AFAIK this is ready, but sometimes it happens due the review that's why I mentioned some points in the Discord, in the maintainer channel, seems you are not there yet

@Piedone
Copy link
Member

Piedone commented Jun 6, 2024

This is waiting for you. I commented that the code, which is still the current one doesn't work: https://github.com/OrchardCMS/OrchardCore/pull/15810/files#r1588088481 Mike also had follow-up comments. Once you fix it, please re-request review. There are also build errors now BTW.

@hishamco
Copy link
Member Author

hishamco commented Jun 6, 2024

There are also build errors now BTW

I just noticed that, seems this happen after merging main

@hishamco
Copy link
Member Author

FYI both of Mike's suggestions in the comment don't work, so the current implementation is working as expected

@hishamco
Copy link
Member Author

hishamco commented Jun 17, 2024

Autoroute.mp4

@hishamco hishamco requested a review from Piedone June 17, 2024 07:20
@Piedone
Copy link
Member

Piedone commented Jun 17, 2024

We still shouldn't have to use dynamic for this. Any changes to the part can cause a compilation error that we won't notice until runtime.

@hishamco
Copy link
Member Author

We already use dynamic in many places, BTW I tried all the possible solutions without luck :( feel free to commit if you have a suggestion

@Piedone
Copy link
Member

Piedone commented Jun 17, 2024

Yes, and we shouldn't use dynamic anywhere where better options are available.

@hishamco
Copy link
Member Author

So what's the better option here? This PR stays long, let us finalize it before you go into your vacation :)

@Piedone
Copy link
Member

Piedone commented Jun 17, 2024

Alter, as you attempted, figuring out why it didn't work for you.

@hishamco
Copy link
Member Author

I already tried many times without luck, and I will try one more time, otherwise let us accept this while it fixes a real issue then we could revise the places that we are using dynamic in the future

Copy link
Contributor

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

@MikeAlhayek
Copy link
Member

for instructions on how to resolve the merge conflicts due to #16572 please follow the step listed in this comment.

Copy link
Contributor

It seems that this pull request didn't really move for quite a while. Is this something you'd like to revisit any time soon or should we close? Please comment if you'd like to pick it up.

@github-actions github-actions bot added the stale label Oct 14, 2024
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.

Content Localization Autoroute problem with culture name in path
4 participants