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

Cleanup customization interfaces #282

Merged
merged 3 commits into from
Nov 2, 2023

Conversation

rafalcymerys
Copy link
Member

This is a follow-up PR to #276 and #274. I made the following changes:

  1. Made interfaces for builders and tabs/actions more explicit
  2. Unified the interfaces between tabs, actions and menu items
  3. Fixed an issue with i18n, where labels were generated during initialization of the application (so they were always in the default locale, not in user's locale)
  4. Created abstraction around action buttons, so that the customization doesn't need to provide a style css class directly
  5. Merged completed_check in tabs with availability_checks as their semantics seems to be the same

@rafalcymerys rafalcymerys force-pushed the feature/cleanup_customization_interfaces branch from 06a1b23 to 49fcce9 Compare November 1, 2023 11:07
@rafalcymerys rafalcymerys marked this pull request as ready for review November 2, 2023 07:45
Copy link
Contributor

Choose a reason for hiding this comment

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

This file needs to be added to spree_rails_frontend (e.g. in this PR).
Without it, when app is being initialized spree_rails_frontend does not find it and throws:

uninitialized constant Spree::Admin::Actions::ProductPreviewActionBuilder (NameError)
Rails.application.config.spree_backend.actions[:product] = Spree::Admin::Actions::ProductPreviewActionBuilder.new.build

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 posted a draft where I moved the creation and details of that button to spree_rails_frontend - since it should know best how to create a button referring to a preview.

https://github.com/spree/spree_rails_frontend/tree/feature/add_preview_button_to_admin_panel

@@ -37,12 +37,15 @@ class Engine < ::Rails::Engine
Rails.application.config.spree_backend.actions[:users] = Spree::Admin::Actions::UsersDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions[:user] = Spree::Admin::Actions::UserDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions[:products] = Spree::Admin::Actions::ProductsDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions.include?(:images) ? (Rails.application.config.spree_backend.actions[:images].items << Spree::Admin::Actions::ImagesDefaultActionsBuilder.new.build.items).flatten! : Rails.application.config.spree_backend.actions[:images] = Spree::Admin::Actions::ImagesDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions[:product] = Spree::Admin::Actions::Root.new
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any guarantee that the config changes from spree_backend will be executed before the config changes from spree_rails_frontend? 🤔
If yes - then this is ok.
If not - then there's a risk tat Spree::Admin::Actions::Root.new would override the contents that were assigned during the after_initialize in the spree_rails_frontend.

Presumably this can be avoided by having the gems being listed in the Gemfile in a specific order but we have no control over how people compose their Gemfiles.

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 can add a check in spree_rails_frontend, that ensures that spree_backend is initialized first, and if not, throws an exception that tells users what to do :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Another option I was exploring was to run the initialization process in a regular initializer, but due to how preferences are built right now, in order to load routes Spree needs to establish a database connection. I think if we solve this, we could make it independent on the order - this is however something to be fixed on its own separately, unfortunately this looks like a bigger rewrite.

Copy link
Contributor

@tomdonarski tomdonarski left a comment

Choose a reason for hiding this comment

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

Fantastic work! 🥇
So good to have it unified! 😃

@rafalcymerys rafalcymerys merged commit d1a9659 into main Nov 2, 2023
2 checks passed
@delete-merged-branch delete-merged-branch bot deleted the feature/cleanup_customization_interfaces branch November 2, 2023 14:12
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.

2 participants