From 95ae3b8828f0ceb68c1ead902a2291379c279ed3 Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Tue, 21 Jan 2025 14:00:46 +0200 Subject: [PATCH] chore: rename markdown field to easy_mde --- .../edit_component.html.erb | 0 .../avo/fields/easy_mde_field/edit_component.rb | 4 ++++ .../show_component.html.erb | 0 .../avo/fields/easy_mde_field/show_component.rb | 4 ++++ .../avo/fields/markdown_field/edit_component.rb | 4 ---- .../avo/fields/markdown_field/show_component.rb | 4 ---- .../avo/views/resource_show_component.html.erb | 2 +- .../{markdown_field.rb => easy_mde_field.rb} | 2 +- lib/avo/resources/items/holder.rb | 16 ++++++++++++---- spec/dummy/app/avo/resources/city.rb | 2 +- spec/dummy/app/avo/resources/project.rb | 2 +- .../avo/resource_tools/_city_editor.html.erb | 2 +- 12 files changed, 25 insertions(+), 17 deletions(-) rename app/components/avo/fields/{markdown_field => easy_mde_field}/edit_component.html.erb (100%) create mode 100644 app/components/avo/fields/easy_mde_field/edit_component.rb rename app/components/avo/fields/{markdown_field => easy_mde_field}/show_component.html.erb (100%) create mode 100644 app/components/avo/fields/easy_mde_field/show_component.rb delete mode 100644 app/components/avo/fields/markdown_field/edit_component.rb delete mode 100644 app/components/avo/fields/markdown_field/show_component.rb rename lib/avo/fields/{markdown_field.rb => easy_mde_field.rb} (93%) diff --git a/app/components/avo/fields/markdown_field/edit_component.html.erb b/app/components/avo/fields/easy_mde_field/edit_component.html.erb similarity index 100% rename from app/components/avo/fields/markdown_field/edit_component.html.erb rename to app/components/avo/fields/easy_mde_field/edit_component.html.erb diff --git a/app/components/avo/fields/easy_mde_field/edit_component.rb b/app/components/avo/fields/easy_mde_field/edit_component.rb new file mode 100644 index 0000000000..80d30d2ae3 --- /dev/null +++ b/app/components/avo/fields/easy_mde_field/edit_component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Avo::Fields::EasyMdeField::EditComponent < Avo::Fields::EditComponent +end diff --git a/app/components/avo/fields/markdown_field/show_component.html.erb b/app/components/avo/fields/easy_mde_field/show_component.html.erb similarity index 100% rename from app/components/avo/fields/markdown_field/show_component.html.erb rename to app/components/avo/fields/easy_mde_field/show_component.html.erb diff --git a/app/components/avo/fields/easy_mde_field/show_component.rb b/app/components/avo/fields/easy_mde_field/show_component.rb new file mode 100644 index 0000000000..78b07fcc45 --- /dev/null +++ b/app/components/avo/fields/easy_mde_field/show_component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Avo::Fields::EasyMdeField::ShowComponent < Avo::Fields::ShowComponent +end diff --git a/app/components/avo/fields/markdown_field/edit_component.rb b/app/components/avo/fields/markdown_field/edit_component.rb deleted file mode 100644 index 4844dcb3fe..0000000000 --- a/app/components/avo/fields/markdown_field/edit_component.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -class Avo::Fields::MarkdownField::EditComponent < Avo::Fields::EditComponent -end diff --git a/app/components/avo/fields/markdown_field/show_component.rb b/app/components/avo/fields/markdown_field/show_component.rb deleted file mode 100644 index a8d7e5fbc3..0000000000 --- a/app/components/avo/fields/markdown_field/show_component.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -class Avo::Fields::MarkdownField::ShowComponent < Avo::Fields::ShowComponent -end diff --git a/app/components/avo/views/resource_show_component.html.erb b/app/components/avo/views/resource_show_component.html.erb index a51bf0dff4..51ef8c7b97 100644 --- a/app/components/avo/views/resource_show_component.html.erb +++ b/app/components/avo/views/resource_show_component.html.erb @@ -27,7 +27,7 @@ diff --git a/lib/avo/fields/markdown_field.rb b/lib/avo/fields/easy_mde_field.rb similarity index 93% rename from lib/avo/fields/markdown_field.rb rename to lib/avo/fields/easy_mde_field.rb index 4ca474201e..2dc572fa79 100644 --- a/lib/avo/fields/markdown_field.rb +++ b/lib/avo/fields/easy_mde_field.rb @@ -1,6 +1,6 @@ module Avo module Fields - class MarkdownField < BaseField + class EasyMdeField < BaseField attr_reader :options def initialize(id, **args, &block) diff --git a/lib/avo/resources/items/holder.rb b/lib/avo/resources/items/holder.rb index 4262e9b19c..fc8656efc3 100644 --- a/lib/avo/resources/items/holder.rb +++ b/lib/avo/resources/items/holder.rb @@ -24,13 +24,21 @@ def field(field_name, **args, &block) if field_parser.invalid? as = args.fetch(:as, nil) + alert_type = :error + message = "There's an invalid field configuration for this resource.
field :#{field_name}, as: :#{as}" + + if as == :markdown + alert_type = :warning + message = "In Avo 3.16.2 we renamed the :markdown field to :easy_mde.

You may continue to use that one or the new and improved one with Active Storage support.

Read more about it in the docs." + end + # End execution ehre and add the field to the invalid_fileds payload so we know to wanr the developer about that. # @todo: Make sure this warning is still active return add_invalid_field({ name: field_name, - as: as, - # resource: resource_class.name, - message: "There's an invalid field configuration for this resource.
field :#{field_name}, as: :#{as}" + as:, + alert_type:, + message: }) end @@ -88,7 +96,7 @@ def add_item(instance) private - def add_invalid_field(payload) + def add_invalid_field(payload, alert_type: :error) invalid_fields << payload end diff --git a/spec/dummy/app/avo/resources/city.rb b/spec/dummy/app/avo/resources/city.rb index 557e18faa9..0d9c6fba72 100644 --- a/spec/dummy/app/avo/resources/city.rb +++ b/spec/dummy/app/avo/resources/city.rb @@ -98,7 +98,7 @@ def tool_fields field :is_capital, as: :boolean, filterable: true field :features, as: :key_value field :image_url, as: :external_image - field :tiny_description, as: :markdown + field :tiny_description, as: :easy_mde field :status, as: :badge, enum: ::City.statuses end end diff --git a/spec/dummy/app/avo/resources/project.rb b/spec/dummy/app/avo/resources/project.rb index 9d8d70f802..8e81a8a413 100644 --- a/spec/dummy/app/avo/resources/project.rb +++ b/spec/dummy/app/avo/resources/project.rb @@ -60,7 +60,7 @@ def fields relative: true, timezone: "EET", format: "MMMM dd, y HH:mm:ss z" - field :description, as: :markdown, height: "350px" + field :description, as: :easy_mde, height: "350px" field :files, as: :files, translation_key: "avo.field_translations.files", diff --git a/spec/dummy/app/views/avo/resource_tools/_city_editor.html.erb b/spec/dummy/app/views/avo/resource_tools/_city_editor.html.erb index 56064ab617..ca2ac9e9da 100644 --- a/spec/dummy/app/views/avo/resource_tools/_city_editor.html.erb +++ b/spec/dummy/app/views/avo/resource_tools/_city_editor.html.erb @@ -14,7 +14,7 @@ <% if params[:show_native_fields].present? %> <%= avo_edit_field(:description, as: :trix, form: form, component_options: {resource_name: 'cities', resource_id: @resource.record&.id}) %> <% end %> - <%= avo_edit_field(:tiny_description, as: :markdown, form: form) %> + <%= avo_edit_field(:tiny_description, as: :easy_mde, form: form) %> <%= avo_edit_field(:status, as: :select, enum: ::City.statuses, form: form) %> <%= avo_show_field(:status, as: :badge, enum: ::City.statuses, form: form) %> <% end %>