Skip to content

A platform for community discussion. Free, open, simple.

FIX: support nested descriptions in object settings (#37538)

Krisfb26fc66a471
diff --git a/app/serializers/theme_objects_setting_metadata_serializer.rb b/app/serializers/theme_objects_setting_metadata_serializer.rb
index 8a3d5b2b98c..ba598457e1e 100644
--- a/app/serializers/theme_objects_setting_metadata_serializer.rb
+++ b/app/serializers/theme_objects_setting_metadata_serializer.rb
@@ -18,7 +18,9 @@ class ThemeObjectsSettingMetadataSerializer < ApplicationSerializer
object.theme.internal_translations.each do |internal_translation|
if internal_translation.key.start_with?(key)
- locales[internal_translation.key.delete_prefix(key)] = internal_translation.value
+ locale_key = internal_translation.key.delete_prefix(key)
+ locale_key = locale_key.gsub(".schema.properties.", ".")
+ locales[locale_key] = internal_translation.value
end
end
diff --git a/spec/fixtures/theme_locales/objects_settings/en.yaml b/spec/fixtures/theme_locales/objects_settings/en.yaml
index 41536129edd..7dd65df13c6 100644
--- a/spec/fixtures/theme_locales/objects_settings/en.yaml
+++ b/spec/fixtures/theme_locales/objects_settings/en.yaml
@@ -9,9 +9,17 @@ en:
label: Name
description: "Section Name"
links:
- name:
- label: Name
- description: "Name of the link"
- url:
- label: URL
- description: "URL of the link"
+ schema:
+ properties:
+ name:
+ label: Name
+ description: "Name of the link"
+ url:
+ label: URL
+ description: "URL of the link"
+ child_links:
+ schema:
+ properties:
+ title:
+ label: Title
+ description: "Title of the child link"
diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb
index 2e3cf736bcb..2e005dd0d91 100644
--- a/spec/requests/admin/themes_controller_spec.rb
+++ b/spec/requests/admin/themes_controller_spec.rb
@@ -1647,6 +1647,8 @@ RSpec.describe Admin::ThemesController do
expect(response.parsed_body["property_descriptions"]).to eq(
{
+ "links.child_links.title.description" => "Title of the child link",
+ "links.child_links.title.label" => "Title",
"links.name.description" => "Name of the link",
"links.name.label" => "Name",
"links.url.description" => "URL of the link",
diff --git a/spec/serializers/theme_objects_setting_metadata_serializer_spec.rb b/spec/serializers/theme_objects_setting_metadata_serializer_spec.rb
index 5db83ef0161..e6a270cdb30 100644
--- a/spec/serializers/theme_objects_setting_metadata_serializer_spec.rb
+++ b/spec/serializers/theme_objects_setting_metadata_serializer_spec.rb
@@ -21,13 +21,15 @@ RSpec.describe ThemeObjectsSettingMetadataSerializer do
theme.save!
end
- it "should return a hash of the settings property descriptions" do
+ it "should return a hash of the settings property descriptions with schema.properties segments stripped" do
objects_setting_locale
payload = described_class.new(theme_setting[:objects_setting], root: false).as_json
expect(payload[:property_descriptions]).to eq(
{
+ "links.child_links.title.description" => "Title of the child link",
+ "links.child_links.title.label" => "Title",
"links.name.description" => "Name of the link",
"links.name.label" => "Name",
"links.url.description" => "URL of the link",
@@ -36,6 +38,8 @@ RSpec.describe ThemeObjectsSettingMetadataSerializer do
"name.label" => "Name",
},
)
+
+ expect(payload[:property_descriptions]).not_to have_key("links.schema.properties.name.label")
end
end