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

Support the new starter frontend installation #276

Merged
merged 3 commits into from
Jan 11, 2023

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Jan 5, 2023

Summary

This works out of the box only for a fresh installation of the starter frontend because we can't anticipate what changed in each storefront, but should be a good starting point.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.
  • I have opened a PR to update the guides.
  • I have updated the README to account for my changes.

@kennyadsl kennyadsl self-assigned this Jan 5, 2023
@kennyadsl kennyadsl force-pushed the kennyadsl/support-starter-frontend branch from c65773f to 485b404 Compare January 5, 2023 14:30
@@ -15,6 +16,30 @@ def add_javascripts
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n"
end

def copy_starter_frontend_files
return if options[:frontend] != 'starter'
Copy link

Choose a reason for hiding this comment

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

imho return unless options[:frontend] == 'starter' is better for readability

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestions @Naokimi. I tend to use unless only when the condition doesn't contain a negation, that's because it would be a double negation, IMO, always harder to read. I think I took this reasoning line from this blog post years ago: https://signalvnoise.com/posts/2699-making-sense-with-rubys-unless. BTW, I'm open to invert it, let me know your thoughts.

Copy link

@Naokimi Naokimi Jan 9, 2023

Choose a reason for hiding this comment

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

yeah, I'm also of the school that you should avoid negations as much as possible, so since return if options[:frontend] != 'starter' contains a negation (NOT equal to) I'm suggesting removing the negation (-> equal to) while using unless

but in any case in this specific case what you wrote is still readable enough, so it wouldn't be a big deal to leave it as it is

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you are right. Personally, I still prefer the negation to be on the condition, so I think I'll leave it as is for now. But appreciate the conversation around this topic. Thanks again!

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @kennyadsl. I left some comments. Interested in your thoughts.

@@ -6,6 +6,7 @@ class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)

class_option :auto_run_migrations, type: :boolean, default: false
class_option :frontend, type: :string, default: 'legacy'
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use the 'legacy' value anywhere. What about following the same pattern that @elia used in solidus_paypal_commerce_platform and, instead, have a starter_frontend boolean option?

Copy link
Member

Choose a reason for hiding this comment

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

Using a string instead of a boolean looks better to me, since more things could end up being frontends (api, graphql, etc) and being able to select the right integration seems like a better choice.

Anyways the name is classic in the solidus installer, and I'm fine with both fixing it or moving it to a boolean, we can change later if necessary 👍

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 used this format to follow the main installer. For sure I should at least change legacy to classic to follow that convention. Not sure which approach is best at this point, @elia do you have any thought?

Copy link
Member

Choose a reason for hiding this comment

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

I think we posted at the same time, but I'll restate my take: while right now I see using a string as the way forward I'm fine with both.

I other words I think we'll have a better understanding on how things "should be done" in a month or two, and we'll be able to codify it somewhere (e.g. in solidus_dev_support).

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to classic, but open to change while I wait for @waiting-for-dev opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also thought about the potential for adding new storefronts. However, I see it as a premature optimization, plus we won't add any other new frontend in the near future. Having code that does nothing looks off. We've been discussing whether to call it classic or legacy, but we could call it potato, and it'd make no difference 😆 But I'm not super-against it, as it could help in the future to avoid breaking changes. However, I'd try to be consistent throughout the extension ecosystems, so we should do the same here and in the PayPal one.

README.md Show resolved Hide resolved
RUBY
end
insert_into_file 'app/controllers/cart_line_items_controller.rb', after: "private\n" do
<<-RUBY.strip_heredoc.indent(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same suggestion to use Ruby's built-in heredoc syntax to remove indentation.

<<-RUBY.strip_heredoc.indent(2)

include SolidusSubscriptions::SubscriptionLineItemBuilder
after_action :handle_subscription_line_items, only: :create, if: ->{ params[:subscription_line_item] }
Copy link
Contributor

Choose a reason for hiding this comment

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

What about moving the injected code to a module and including that module in the host application? That would make it less brittle to installations that have already been modified.

Copy link
Member

Choose a reason for hiding this comment

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

@waiting-for-dev I'm not sure I understand, looks like it's already in a module being injected in the host application, what am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wonderful idea, working on it

Copy link
Member Author

Choose a reason for hiding this comment

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

@elia I'm working on a concern (that will be copied along to the host app), so that its inclusion is the only thing we inject in the controller.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see thanks 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed a new version that uses a Rails concern, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Member

@elia elia left a comment

Choose a reason for hiding this comment

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

Awesome!
I hope we'll be able to also add testing soon, but for now this is great!

pending the nits pointed out in other reviews

@@ -6,6 +6,7 @@ class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)

class_option :auto_run_migrations, type: :boolean, default: false
class_option :frontend, type: :string, default: 'legacy'
Copy link
Member

Choose a reason for hiding this comment

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

Using a string instead of a boolean looks better to me, since more things could end up being frontends (api, graphql, etc) and being able to select the right integration seems like a better choice.

Anyways the name is classic in the solidus installer, and I'm fine with both fixing it or moving it to a boolean, we can change later if necessary 👍

<<-RUBY.strip_heredoc.indent(2)

include SolidusSubscriptions::SubscriptionLineItemBuilder
after_action :handle_subscription_line_items, only: :create, if: ->{ params[:subscription_line_item] }
Copy link
Member

Choose a reason for hiding this comment

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

@waiting-for-dev I'm not sure I understand, looks like it's already in a module being injected in the host application, what am I missing?

@kennyadsl kennyadsl force-pushed the kennyadsl/support-starter-frontend branch from 0436be2 to 6a2ba92 Compare January 9, 2023 10:54
This works out of the box only for fresh install of the
starter frontend because we can't anticipate what changed
in each storefront, but should be a good starting point.
This way they will be loaded only when solidus_frontend
is in use.
Auth devise is already installed with the new storefront, so
we can remove a couple of options from solidus:install and the
inclusion of the gem in the sandbox Gemfile.

Also, we can remove enforce_available_locales, which is deprecated.
@kennyadsl kennyadsl force-pushed the kennyadsl/support-starter-frontend branch from 6a2ba92 to a1a2c0c Compare January 9, 2023 13:28
@kennyadsl kennyadsl merged commit 9d8eaca into master Jan 11, 2023
@kennyadsl kennyadsl deleted the kennyadsl/support-starter-frontend branch January 11, 2023 15:06
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.

4 participants