Skip to content

Commit 871c818

Browse files
authoredSep 9, 2024··
[SelectPanel] Raise an error when remote fetch + hidden filter combo (#3053)
1 parent c20ec78 commit 871c818

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed
 

‎.changeset/many-zoos-scream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
[SelectPanel] Raise an error when remote fetch + hidden filter argument combo

‎app/components/primer/alpha/select_panel.rb

+12
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ def initialize(
453453
label: "#{title} options"
454454
}
455455
)
456+
457+
return if @show_filter || @fetch_strategy != :remote
458+
return if shouldnt_raise_error?
459+
460+
raise(
461+
"Hiding the filter input with a remote fetch strategy is not permitted, "\
462+
"since such a combinaton of options will cause the component to only "\
463+
"fetch items from the server once when the panel opens for the first time; "\
464+
"this is what the `:eventually_local` fetch strategy is designed to do. "\
465+
"Consider passing `show_filter: true` or use the `:eventually_local` fetch "\
466+
"strategy instead."
467+
)
456468
end
457469

458470
# @!parse

‎previews/primer/alpha/select_panel_preview.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class SelectPanelPreview < ViewComponent::Preview
1414
# @param dynamic_label toggle
1515
# @param dynamic_label_prefix text
1616
# @param dynamic_aria_label_prefix text
17-
# @param show_filter toggle
1817
# @param open_on_load toggle
1918
# @param anchor_align [Symbol] select [start, center, end]
2019
# @param anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
@@ -29,7 +28,6 @@ def playground(
2928
dynamic_label: false,
3029
dynamic_label_prefix: nil,
3130
dynamic_aria_label_prefix: nil,
32-
show_filter: true,
3331
open_on_load: false,
3432
anchor_align: :start,
3533
anchor_side: :outside_bottom,
@@ -47,7 +45,6 @@ def playground(
4745
dynamic_label: dynamic_label,
4846
dynamic_label_prefix: dynamic_label_prefix,
4947
dynamic_aria_label_prefix: dynamic_aria_label_prefix,
50-
show_filter: show_filter,
5148
open_on_load: open_on_load,
5249
anchor_align: anchor_align,
5350
anchor_side: anchor_side
@@ -59,18 +56,21 @@ def playground(
5956
#
6057
# @snapshot interactive
6158
# @param open_on_load toggle
62-
def default(open_on_load: false)
59+
# @param show_filter toggle
60+
def default(open_on_load: false, show_filter: true)
6361
render_with_template(template: "primer/alpha/select_panel_preview/local_fetch", locals: {
64-
open_on_load: open_on_load
62+
open_on_load: open_on_load,
63+
show_filter: show_filter
6564
})
6665
end
6766

6867
# @label Local fetch
6968
#
7069
# @snapshot interactive
7170
# @param open_on_load toggle
72-
def local_fetch(open_on_load: false)
73-
render_with_template(locals: { open_on_load: open_on_load })
71+
# @param show_filter toggle
72+
def local_fetch(open_on_load: false, show_filter: true)
73+
render_with_template(locals: { open_on_load: open_on_load, show_filter: show_filter })
7474
end
7575

7676
# @label Eventually local fetch

‎previews/primer/alpha/select_panel_preview/local_fetch.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
data: { interaction_subject: subject_id },
55
select_variant: :multiple,
66
fetch_strategy: :local,
7-
open_on_load: open_on_load
7+
open_on_load: open_on_load,
8+
show_filter: show_filter,
89
)) do |panel| %>
910
<% panel.with_show_button { "Panel" } %>
1011
<% panel.with_item(label: "Item 1") %>

‎test/components/alpha/select_panel_test.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_renders_a_filter_input
1818
end
1919

2020
def test_does_not_render_a_filter_input
21-
render_inline(Primer::Alpha::SelectPanel.new(show_filter: false))
21+
render_inline(Primer::Alpha::SelectPanel.new(fetch_strategy: :local, show_filter: false))
2222

2323
refute_selector("primer-text-field")
2424
end
@@ -102,6 +102,16 @@ def test_renders_close_button
102102
assert_selector "select-panel button[data-close-dialog-id='#{panel_id}-dialog']"
103103
end
104104

105+
def test_raises_if_remote_strategy_and_hidden_filter_used_together
106+
with_raise_on_invalid_options(true) do
107+
error = assert_raises do
108+
render_inline(Primer::Alpha::SelectPanel.new(fetch_strategy: :remote, show_filter: false))
109+
end
110+
111+
assert_includes error.message, "Hiding the filter input with a remote fetch strategy is not permitted"
112+
end
113+
end
114+
105115
def test_raises_if_role_given
106116
with_raise_on_invalid_options(true) do
107117
error = assert_raises do

0 commit comments

Comments
 (0)
Please sign in to comment.