Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def primo_tabs
end

def timdex_tabs
%w[aspace timdex timdex_alma website]
%w[aspace databases dspace geodata timdex timdex_alma website]
end

def all_tabs
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ 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'
query[:sourceFilter] = ['DSpace@MIT'] if @active_tab == 'dspace'
query[:sourceFilter] = ['Research Databases'] if @active_tab == 'databases'
query[:sourceFilter] = ['OpenGeoMetadata GIS Resources', 'MIT GIS Resources'] if @active_tab == 'geodata'

# We generate unique cache keys to avoid naming collisions.
cache_key = CacheKeyGenerator.call(query)
Expand Down Expand Up @@ -391,7 +394,8 @@ def handle_primo_errors(error)
'message' => 'Hmm, we seem to be having difficulties...',
'description' => 'In the meantime, try searching these tools directly.',
'links' => [
{ 'label' => "MIT's WorldCat", 'description' => 'Books and media', 'url' => 'https://libraries.mit.edu/worldcat' },
{ 'label' => "MIT's WorldCat", 'description' => 'Books and media',
'url' => 'https://libraries.mit.edu/worldcat' },
{ 'label' => 'Google Scholar', 'description' => 'Articles', 'url' => 'https://scholar.google.com/' },
{ 'label' => 'ArchivesSpace', 'description' => 'MIT archives', 'url' => 'https://archivesspace.mit.edu/' },
{ 'label' => 'DSpace@MIT', 'description' => 'MIT research', 'url' => 'https://dspace.mit.edu/' }
Expand Down
39 changes: 23 additions & 16 deletions app/helpers/results_helper.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
module ResultsHelper
# Descriptions for each tab. HTML entries use raw anchor tags (all URLs are
# hardcoded external links, so no XSS risk) and must be marked html_safe.
TAB_DESCRIPTIONS = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this change in pattern a lot. 🍻

'all' => 'All MIT Libraries sources',
'cdi' => 'Journal and newspaper articles, book reviews, book chapters, and more',
'alma' => 'Books, e-books, journals, streaming and physical media, and more',
'timdex_alma' => 'Books, e-books, journals, streaming and physical media, and more',
'primo' => 'Articles, books, chapters, streaming and physical media, and more',
'aspace' => 'Archives, manuscripts, and other unique materials related to MIT',
'timdex' => 'Digital collections, images, documents, and more from MIT Libraries',
'website' => 'Information about the library: events, news, services, and more',
'dspace' => '<a href="https://dspace.mit.edu">DSpace@MIT</a> ' \
"is a digital repository for MIT's research, including peer-reviewed articles, " \
'technical reports, working papers, theses, and more.'.html_safe,
'geodata' => "Geospatial datasets and maps from MIT Libraries' " \
'<a href="https://geodata.libraries.mit.edu">GeoData</a> collections; ' \
'includes <a href="https://opengeometadata.org">Open Geospatial Consortium (OGC)</a> data.'.html_safe,
'databases' => '<a href="https://libguides.mit.edu/az/databases">Research Databases</a> ' \
'covering a wide range of subjects and formats'.html_safe
}.freeze

def results_summary(hits)
hits.to_i >= 10_000 ? '10,000+ results' : "#{number_with_delimiter(hits)} results"
end

# Provides a description for the current tab in search results.
def tab_description
case params[:tab]
when 'all'
'All MIT Libraries sources'
when 'cdi'
'Journal and newspaper articles, book reviews, book chapters, and more'
when 'alma', 'timdex_alma'
'Books, e-books, journals, streaming and physical media, and more'
when 'primo'
'Articles, books, chapters, streaming and physical media, and more'
when 'aspace'
'Archives, manuscripts, and other unique materials related to MIT'
when 'timdex'
'Digital collections, images, documents, and more from MIT Libraries'
when 'website'
'Information about the library: events, news, services, and more'
else
TAB_DESCRIPTIONS.fetch(params[:tab]) do
Rails.logger.error "Unknown tab parameter in `tab_description` helper: #{params[:tab]}"
''
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Making sure I understand - this is the default value in case tab_description gets presented a value that we don't expect, right? So if there's a regression or mismatch somehow, we're not presenting gibberish, just an empty string.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct. Previous to this we were inadvertently returning true as the logging statement is apparently truthy.

end
Comment thread
JPrevost marked this conversation as resolved.
Comment thread
JPrevost marked this conversation as resolved.
end

Expand Down
12 changes: 9 additions & 3 deletions app/javascript/source_tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ moreBtn.addEventListener('click', (e) => {
moreBtn.setAttribute('aria-expanded', container.classList.contains('--show-secondary'))
})

// Maximum number of tabs to show in the primary tab bar at once
const MAX_TABS = 10

// adapt tabs
const doAdapt = () => {

Expand All @@ -43,14 +46,17 @@ const doAdapt = () => {
item.classList.remove('--hidden')
})

// hide items that won't fit in the Primary tab bar
// hide items that won't fit in the Primary tab bar, or exceed MAX_TABS
// once a tab is hidden, all subsequent tabs are also hidden to preserve order
let stopWidth = moreBtn.offsetWidth
let hiddenItems = []
let shouldHide = false
const primaryWidth = primary.offsetWidth
primaryItems.forEach((item, i) => {
if(primaryWidth >= stopWidth + item.offsetWidth) {
if(!shouldHide && i < MAX_TABS && primaryWidth >= stopWidth + item.offsetWidth) {
stopWidth += item.offsetWidth
} else {
shouldHide = true
item.classList.add('--hidden')
hiddenItems.push(i)
}
Expand Down Expand Up @@ -86,4 +92,4 @@ document.addEventListener('click', (e) => {
}
container.classList.remove('--show-secondary')
moreBtn.setAttribute('aria-expanded', false)
})
})
5 changes: 3 additions & 2 deletions app/models/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
#
class Feature
# List of all valid features in the application
VALID_FEATURES = %i[bot_detection geodata boolean_picker oa_always primo_nde_links simulate_search_latency tab_primo_all tab_timdex_all
tab_timdex_alma record_link timdex_fulltext timdex_semantic_search].freeze
VALID_FEATURES = %i[bot_detection geodata boolean_picker oa_always primo_nde_links simulate_search_latency
tab_primo_all tab_timdex_all tab_timdex_alma record_link timdex_fulltext
timdex_semantic_search].freeze

# Check if a feature is enabled by name
#
Expand Down
15 changes: 10 additions & 5 deletions app/views/search/_source_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<!-- Tab Navigation -->
<nav id="tabs" class="tab-navigation" aria-label="Result type navigation" data-matomo-click="Navigation, Tabs Engaged, Current Tab: {{getActiveTabName}}; Navigated to: {{getElementText}}">
<ul class="primary">
<%# Core tabs %>
<li><%= link_to_tab("All") %></li>
<li><%= link_to_tab("cdi", "Articles") %></li>
<li><%= link_to_tab("alma", "Books and media") %></li>
<li><%= link_to_tab("databases", "Databases") %></li>
<li><%= link_to_tab("aspace", "MIT archives") %></li>
<li><%= link_to_tab("Website") %></li>
<li><%= link_to_tab("dspace", "MIT research") %></li>
<li><%= link_to_tab("geodata", "Geospatial data") %></li>

<%# Experimental tabs %>
<% if Feature.enabled?(:tab_primo_all) %>
<li><%= link_to_tab("Primo", "Articles and Catalog") %></li>
<% end %>

<li><%= link_to_tab("cdi", "Articles") %></li>
<li><%= link_to_tab("alma", "Books and media") %></li>

<% if Feature.enabled?(:tab_timdex_all) %>
<li><%= link_to_tab("TIMDEX") %></li>
<% end %>

<% if Feature.enabled?(:tab_timdex_alma) %>
<li><%= link_to_tab("timdex_alma", "Alma (TIMDEX)") %></li>
<% end %>
<li><%= link_to_tab("aspace", "MIT archives") %></li>
<li><%= link_to_tab("Website") %></li>
</ul>
</nav>

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/application_controller_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class ApplicationControllerUnitTest < ActionController::TestCase
end

test '#timdex_tabs returns expected tabs' do
assert_equal %w[aspace timdex timdex_alma website], @controller.timdex_tabs
assert_equal %w[aspace databases dspace geodata 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]
expected = %w[all alma cdi primo aspace databases dspace geodata timdex timdex_alma website]
assert_equal expected, @controller.all_tabs
end

Expand Down
35 changes: 4 additions & 31 deletions test/helpers/results_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,10 @@ class ResultsHelperTest < ActionView::TestCase
end

test 'result helper handles tab descriptions for tabs based on params hash' do
params[:tab] = 'all'
description = 'All MIT Libraries sources'
assert_equal description, tab_description

params[:tab] = 'cdi'
description = 'Journal and newspaper articles, book reviews, book chapters, and more'
assert_equal description, tab_description

params[:tab] = 'alma'
description = 'Books, e-books, journals, streaming and physical media, and more'
assert_equal description, tab_description

params[:tab] = 'timdex_alma'
description = 'Books, e-books, journals, streaming and physical media, and more'
assert_equal description, tab_description

params[:tab] = 'primo'
description = 'Articles, books, chapters, streaming and physical media, and more'
assert_equal description, tab_description

params[:tab] = 'aspace'
description = 'Archives, manuscripts, and other unique materials related to MIT'
assert_equal description, tab_description

params[:tab] = 'timdex'
description = 'Digital collections, images, documents, and more from MIT Libraries'
assert_equal description, tab_description

params[:tab] = 'website'
description = 'Information about the library: events, news, services, and more'
assert_equal description, tab_description
ResultsHelper::TAB_DESCRIPTIONS.each do |tab, expected|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the efficiency of this test, but I wonder whether we should have a test for the behavior when a value outside that TAB_DESCRIPTIONS construct is presented?

More theoretically, I get that this test makes things more robust because we don't need to manually keep the list of test values in sync with the content of the helper method. This feels like a win - but I'm not sure where the line is where we just end up testing that .each() does what we expect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I definitely agree we should confirm something outside of the expected list returns blank. I'll confirm that test exists or add one.

params[:tab] = tab
assert_equal expected, tab_description, "Expected description for tab '#{tab}' to match TAB_DESCRIPTIONS"
end
end

test 'search_primo_link includes encoded search query and correct path' do
Expand Down
Loading