Add Time Zone Select#6437
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6437 +/- ##
==========================================
+ Coverage 89.68% 89.70% +0.01%
==========================================
Files 993 994 +1
Lines 20863 20886 +23
==========================================
+ Hits 18712 18735 +23
Misses 2151 2151 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
899d5a5 to
c8011a0
Compare
c8011a0 to
def12cd
Compare
By including this module into a controller it will run all controller actions within the defined timezone. The timezone is taken from the params, the session, user preference (if existing), or the default timezone of the app. The resolved timezone is then stored in the session for future reference.
Use the `Spree::Core::ControllerHelpers::Timezone` module to wrap all admin actions inside the selected timezone.
Use the `Spree::Core::ControllerHelpers::Timezone` module to wrap all admin actions inside the selected timezone. Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
Spans do not self close and this actually has a closing tag anyway. Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
If the user has a timezone column we show a select to let admins set the preferred time zone of the user.
If the user has a timezone column we show a select to let admins set the preferred time zone of the user.
| it "sets timezone by param" do | ||
| get :index, params: {solidus_timezone: "Hawaii"} | ||
| expect(session).to have_key(:solidus_timezone) | ||
| expect(session[:solidus_timezone]).to eq("Hawaii") |
There was a problem hiding this comment.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
| end | ||
|
|
||
| it "sets timezone by param" do | ||
| get :index, params: {solidus_timezone: "Hawaii"} |
There was a problem hiding this comment.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
| expect(response.code).to eq "200" | ||
| end | ||
|
|
||
| it "sets timezone by param" do |
There was a problem hiding this comment.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
| end | ||
|
|
||
| context "successful request" do | ||
| context "authorized request" do |
There was a problem hiding this comment.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
| let(:sign_in_date) { DateTime.now } | ||
|
|
||
| before do | ||
| allow_any_instance_of(Spree.user_class).to receive(:try).with(:timezone) { nil } |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [86/80]
| let!(:user) { create :user } | ||
|
|
||
| before { expect(controller).to receive(:spree_current_user).and_return(user) } | ||
| before { expect(controller).to receive(:spree_current_user).twice.and_return(user) } |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [92/80]
|
|
||
| # Checks if we need to change the timezone or not. | ||
| def timezone_change_needed? | ||
| params[:solidus_timezone].present? || session[:solidus_timezone].blank? |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [81/80]
| resolved_timezone || Time.zone.name | ||
| else | ||
| session[:solidus_timezone] | ||
| end |
There was a problem hiding this comment.
Layout/EndAlignment: end at 26, 10 is not aligned with if at 22, 21.
| def set_timezone(&action) | ||
| timezone = if timezone_change_needed? | ||
| resolved_timezone || Time.zone.name | ||
| else |
There was a problem hiding this comment.
Layout/ElseAlignment: Align else with if.
| # | ||
| def set_timezone(&action) | ||
| timezone = if timezone_change_needed? | ||
| resolved_timezone || Time.zone.name |
There was a problem hiding this comment.
Layout/IndentationWidth: Use 2 (not -9) spaces for indentation.
Summary
Adding a timezone select into the various admin/backend navigations we have. Allows for users to see dates in the admin in the selected timezone. If the current solidus user record has a preferred timezone this is used instead. The resolved timezone is stored in the users session.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: