summaryrefslogtreecommitdiff
path: root/app/helpers/listbox_helper.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 20:02:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 20:02:30 +0000
commit41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch)
tree9c8d89a8624828992f06d892cd2f43818ff5dcc8 /app/helpers/listbox_helper.rb
parent0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff)
downloadgitlab-ce-14.9.0-rc42.tar.gz
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'app/helpers/listbox_helper.rb')
-rw-r--r--app/helpers/listbox_helper.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/app/helpers/listbox_helper.rb b/app/helpers/listbox_helper.rb
index d24680bc0b0..16caf862c7b 100644
--- a/app/helpers/listbox_helper.rb
+++ b/app/helpers/listbox_helper.rb
@@ -16,8 +16,10 @@ module ListboxHelper
# the sort key), `text` is the user-facing string for the item, and `href` is
# the path to redirect to when that item is selected.
#
- # The `selected` parameter is the currently selected `value`, and must
- # correspond to one of the `items`, or be `nil`. When `selected.nil?`, the first item is selected.
+ # The `selected` parameter is the currently selected `value`, and should
+ # correspond to one of the `items`, or be `nil`. When `selected.nil?` or
+ # a value which does not correspond to one of the items, the first item is
+ # selected.
#
# The final parameter `html_options` applies arbitrary attributes to the
# returned tag. Some of these are passed to the underlying Vue component as
@@ -37,9 +39,12 @@ module ListboxHelper
webpack_bundle_tag 'redirect_listbox'
end
- selected ||= items.first[:value]
selected_option = items.find { |opt| opt[:value] == selected }
- raise ArgumentError, "cannot find #{selected} in #{items}" unless selected_option
+
+ unless selected_option
+ selected_option = items.first
+ selected = selected_option[:value]
+ end
button = button_tag(type: :button, class: DROPDOWN_BUTTON_CLASSES) do
content_tag(:span, selected_option[:text], class: DROPDOWN_INNER_CLASS) +