-
Notifications
You must be signed in to change notification settings - Fork 0
Adds persistence to Tab selection across searches #265
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,23 @@ | ||
| class ApplicationController < ActionController::Base | ||
| helper Mitlibraries::Theme::Engine.helpers | ||
|
|
||
| # Set active tab based on feature flag and params | ||
| # Also stores the last used tab in a cookie for future searches when passed via params. | ||
| # We set this in a session cookie to persist user preference across searches. | ||
| # Clicking on a different tab will update the cookie. | ||
| def set_active_tab | ||
| @active_tab = if Feature.enabled?(:geodata) | ||
| # Determine which tab to load - default to primo unless gdt is enabled | ||
| 'geodata' | ||
| elsif params[:tab].present? | ||
| # If params[:tab] is set, use it and set session | ||
| cookies[:last_tab] = params[:tab] | ||
| elsif cookies[:last_tab].present? | ||
| # Otherwise, check for last used tab in session | ||
| cookies[:last_tab] | ||
| else | ||
| # Default behavior when no tab is specified in params or session | ||
| cookies[:last_tab] = 'primo' | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| class BasicSearchController < ApplicationController | ||
| before_action :set_active_tab | ||
|
|
||
| def index; end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Be sure to restart your server when you modify this file. | ||
| # Note, you must set `SECRET_KEY_BASE` environment variable before running the application or sessions will not work. | ||
| # Changing `SECRET_KEY_BASE` will invalidate all existing sessions. | ||
| # You can generate a new secret key by running `bin/rails secret` command. | ||
| Rails.application.config.session_store :cookie_store, key: '_use_session', secure: false, same_site: :strict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| require 'test_helper' | ||
|
|
||
| class ApplicationControllerTest < ActionDispatch::IntegrationTest | ||
| test 'set_active_tab sets default to primo when no feature flag or params' do | ||
| assert_nil cookies[:last_tab] | ||
|
|
||
| get root_path | ||
| assert_select '#tab-to-target' do | ||
| assert_select '[value=?]', 'primo' | ||
| refute_select '[value=?]', 'geodata' | ||
| refute_select '[value=?]', 'timdex' | ||
| end | ||
|
|
||
| assert_equal cookies[:last_tab], 'primo' | ||
| end | ||
|
|
||
| test 'set_active_tab sets to geodata when feature flag enabled' do | ||
| skip 'Geodata uses a different form so we do no set the tab this way' | ||
| ClimateControl.modify FEATURE_GEODATA: 'true' do | ||
| get root_path | ||
| assert_select '#tab-to-target' do | ||
| refute_select '[value=?]', 'primo' | ||
| assert_select '[value=?]', 'geodata' | ||
| refute_select '[value=?]', 'timdex' | ||
| end | ||
| end | ||
| end | ||
|
|
||
| test 'set_active_tab sets to geodata when feature flag enabled even if param is passed' do | ||
| skip 'Geodata uses a different form' | ||
| ClimateControl.modify FEATURE_GEODATA: 'true' do | ||
| get root_path, params: { tab: 'primo' } | ||
| assert_select '#tab-to-target' do | ||
| refute_select '[value=?]', 'primo' | ||
| assert_select '[value=?]', 'geodata' | ||
| refute_select '[value=?]', 'timdex' | ||
| end | ||
| end | ||
| end | ||
|
|
||
| test 'set_active_tab sets to param tab when provided' do | ||
| get root_path, params: { tab: 'timdex' } | ||
|
|
||
| assert_select '#tab-to-target' do | ||
| refute_select '[value=?]', 'primo' | ||
| refute_select '[value=?]', 'geodata' | ||
| assert_select '[value=?]', 'timdex' | ||
| end | ||
| end | ||
|
|
||
| test 'set_active_tab sets to param tab when provided even if cookie is set and updates cookie' do | ||
| cookies[:last_tab] = 'timdex' | ||
| get root_path, params: { tab: 'geodata' } | ||
|
|
||
| assert_select '#tab-to-target' do | ||
| refute_select '[value=?]', 'primo' | ||
| assert_select '[value=?]', 'geodata' | ||
| refute_select '[value=?]', 'timdex' | ||
| end | ||
|
|
||
| assert_equal cookies[:last_tab], 'geodata' | ||
| end | ||
|
|
||
| test 'set_active_tab uses cookie last_tab when no param provided' do | ||
| cookies[:last_tab] = 'timdex' | ||
| get root_path | ||
| assert_select '#tab-to-target' do | ||
| refute_select '[value=?]', 'primo' | ||
| refute_select '[value=?]', 'geodata' | ||
| assert_select '[value=?]', 'timdex' | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djanelle-mit just tagging you so you know where to remove my amazing code when you pull the tab work soon!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the tag and the comment in the css, too!