10000 [PoC] Resource operations by loic425 · Pull Request #17695 · Sylius/Sylius · GitHub
[go: up one dir, main page]

Skip to content

[PoC] Resource operations #17695

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

Draft
wants to merge 1 commit into
base: 2.1
Choose a base branch
from
Draft

Conversation

loic425
Copy link
Member
@loic425 loic425 commented Feb 26, 2025
Q A
Branch? 2.1
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
License MIT

Linked to Sylius/SyliusResourceBundle#983

@loic425 loic425 requested review from a team as code owners February 26, 2025 08:49
@probot-autolabeler probot-autolabeler bot added the Admin AdminBundle related issues and PRs. label Feb 26, 2025
@loic425 loic425 marked this pull request as draft February 26, 2025 08:49
Copy link
coderabbitai bot commented Feb 26, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

sylius_resource:
mapping:
imports:
- "%kernel.project_dir%/src/Sylius/Bundle/AdminBundle/Resources/config/app/sylius/resources"
Copy link
Member Author
@loic425 loic425 Feb 26, 2025

Choose a reason for hiding this comment

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

Of course, this needs to be fixed.
It should be @SyliusAdminBundle/Resources/config/app/sylius/resources

We should also configure this on another config file to provide a bc-layer.
Routes will still be built with ResourceController system by default on 2.x and should be removed on 3.x.

@loic425 loic425 self-assigned this Feb 26, 2025
@loic425 loic425 force-pushed the poc/resource-operations branch from b25573c to a365750 Compare February 27, 2025 13:35
@loic425 loic425 force-pushed the poc/resource-operations branch 2 times, most recently from 6723998 to d81a730 Compare March 3, 2025 09:45
Copy link
github-actions bot commented Mar 3, 2025

✅ Preview Environment deployed on Bunnyshell

Component Endpoints
mailhog https://mailhog-zdivhy.bunnyenv.com/
php https://store-zdivhy.bunnyenv.com/

See: Environment Details | Pipeline Logs

Available commands:

  • 🔴 /bns:stop to stop the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@loic425 loic425 force-pushed the poc/resource-operations branch from d81a730 to c742165 Compare June 10, 2025 15:24
@loic425 loic425 force-pushed the poc/resource-operations branch 2 times, most recently from 90988a1 to 7814307 Compare June 18, 2025 07:08
@loic425 loic425 force-pushed the poc/resource-operations branch from 7814307 to 694f23e Compare June 30, 2025 11:48
use Sylius\Resource\Metadata\Operations;
use Sylius\Resource\Metadata\ResourceMetadata;

return (new ResourceMetadata())
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 one has a small issue on the browser title.
image

@loic425 loic425 force-pushed the poc/resource-operations branch 4 times, most recently from de977b6 to 1655d6b Compare June 30, 2025 14:43
@probot-autolabeler probot-autolabeler bot added the Maintenance CI configurations, READMEs, releases, etc. label Jun 30, 2025
@loic425 loic425 force-pushed the poc/resource-operations branch 3 times, most recently from c1d3124 to 89075d5 Compare July 1, 2025 10:07
try {
$this->indexPage->deleteResourceOnPage(['code' => $productVariant->getCode()]);
} catch (ResourceDeleteException $exception) {
$this->sharedStorage->set('last_exception', $exception);
Copy link
Member Author

Choose a reason for hiding this comment

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

The error message is still ok.
image

@loic425 loic425 force-pushed the poc/resource-operations branch 4 times, most recently from efb4fe7 to 5f37500 Compare July 2, 2025 08:14
@@ -34,6 +36,7 @@ public function __construct(
private readonly UpdatePageInterface $updatePage,
private readonly FormElementInterface $formElement,
private readonly NotificationCheckerInterface $notificationChecker,
private SharedStorageInterface $sharedStorage,
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
private SharedStorageInterface $sharedStorage,
private readonly SharedStorageInterface $sharedStorage,

use Sylius\Resource\Metadata\Update;

return (new ResourceMetadata())
->withRoutePrefix('/admin')
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the parameter instead:

Suggested change
->withRoutePrefix('/admin')
->withRoutePrefix('/%sylius_admin.path_name%')

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for every admin resource definition.

->withRoutePrefix('/admin')
->withClass('%sylius.model.admin_user.class%')
->withSection('admin')
->withTemplatesDir('@SyliusAdmin\\shared\\crud')
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this a lot but Symfony can handle both / and \ format.

To avoid using too many chars this can be simplified like this:

Suggested change
->withTemplatesDir('@SyliusAdmin\\shared\\crud')
->withTemplatesDir('@SyliusAdmin/shared/crud')

Same for the rest of the resource definitions

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree.

return (new ResourceMetadata())
->withRoutePrefix('/admin')
->withClass('%sylius.model.admin_user.class%')
->withSection('admin')
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 This can be transform to a class constant or a parameter one day

Copy link
Contributor

Choose a reason for hiding this comment

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

Could also somehow be joined w/ the SectionInterface objects. That'd probably necessitate moving the interface to ResourceBundle, but ultimately should ease resolving and basing some logic on specific sections.
Food for thought.

formType: ProductGenerateVariantsType::class,
notificationMessage: 'sylius.product_variant.generate',
redirectToRoute: 'sylius_admin_product_variant_index',
redirectArguments: ['productId' => "request.attributes.get('productId')"],
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a notation used to specify that the value has to be interpreted, why in this case we are not using :

Suggested change
redirectArguments: ['productId' => "request.attributes.get('productId')"],
redirectArguments: ['productId' => "@=request.attributes.get('productId')"],

Copy link
Member Author
@loic425 loic425 Jul 4, 2025

Choose a reason for hiding this comment

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

currently here, we can only have an expression.
So, we need to

  • allow this extra characters like you did here..
  • deprecate using expresion without using "@="
  • allow simple strings

new Create(redirectToRoute: 'sylius_admin_taxon_update'),
new Create(
path: 'taxons/new/{id}',
template: '@SyliusAdmin/shared/crud/create.html.twig',
Copy link
Contributor

Choose a reason for hiding this comment

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

If the resource use : @SyliusAdmin/shared/crud as templateDir is this template required ?

Copy link
Member Author
@loic425 loic425 Jul 4, 2025

Choose a reason for hiding this comment

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

I need to check that one. I think it uses the short name of the operation.

Comment on lines +1 to +13
#sylius_admin_admin_user:
# resource: |
# alias: sylius.admin_user
# section: admin
# path: users
# templates: "@SyliusAdmin\\shared\\crud"
# except: ['show']
# redirect: index
# grid: sylius_admin_admin_user
# form:
# type: Sylius\Bundle\AdminBundle\Form\Type\AdminUserType
# permission: true
# type: sylius.resource
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move all route resource to a dedicated file, so we can migrate resources one by one?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we cannot move routing files. The file is public, so we can break things.
I need to test routing condition to bring a bc-layer with that kind of thing
https://github.com/monsieurbiz/SyliusCmsPagePlugin/blob/8cc79bf5e0a3b66799868ad4ff7e13086f80b347/src/Routing/RequestContext.php#L42

@loic425 loic425 force-pushed the poc/resource-operations branch 3 times, most recently from 4eeac1b to c75eba4 Compare July 7, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin AdminBundle related issues and PRs. Maintenance CI configurations, READMEs, releases, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0