Skip to content

Commit

Permalink
chore: rename markdown field to easy_mde (#3599)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Jan 22, 2025
1 parent a14131e commit 723d218
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions app/components/avo/fields/easy_mde_field/edit_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Avo::Fields::EasyMdeField::EditComponent < Avo::Fields::EditComponent
end
4 changes: 4 additions & 0 deletions app/components/avo/fields/easy_mde_field/show_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Avo::Fields::EasyMdeField::ShowComponent < Avo::Fields::ShowComponent
end
4 changes: 0 additions & 4 deletions app/components/avo/fields/markdown_field/edit_component.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/components/avo/fields/markdown_field/show_component.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/components/avo/views/resource_show_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<turbo-stream action="append" target="alerts">
<template>
<% @resource.invalid_fields.each do |error| %>
<%= render Avo::AlertComponent.new :error, error[:message] %>
<%= render Avo::AlertComponent.new error[:alert_type], error[:message] %>
<% end %>
</template>
</turbo-stream>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Avo
module Fields
class MarkdownField < BaseField
class EasyMdeField < BaseField
attr_reader :options

def initialize(id, **args, &block)
Expand Down
16 changes: 12 additions & 4 deletions lib/avo/resources/items/holder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as: :#{as}</code>"

if as == :markdown
alert_type = :warning
message = "In Avo 3.16.2 we renamed the <code>:markdown</code> field to <code>:easy_mde</code>. <br/><br/>You may continue to use that one or the new and improved one with Active Storage support. <br/><br/> Read more about it in the <a href=\"https://docs.avohq.io/3.0/fields/markdown.html\" target=\"_blank\">docs</a>."
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. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as: :#{as}</code>"
as:,
alert_type:,
message:
})
end

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/avo/resources/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/avo/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down

0 comments on commit 723d218

Please sign in to comment.