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

All Names link #1843

Merged
merged 3 commits into from
Jan 29, 2024
Merged
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
32 changes: 15 additions & 17 deletions app/helpers/tabs/names_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,7 @@ def mycobank_basic_search_tab
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def name_correct_spelling_tab(name)
Copy link
Member Author

Choose a reason for hiding this comment

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

Dead Code

[name.correct_spelling.display_name.l,
add_query_param(name_path(name.correct_spelling_id)),
{ class: tab_id(__method__.to_s) }]
end

def show_name_tab(name)
[name.display_name.l, add_query_param(name_path(name.id)),
{ class: tab_id(__method__.to_s) }]
end

# lifeform tabs:
def propagate_lifeform_form_tab(name)
[:show_name_propagate_lifeform.t,
add_query_param(propagate_name_lifeform_form_path(name.id)),
{ class: tab_id(__method__.to_s) }]
end

def edit_name_lifeform_tab(name)
[:EDIT.l, add_query_param(edit_name_lifeform_path(name.id)),
{ class: tab_id(__method__.to_s), icon: :edit }]
Expand Down Expand Up @@ -234,6 +217,21 @@ def descriptions_of_these_names_tab(query)
{ class: tab_id(__method__.to_s) }]
end

def all_names_index_tabs(query:)
[
new_name_tab,
all_names_tab(query),
coerced_observation_query_tab(query)
].reject(&:empty?)
end

def all_names_tab(query)
return if query&.flavor == :all || query&.flavor&.empty?
Copy link
Member Author

Choose a reason for hiding this comment

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

@nimmolo: Does this make sense? Is the 2nd condition over-cautious?


[:all_objects.t(type: :name), names_path,
{ class: tab_id(__method__.to_s) }]
end

def names_index_sorts(query:)
[
["name", :sort_by_name.t],
Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/names/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%
@container = :text_image
add_index_title(@query, no_hits: "")
add_tab_set(names_index_tabs(query: @query))
add_tab_set(all_names_index_tabs(query: @query))
add_sorter(@query, names_index_sorts(query: @query))

flash_error(@error) if @error && @objects.empty?
Expand Down
4 changes: 4 additions & 0 deletions test/controllers/names_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def test_index
get(:index)

assert_displayed_title("Names by Name")
assert_select("#right_tabs a[href='#{names_path}']", { count: 0 },
"right `tabs` should not link to All Names")
end

def test_index_with_non_default_sort
Expand Down Expand Up @@ -220,6 +222,8 @@ def test_index_with_observations
distinct.count },
"Wrong number of (correctly spelled) Names"
)
assert_select("#right_tabs a[href='#{names_path}']", { count: 1 },
"right `tabs` should have a link to All Names")
end

def test_index_with_observations_by_letter
Expand Down