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

Refactor frontend and backend locale_controllers #4126

Merged
merged 2 commits into from
Jul 7, 2021

Conversation

RyanofWoods
Copy link
Contributor

The goal of these changes were to refactor where possible, improve readability and make the backend and frontend locale_controllers more consistent with each other.

  1. Refactor frontend locale_controller by:
  • encapsulating the if statement to the new private method
    locale_is_available? for readability and context
  • making the requested_locale a symbol instead of mapping the
    available_locales to a string during locale_is_available?
  • moving setting of the session's' locale line down one to be
    consistent with the backend's locale_controller
  1. Refactor backend locale_controller by:
  • renaming locale to requested_locale
  • encapsulating the if statement to the new private method
    locale_is_available? for readability and context
  • removing unnecessary respond_to and format.json

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (N/A)
  • I have added tests to cover this change (N/A)
  • I have attached screenshots to this PR for visual changes (N/A)

Refactored by:
- encapsulating the if statement to the new private method
  `locale_is_available?` for readability and context
- making the `requested_locale` a symbol instead of mapping the
  `available_locales` to a string during `locale_is_available?`
- moving setting of the `session`'s' locale line down one to be
  consistent with the `backend`'s `locale_controller`
Refactored by:
- renaming `locale` to `requested_locale`
- encapsulating the if statement to the new private method
  `locale_is_available?` for readability and context
- removing unnecessary `respond_to` and `format.json`
respond_to do |format|
format.json { render json: { locale: I18n.locale }, status: 404 }
end
render json: { locale: I18n.locale }, status: 404

Choose a reason for hiding this comment

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

Rails/HttpStatus: Prefer :not_found over 404 to define HTTP status code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I have seen in Solidus, is that only or mainly status codes are used rather than the symbol equivalents. Should this style be turned off or does the core team actually prefer the symbols?

Copy link
Member

Choose a reason for hiding this comment

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

I'd gradually refactor the codebase following the linter rules when some lines are changed. This way we keep improving the codebase without big refactors that can compromise git history. The trade-off here is not being consistent, which I don't like either. I'd go with the first, if we have a linter setup with Hound (only checks lines changed) we should use it otherwise it doesn't make sense to keep it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great to know for the future! Thank you 👍

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Not super strong opinion about the linter requested change, so approving this. Thanks! I can't see any change that could be breaking, thanks for this refactor.

respond_to do |format|
format.json { render json: { locale: I18n.locale }, status: 404 }
end
render json: { locale: I18n.locale }, status: 404
Copy link
Member

Choose a reason for hiding this comment

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

I'd gradually refactor the codebase following the linter rules when some lines are changed. This way we keep improving the codebase without big refactors that can compromise git history. The trade-off here is not being consistent, which I don't like either. I'd go with the first, if we have a linter setup with Hound (only checks lines changed) we should use it otherwise it doesn't make sense to keep it.

@kennyadsl kennyadsl merged commit 673b4fb into solidusio:master Jul 7, 2021
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