Skip to content

Commit

Permalink
Chore: Apply literal properties (#3102)
Browse files Browse the repository at this point in the history
* Add literal to alert_component

* Add literal to backtrace_alert_component

* Apply literal to button_component

* Apply literal to cover_photo_component

* Apply literal to divider_component

* Apply literal to empty_state_component

* Ensure Symbol is passed into empty_state_component because ./spec/system/avo/resource_index_map_spec.rb fails

* Lint

* Apply literal to field_wrapper_component

* Apply literal to filters_component

* Apply literal to flash_alerts_component

* Apply literal to loading_component

* Remove redundant var and apply literal to modal component

* Lint

* Apply literal to paginator_component

* Apply literal to panel_component

* Apply literal to referrer_params_component

* Apply literal to resource_sidebar_component

* Apply literal to row_component

* Apply literal to row_selector_component

* apply literal to sidebar_component

* Apply literal to app/components/avo/sidebar_profile_component.rb

* Apply literal to app/components/avo/tab_group_component.rb

* Apply literal to app/components/avo/tab_switcher_component.rb

* Apply literal to app/components/avo/turbo_frame_wrapper_component.rb

* Apply literal to app/components/avo/index/field_wrapper_component.rb

* Add note on breakage

* Apply literal to app/components/avo/views/resource_edit_component.rb

* Apply literal to app/components/avo/index/resource_table_component.rb

* Apply literal to app/components/avo/index/grid_item_component.rb

* Apply literal to app/components/avo/index/resource_controls_component.rb

* Apply literal to app/components/avo/views/resource_show_component.rb

* Make user nilable for sidebar_profile_component

* Coerce to symbol

* Coerce to Symbol

* Apply literal to app/components/avo/profile_photo_component.rb

* Apply literal to app/components/avo/panel_name_component.rb

* Apply literal to app/components/avo/fields/show_component.rb

* Revert "Apply literal to app/components/avo/fields/show_component.rb"
because tests are failing

* Apply literal to app/components/avo/fields/edit_component.rb

* Revert "Apply literal to app/components/avo/fields/edit_component.rb"
because of failing tests

* Apply literal to app/components/avo/fields/tags_field/tag_component.rb

* Apply literal to app/components/avo/fields/common/gravatar_viewer_component.rb

* Apply literal to app/components/avo/fields/common/files/controls_component.rb

* Use correct type

* Apply literal to app/components/avo/fields/common/files/view_type/grid_item_component.rb

* Apply literal to app/components/avo/fields/common/files/list_viewer_component.rb

* Apply literal to app/components/avo/fields/common/badge_viewer_component.rb

* Apply literal to app/components/avo/fields/common/status_viewer_component.rb

* Apply literal to app/components/avo/fields/common/key_value_component.rb

* Apply literal to app/components/avo/fields/common/boolean_check_component.rb

* Apply literal to app/components/avo/fields/common/boolean_group_component.rb

* Apply literal to app/components/avo/fields/common/progress_bar_component.rb

* Apply literal to app/components/avo/fields/common/heading_component.rb

* Apply literal to app/components/avo/index/resource_grid_component.rb

* Apply literal to app/components/avo/index/table_row_component.rb

* Apply literal to app/components/avo/views/resource_index_component.rb

* Apply literal to app/components/avo/sidebar/link_component.rb

* Fix tests

* Apply literal to app/components/avo/items/panel_component.rb

* Apply literal to app/components/avo/sidebar/base_item_component.rb

* Apply literal to app/components/avo/sidebar/heading_component.rb

* Apply literal to app/components/avo/items/visible_items_component.rb

* Apply literal to app/components/avo/profile_item_component.rb

* Fix

* Lint

* view must be an instance of Avo::ViewInquirer

* Coerce value to symbol

* Remove reader from resource_sidebar_component

* Remove reader from app/components/avo/paginator_component.rb

* Remove reader from app/components/avo/empty_state_component.rb

* Remove reader from app/components/avo/row_component.rb

* Remove reader from app/components/avo/modal_component.rb

* Remove reader from app/components/avo/fields/tags_field/tag_component.rb

* Remove reader from app/components/avo/fields/common/files/controls_component.rb

* Remove reader from app/components/avo/fields/common/files/view_type/grid_item_component.rb

* Remove reader from app/components/avo/fields/common/files/list_viewer_component.rb

* Remove reader from app/components/avo/fields/common/key_value_component.rb

* Remove reader from app/components/avo/fields/common/progress_bar_component.rb

* Remove reader from app/components/avo/divider_component.rb

* Remove reader from app/components/avo/alert_component.rb

* Remove reader from app/components/avo/tab_switcher_component.rb

* Remove reader from app/components/avo/index/resource_grid_component.rb

* Revert because ./spec/features/avo/record_selector_spec.rb:20 fails

* Remove reader from app/components/avo/index/grid_item_component.rb

* Remove reader from app/components/avo/index/resource_table_component.rb

* Remove reader from app/components/avo/index/resource_controls_component.rb

* Remove reader from app/components/avo/index/field_wrapper_component.rb

* Remove reader from app/components/avo/panel_component.rb

* Remove reader from app/components/avo/views/resource_edit_component.rb

* Revert because display_breadcrumbs needs to be a reader

* Remove reader from app/components/avo/views/resource_edit_component.rb

* Remove reader from app/components/avo/views/resource_index_component.rb

* Remove reader from app/components/avo/sidebar_profile_component.rb

* Remove reader from app/components/avo/sidebar/link_component.rb

* Remove reader from app/components/avo/sidebar/base_item_component.rb

* Remove reader from app/components/avo/turbo_frame_wrapper_component.rb

* Remove reader from app/components/avo/referrer_params_component.rb

* Remove reader from app/components/avo/field_wrapper_component.rb

* Fix tests

* Delegate id to @field

* Fix tests

* Fix tests

* Set instance var without calling after_initialize

* Remove after_initialize from app/components/avo/cover_photo_component.rb

* Remove after_initialize for app/components/avo/fields/common/badge_viewer_component.rb

* Remove after_initialize for app/components/avo/fields/common/boolean_check_component.rb

* Remove after_initialize for app/components/avo/fields/common/heading_component.rb

* Remove after_initialize for app/components/avo/button_component.rb

* Remove after_initialize for app/components/avo/index/field_wrapper_component.rb

* Remove after_initialize for app/components/avo/views/resource_edit_component.rb

* Remove after_initialize for app/components/avo/field_wrapper_component.rb

* lint

* Update app/components/avo/fields/common/badge_viewer_component.rb

* Update app/components/avo/button_component.rb

* Update app/components/avo/fields/common/files/view_type/list_item_component.rb

* Update app/views/avo/base/_new_via_belongs_to.html.erb

* Update app/components/avo/index/field_wrapper_component.rb

* tweaks

* fixes

* prop view to Avo::ViewInquirer

* prop view to Avo::ViewInquirer

* tweaks

* tweaks

---------

Co-authored-by: Paul Bob <[email protected]>
Co-authored-by: Paul Bob <[email protected]>
  • Loading branch information
3 people committed Aug 19, 2024
1 parent efc1f9a commit ff35408
Show file tree
Hide file tree
Showing 78 changed files with 432 additions and 595 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gem 'redis', '~> 5.0'
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.2", require: false
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
gem "debug", platforms: [:mri, :mingw, :x64_mingw]
gem "dotenv-rails"
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "web-console", ">= 3.3.0"
Expand Down
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ GEM
builder (3.3.0)
bump (0.10.0)
bundler-integrity (1.0.9)
byebug (11.1.3)
capybara (3.40.0)
addressable
matrix
Expand Down Expand Up @@ -228,6 +227,9 @@ GEM
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.9.4)
Expand Down Expand Up @@ -670,14 +672,14 @@ DEPENDENCIES
bootsnap (>= 1.4.2)
bump
bundler-integrity (~> 1.0)
byebug
capybara
chartkick
countries
cssbundling-rails
csv
cuprite
database_cleaner-active_record
debug
devise
dotenv-rails
erb-formatter
Expand Down
6 changes: 2 additions & 4 deletions app/components/avo/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class Avo::ActionsComponent < Avo::BaseComponent
Array(exclude).to_set
end
prop :resource, _Nilable(Avo::BaseResource)
prop :view, _Nilable(Symbol) do |view|
view&.to_sym
end
prop :view, _Nilable(Avo::ViewInquirer)

def after_initialize
filter_actions
Expand Down Expand Up @@ -56,7 +54,7 @@ def is_disabled?(action)
private

def on_record_page?
@view.in?([:show, :edit, :new])
@view.in?(["show", "edit", "new"])
end

def on_index_page?
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/alert_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="ml-3 w-0 flex-1 pt-0.5">
<p class="text-sm leading-5 font-semibold">
<%= sanitize message.to_s %>
<%= sanitize @message.to_s %>
</p>
</div>
<div class="ml-4 flex-shrink-0 flex items-center">
Expand Down
19 changes: 7 additions & 12 deletions app/components/avo/alert_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
class Avo::AlertComponent < Avo::BaseComponent
include Avo::ApplicationHelper

attr_reader :type
attr_reader :message

def initialize(type, message)
@type = type
@message = message
end
prop :type, Symbol, :positional
prop :message, String, :positional

def icon
return "heroicons/solid/exclamation-circle" if is_error?
Expand Down Expand Up @@ -39,22 +34,22 @@ def classes
end

def is_error?
type.to_sym == :error || type.to_sym == :alert
@type.to_sym == :error || @type.to_sym == :alert
end

def is_success?
type.to_sym == :success
@type.to_sym == :success
end

def is_info?
type.to_sym == :notice || type.to_sym == :info
@type.to_sym == :notice || @type.to_sym == :info
end

def is_warning?
type.to_sym == :warning
@type.to_sym == :warning
end

def is_empty?
message.nil?
@message.nil?
end
end
6 changes: 2 additions & 4 deletions app/components/avo/backtrace_alert_component.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

class Avo::BacktraceAlertComponent < ViewComponent::Base
class Avo::BacktraceAlertComponent < Avo::BaseComponent
include Avo::ApplicationHelper

def initialize(backtrace: nil)
@backtrace = backtrace
end
prop :backtrace, _Nilable(Array)

def render?
@backtrace.present?
Expand Down
31 changes: 13 additions & 18 deletions app/components/avo/button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ class Avo::ButtonComponent < Avo::BaseComponent
SIZE = _Union(:xs, :sm, :md, :lg, :xl)
STYLE = _Union(:primary, :outline, :text, :icon)

def initialize(path = nil, size: :md, style: :outline, color: :gray, icon: nil, icon_class: "", is_link: false, rounded: true, compact: false, aria: {}, **args)
# Main settings
@size = size
@style = style
@color = color

# Other things that appear in the button
@path = path
@icon = icon
@icon_class = icon_class
@rounded = rounded
@compact = compact

# Other settings
@class = args[:class]
@is_link = is_link
@aria = aria
@args = args || {}
prop :path, _Nilable(String), :positional
prop :size, Symbol, default: :md
prop :style, Symbol, default: :outline
prop :color, Symbol, default: :gray
prop :icon, _Nilable(Symbol) do |value|
value&.to_sym
end
prop :icon_class, String, default: ""
prop :is_link, _Boolean, default: false
prop :rounded, _Boolean, default: true
prop :compact, _Boolean, default: false
prop :aria, Hash, default: {}.freeze
prop :args, Hash, :**, default: {}.freeze
prop :class, _Nilable(String)

def args
if @args[:loading]
Expand Down
8 changes: 4 additions & 4 deletions app/components/avo/cover_photo_component.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class Avo::CoverPhotoComponent < ViewComponent::Base
def initialize(cover_photo:)
@cover_photo = cover_photo
@size = cover_photo&.size
class Avo::CoverPhotoComponent < Avo::BaseComponent
prop :cover_photo, _Nilable(Avo::CoverPhoto)
prop :size, _Nilable(Symbol) do |value|
@cover_photo&.size
end

# aspect-cover-sm
Expand Down
4 changes: 2 additions & 2 deletions app/components/avo/divider_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="relative flex justify-center items-center w-full !border-b-2 border-gray-200 border-solid" data-component-name="<%= self.class.to_s.underscore %>">
<% if label.present? %>
<% if @label.present? %>
<div class="absolute inset-auto z-20 text-xs font-semibold uppercase leading-none text-gray-500 bg-white px-2 border py-1 rounded">
<%= label %>
<%= @label %>
</div>
<% end %>
</div>
7 changes: 2 additions & 5 deletions app/components/avo/divider_component.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# frozen_string_literal: true

class Avo::DividerComponent < Avo::BaseComponent
attr_reader :label

def initialize(label = nil, **args)
@label = label
end
prop :label, _Nilable(String), :positional
prop :args, Hash, :**
end
18 changes: 8 additions & 10 deletions app/components/avo/empty_state_component.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
# frozen_string_literal: true

class Avo::EmptyStateComponent < Avo::BaseComponent
attr_reader :message, :view_type, :add_background, :by_association

def initialize(message: nil, view_type: :table, add_background: false, by_association: false)
@message = message
@view_type = view_type
@add_background = add_background
@by_association = by_association
prop :message, _Nilable(String)
prop :view_type, Symbol, default: :table do |value|
value&.to_sym
end
prop :add_background, _Boolean, default: false
prop :by_association, _Boolean, default: false

def text
message || locale_message
@message || locale_message
end

def view_type_svg
"avo/#{view_type}-empty-state"
"avo/#{@view_type}-empty-state"
end

private

def locale_message
helpers.t by_association ? "avo.no_related_item_found" : "avo.no_item_found"
helpers.t @by_association ? "avo.no_related_item_found" : "avo.no_item_found"
end
end
18 changes: 9 additions & 9 deletions app/components/avo/field_wrapper_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
class: classes,
style: style,
data: data do %>
<%= content_tag :div, class: class_names("pt-4 flex self-start items-center flex-shrink-0 w-48 px-6 uppercase font-semibold text-gray-500 text-sm", @field.get_html(:classes, view: view, element: :label), {
<%= content_tag :div, class: class_names("pt-4 flex self-start items-center flex-shrink-0 w-48 px-6 uppercase font-semibold text-gray-500 text-sm", @field.get_html(:classes, view: @view, element: :label), {
"md:pt-4 md:w-full": stacked?,
"h-full md:pt-0": !stacked?,
"md:h-10 ": !stacked? && short?,
"md:h-14 ": !stacked? && !short?,
"md:w-48": compact?,
"md:w-64": !compact?,
}), data: {slot: "label"} do %>
<% if form.present? %>
<%= form.label label_for, label %>
<% if @form.present? %>
<%= @form.label label_for, label %>
<% else %>
<%= field.name %>
<%= @field.name %>
<% end %>
<% if on_edit? && field.is_required? %> <span class="text-red-600 ml-1">*</span> <% end %>
<% if on_edit? && @field.is_required? %> <span class="text-red-600 ml-1">*</span> <% end %>
<% end %>
<%= content_tag :div, class: class_names("flex-1 flex flex-row md:min-h-inherit px-6",
@field.get_html(:classes, view: view, element: :content),
@field.get_html(:classes, view: @view, element: :content),
{
"pb-4": stacked?,
"py-2": !compact?,
Expand All @@ -33,8 +33,8 @@
<% end %>
<% elsif on_edit? %>
<%= content %>
<% if record.present? and record.errors.include? field.id %>
<div class="text-red-600 mt-2 text-sm"><%= record.errors.full_messages_for(field.id).to_sentence %></div>
<% if record.present? and record.errors.include? @field.id %>
<div class="text-red-600 mt-2 text-sm"><%= record.errors.full_messages_for(@field.id).to_sentence %></div>
<% end %>
<% if help.present? %>
<div class="text-gray-600 mt-2 text-sm"><%= sanitize help %></div>
Expand All @@ -44,6 +44,6 @@
<% end %>
<% if params[:avo_debug].present? %>
<!-- Raw value: -->
<!-- <%= sanitize field.value.inspect %> -->
<!-- <%= sanitize @field.value.inspect %> -->
<% end %>
<% end %>
Loading

0 comments on commit ff35408

Please sign in to comment.