Skip to content

Commit

Permalink
fix: return valid attributes for html options
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Jan 22, 2024
1 parent 58f6231 commit 63cf7e4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
10 changes: 8 additions & 2 deletions lib/avo/fields/concerns/has_html_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ def get_html(name = nil, element:, view:)
add_action_data_attributes(attributes, name, element)
add_resource_data_attributes(attributes, name, element, view)

attributes
value_or_default name, attributes
end

private

def value_or_default(name, attributes)
return attributes if attributes.present?

default_attribute_value name
end

# Returns Hash, HTML::Builder, or nil.
def parse_html
return if @html.nil?
Expand All @@ -50,7 +56,7 @@ def parse_html
end

def default_attribute_value(name)
name == :data ? {} : ""
(name == :data) ? {} : ""
end

def add_action_data_attributes(attributes, name, element)
Expand Down
8 changes: 4 additions & 4 deletions lib/avo/html/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_stack(name = nil)
# We don't have an edit component for new so we should use edit
name = :edit if name == :new

send "#{name}_stack"
send :"#{name}_stack"
end

def dig_stack(*names)
Expand Down Expand Up @@ -115,17 +115,17 @@ def build
self
end

protected
private

# Capture and parse the blocks for the nested structure
def capture_block(property = nil, &block)
send("#{property}_stack=", self.class.parse_block(record: record, resource: resource, &block).build)
send(:"#{property}_stack=", self.class.parse_block(record: record, resource: resource, &block).build)
end

# Parse the properties and assign them to the blocks
def assign_property(property = :data, payload = nil, &block)
value = Avo::ExecutionContext.new(target: block || payload, record: record).handle

send("#{property}_stack=", value)
send(:"#{property}_stack=", value)
end
end
2 changes: 1 addition & 1 deletion lib/tasks/avo_tasks.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
desc "Runs the update command for all Avo gems."
task "avo:update" do
system "bundle update avo avo-pro avo-advanced avo-dashboards avo_filters avo-menu avo_upgrade"
system "bundle update avo avo-pro avo-advanced avo-dashboards avo_filters avo-menu"
end

desc "Installs Avo assets and bundles them for when you want to use the GitHub repo in your app"
Expand Down
7 changes: 6 additions & 1 deletion scripts/export-tailwind-safelist.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
This command should only be run when updating one of the dynamic components or when we add a suport for a custom class on the docs.
EX: - Avo::ButtonComponent
*/

/* eslint-disable no-template-curly-in-string */
const fs = require('fs')
const kebabCase = require('lodash/kebabCase')
const colors = require('tailwindcss/colors')

// Dynamically built buttons need these classes in prod.
// Dynamically-built buttons need these classes in prod.
const buttonClasses = [
'bg-${color}-500',
'border-${color}-500',
Expand Down
6 changes: 5 additions & 1 deletion spec/dummy/app/avo/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def fields
translation_key: "avo.field_translations.files",
view_type: :list, stacked: false,
hide_view_type_switcher: false
field :meta, as: :key_value, key_label: "Meta key", value_label: "Meta value", action_text: "New item", delete_text: "Remove item", disable_editing_keys: false, disable_adding_rows: false, disable_deleting_rows: false
field :meta, as: :key_value, key_label: "Meta key", value_label: "Meta value", action_text: "New item", delete_text: "Remove item", disable_editing_keys: false, disable_adding_rows: false, disable_deleting_rows: false, html: -> do
show do
wrapper { classes("spoon") }
end
end

field :users, as: :has_and_belongs_to_many
field :comments, as: :has_many, searchable: true
Expand Down
5 changes: 4 additions & 1 deletion spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@

config.factory_bot.definition_file_paths = ["../../db"]

config.log_level = :fatal
if ENV["RAILS_LOG"].blank?
config.logger = Logger.new(nil)
config.log_level = :fatal
end

config.i18n.load_path += Dir[Avo::Engine.root.join("lib", "generators", "avo", "templates", "locales", "*.{rb,yml}")]

Expand Down

0 comments on commit 63cf7e4

Please sign in to comment.