Skip to content

Commit 8f1c595

Browse files
committed
Do not esacpe special characters in node data-path attributes. Otherwise, the JS controller won't find them.
1 parent d640316 commit 8f1c595

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

.changeset/clear-cooks-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openproject/primer-view-components': patch
3+
---
4+
5+
Support special characters in node names of Primer::Alpha::TreeView

app/components/primer/alpha/tree_view/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def initialize(
129129
@content_arguments, {
130130
data: {
131131
value: value,
132-
path: @path.to_json,
132+
path: JSON.generate(@path),
133133
select_variant: @select_variant
134134
}
135135
}

previews/primer/alpha/tree_view_preview/form_input.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<% end %>
88

99
<% tree.with_leaf(label: "action_menu.rb", select_variant: select_variant, value: 3) %>
10+
<% tree.with_sub_tree(label: "Docs & legal requirements", select_variant: select_variant, value: 4) do |sub_tree| %>
11+
<% sub_tree.with_leaf(label: "Readme.md", select_variant: select_variant, value: 5) %>
12+
<% sub_tree.with_leaf(label: "Copyright.md", select_variant: select_variant, value: 6) %>
13+
<% end %>
1014
<% end %>
1115

1216
<%= render(Primer::Alpha::SubmitButton.new(name: :submit, label: "Submit")) %>

test/system/alpha/tree_view_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,5 +885,20 @@ def test_initial_form_state_for_single_select
885885

886886
assert_equal "{\"path\":[\"src\",\"button.rb\"],\"value\":\"1\"}", response.dig("form_params", "folder_structure", 0)
887887
end
888+
889+
def test_single_select_with_special_character
890+
visit_preview(:form_input, expanded: true, select_variant: :single, route_format: :json)
891+
892+
assert_path_checked "src", "button.rb"
893+
activate_at_path("Docs & legal requirements")
894+
assert_path_checked "Docs & legal requirements"
895+
896+
find("button[type=submit]").click
897+
898+
# for some reason the JSON response is wrapped in HTML, I have no idea why
899+
response = JSON.parse(find("pre").text)
900+
901+
assert_equal "{\"path\":[\"Docs & legal requirements\"],\"value\":\"4\"}", response.dig("form_params", "folder_structure", 0)
902+
end
888903
end
889904
end

test/test_helpers/tree_view_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Primer
44
module TreeViewHelpers
55
def selector_for(*path)
6-
"[role=treeitem][data-path='#{path.to_json}']"
6+
"[role=treeitem][data-path='#{JSON.generate(path)}']"
77
end
88

99
def activate_at_path(*path)

0 commit comments

Comments
 (0)