-
Notifications
You must be signed in to change notification settings - Fork 0
Add new search tabs and improve tab handling #278
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
Changes from all commits
42bbbf4
8290364
5ece9e6
9d53faa
2d23db5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,15 +23,15 @@ def results | |
| render 'results_geo' | ||
| return | ||
| end | ||
|
|
||
| # Route to appropriate search based on active tab | ||
| case @active_tab | ||
| when 'primo' | ||
| load_primo_results | ||
| when 'timdex' | ||
| load_timdex_results | ||
| when 'all' | ||
| load_all_results | ||
| when *primo_tabs | ||
| load_primo_results | ||
| when *timdex_tabs | ||
| load_timdex_results | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -108,7 +108,7 @@ def load_all_results | |
|
|
||
| # For now, just use primo pagination as a placeholder | ||
| @pagination = primo_data[:pagination] || {} | ||
|
|
||
| # Handle primo continuation for high page numbers | ||
| @show_primo_continuation = primo_data[:show_continuation] || false | ||
| end | ||
|
|
@@ -119,9 +119,7 @@ def fetch_primo_data | |
| offset = (current_page - 1) * per_page | ||
|
|
||
| # Check if we're beyond Primo API limits before making the request. | ||
| if offset >= Analyzer::PRIMO_MAX_OFFSET | ||
| return { results: [], pagination: {}, errors: nil, show_continuation: true } | ||
| end | ||
| return { results: [], pagination: {}, errors: nil, show_continuation: true } if offset >= Analyzer::PRIMO_MAX_OFFSET | ||
|
|
||
| primo_response = query_primo | ||
| results = NormalizePrimoResults.new(primo_response, @enhanced_query[:q]).normalize | ||
|
|
@@ -133,7 +131,7 @@ def fetch_primo_data | |
| # exists in Primo UI, sending users there seems like the best we can do. | ||
| show_continuation = false | ||
| errors = nil | ||
|
|
||
| if results.empty? | ||
| docs = primo_response['docs'] if primo_response.is_a?(Hash) | ||
| if docs.nil? || docs.empty? | ||
|
|
@@ -153,7 +151,7 @@ def fetch_timdex_data | |
| query = QueryBuilder.new(@enhanced_query).query | ||
| response = query_timdex(query) | ||
| errors = extract_errors(response) | ||
|
|
||
| if errors.nil? | ||
| pagination = Analyzer.new(@enhanced_query, response, :timdex).pagination | ||
| raw_results = extract_results(response) | ||
|
|
@@ -169,14 +167,18 @@ def active_filters | |
| end | ||
|
|
||
| def query_timdex(query) | ||
| query[:sourceFilter] = ['MIT Libraries Website', 'LibGuides'] if @active_tab == 'website' | ||
| query[:sourceFilter] = ['MIT ArchivesSpace'] if @active_tab == 'aspace' | ||
| query[:sourceFilter] = ['MIT Alma'] if @active_tab == 'timdex_alma' | ||
|
|
||
| # We generate unique cache keys to avoid naming collisions. | ||
| cache_key = generate_cache_key(query) | ||
|
|
||
| # Builder hands off to wrapper which returns raw results here. | ||
| Rails.cache.fetch("#{cache_key}/#{@active_tab}", expires_in: 12.hours) do | ||
| raw = if Feature.enabled?(:geodata) | ||
| execute_geospatial_query(query) | ||
| elsif @active_tab == 'timdex' || @active_tab == 'all' | ||
| else | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this a bug that slipped past me? Reading it now, it seems like I think this is cleaner, but I want to know if I missed something here before.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there was an intermediary change that used the |
||
| TimdexBase::Client.query(TimdexSearch::BaseQuery, variables: query) | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,16 +22,22 @@ def link_to_result(result) | |
| end | ||
| end | ||
|
|
||
| def link_to_tab(target) | ||
| if @active_tab == target.downcase | ||
| link_to target, results_path(params.permit(:q, :per_page, :booleanType, :tab).merge(tab: target.downcase)), | ||
| aria: { current: "page" }, | ||
| class: "active tab-link", | ||
| data: { turbo_frame: "search-results", turbo_action: "advance" } | ||
| # Generates a link for a search results tab, marking it as active if it matches the current active tab. | ||
| # @param target [String] The name of the tab to link to | ||
| # @param label [String] The display label for the tab (optional) | ||
| # @return [String] HTML link element for the tab | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for writing the document block for this helper! |
||
| def link_to_tab(target, label = nil) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered how soon we'd need to have a Question:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh...my names for all of this is confusing after me reading your summary of what is going on :) I have no idea why I redefine My fix is likely to change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added tests and updated variable names to be clearer.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I like these variable names better - thanks! |
||
| clean_target = target.downcase.gsub(' ', '_').downcase | ||
| tab_label = label || target | ||
| if @active_tab == clean_target | ||
| link_to tab_label, results_path(params.permit(:q, :per_page, :booleanType, :tab).merge(tab: clean_target)), | ||
| aria: { current: 'page' }, | ||
| class: 'active tab-link', | ||
| data: { turbo_frame: 'search-results', turbo_action: 'advance' } | ||
| else | ||
| link_to target, results_path(params.permit(:q, :per_page, :booleanType, :tab).merge(tab: target.downcase)), | ||
| class: "tab-link", | ||
| data: { turbo_frame: "search-results", turbo_action: "advance" } | ||
| link_to tab_label, results_path(params.permit(:q, :per_page, :booleanType, :tab).merge(tab: clean_target)), | ||
| class: 'tab-link', | ||
| data: { turbo_frame: 'search-results', turbo_action: 'advance' } | ||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ def initialize(record, query) | |
| def normalize | ||
| { | ||
| # Core fields | ||
| api: 'primo', | ||
| title:, | ||
| creators:, | ||
| source:, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| require 'test_helper' | ||
|
|
||
| class ApplicationControllerUnitTest < ActionController::TestCase | ||
| setup do | ||
| @controller = ApplicationController.new | ||
| end | ||
|
|
||
| test '#primo_tabs returns expected tabs' do | ||
| assert_equal %w[alma cdi primo], @controller.primo_tabs | ||
| end | ||
|
|
||
| test '#timdex_tabs returns expected tabs' do | ||
| assert_equal %w[aspace timdex timdex_alma website], @controller.timdex_tabs | ||
| end | ||
|
|
||
| test '#all_tabs includes both primo and timdex tabs as well as all tab' do | ||
| expected = %w[all alma cdi primo aspace timdex timdex_alma website] | ||
| assert_equal expected, @controller.all_tabs | ||
| end | ||
|
|
||
| test '#valid_tab? returns true for valid tabs' do | ||
| assert @controller.send(:valid_tab?, 'all') | ||
| assert @controller.send(:valid_tab?, 'alma') | ||
| assert @controller.send(:valid_tab?, 'timdex') | ||
| end | ||
|
|
||
| test '#valid_tab? returns false for invalid tabs' do | ||
| refute @controller.send(:valid_tab?, 'invalid') | ||
| refute @controller.send(:valid_tab?, '') | ||
| end | ||
|
|
||
| test 'set_active_tab defaults @active_tab to all when no params or cookies are set' do | ||
| @controller.stubs(:params).returns({}) | ||
| @controller.stubs(:cookies).returns({}) | ||
| @controller.set_active_tab | ||
| assert_equal 'all', @controller.instance_variable_get(:@active_tab) | ||
| end | ||
|
|
||
| test 'set_active_tab sets @active_tab to tab when tab params is valid' do | ||
| @controller.stubs(:params).returns({ tab: 'primo' }) | ||
| @controller.stubs(:cookies).returns({}) | ||
| @controller.set_active_tab | ||
| assert_equal 'primo', @controller.instance_variable_get(:@active_tab) | ||
| end | ||
|
|
||
| test 'set_active_tab sets @active_tab to all when tab params is invalid and no cookie is set' do | ||
| @controller.stubs(:params).returns({ tab: 'supertab' }) | ||
| @controller.stubs(:cookies).returns({}) | ||
| @controller.set_active_tab | ||
| assert_equal 'all', @controller.instance_variable_get(:@active_tab) | ||
| end | ||
|
|
||
| test 'set_active_tab sets @active_tab to cookie value when tab params is invalid and valid cookie is set' do | ||
| @controller.stubs(:params).returns({ tab: 'supertab' }) | ||
| @controller.stubs(:cookies).returns({ last_tab: 'timdex' }) | ||
| @controller.set_active_tab | ||
| assert_equal 'timdex', @controller.instance_variable_get(:@active_tab) | ||
| end | ||
|
|
||
| test 'set_active_tab sets @active_tab to all value when tab params is invalid and cookie is invalid' do | ||
| @controller.stubs(:params).returns({ tab: 'supertab' }) | ||
| @controller.stubs(:cookies).returns({ last_tab: 'woohoo' }) | ||
| @controller.set_active_tab | ||
| assert_equal 'all', @controller.instance_variable_get(:@active_tab) | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.