Skip to content

Commit

Permalink
Get conditional reveal working 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBAshton committed Jan 2, 2025
1 parent 18f0848 commit fcd2e8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
4 changes: 3 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def confirm_facets
end

if facet["type"] == "enum_text"
facet.delete("allowed_values")
facet["type"] = "text"
else
facet.delete("allowed_values")
end

if facet["display_as_result_metadata"]
facet["display_as_result_metadata"] = facet["display_as_result_metadata"] == "true"
end
Expand Down
30 changes: 11 additions & 19 deletions app/views/admin/_facet_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,34 @@
hint: "Example: Control zone type"
} %>

<%= render "govuk_publishing_components/components/select", {
<%= render "govuk_publishing_components/components/radio", {
name: "facets[#{index}][type]",
id: "facet[#{index}][type]",
label: "Type",
heading: "Type",
heading_size: "s",
options: [
items: [
{
text: "Radio button",
value: "enum_text", # 'enum_text' only used to hide the 'filter options' field (TODO).
selected: facet["type"] == "text",
checked: facet["type"] == "text",
conditional: render(partial: "facet_fields_options",
locals: {
facet:, index:
}
),
},
{
text: "Text",
value: "text",
selected: facet["type"] == "text" && facet["allowed_values"].nil?,
checked: facet["type"] == "text" && facet["allowed_values"].nil?,
},
{
text: "Date",
value: "date",
selected: facet["type"] == "date",
checked: facet["type"] == "date",
}
]
} %>

<%= render "govuk_publishing_components/components/textarea", {
label: {
text: "Filter options",
heading_size: "s",
},
hint: sanitize("Enclose options in quotes and separate with commas<br>Example: \"Option 1\", \"Option 2\""),
name: "facets[#{index}][allowed_values]",
rows: 5,
# TODO corresponding facet value will be derived from label and subject to manual care by developer
value: facet["allowed_values"]&.map { |opt| "\"#{opt["label"]}\"" }&.join(", "),
} %>

<%= render "govuk_publishing_components/components/radio", {
heading: "Can users use this filter when searching for content items?",
heading_size: "s",
Expand Down
11 changes: 11 additions & 0 deletions app/views/admin/_facet_fields_options.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= render "govuk_publishing_components/components/textarea", {
label: {
text: "Filter options",
heading_size: "s",
},
hint: sanitize("Enclose options in quotes and separate with commas<br>Example: \"Option 1\", \"Option 2\""),
name: "facets[#{index}][allowed_values]",
rows: 5,
# TODO corresponding facet value will be derived from label and subject to manual care by developer
value: facet["allowed_values"]&.map { |opt| "\"#{opt["label"]}\"" }&.join(", "),
} %>

0 comments on commit fcd2e8f

Please sign in to comment.