Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove types #3308

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,5 @@ gem "avo-record_link_field"
gem "pagy", "> 8"

gem "csv"

gem "prop_initializer", github: "avo-hq/prop_initializer", branch: "main"
11 changes: 9 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ GIT
acts-as-taggable-on (10.0.0)
activerecord (>= 6.1, < 8)

GIT
remote: https://github.com/avo-hq/prop_initializer.git
revision: ec6808bc18b00ee53123497e885305d4d63da9de
branch: main
specs:
prop_initializer (0.1.0)
zeitwerk (>= 2.6.18)

GIT
remote: https://github.com/rails/rails.git
revision: b88d9af34fbc1c84ce2769ba02584eab2c28ac6e
Expand Down Expand Up @@ -115,7 +123,6 @@ PATH
addressable
docile
inline_svg
literal (~> 0.2)
meta-tags
pagy (>= 7.0.0)
turbo-rails (>= 2.0.0)
Expand Down Expand Up @@ -391,7 +398,6 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
literal (0.2.1)
logger (1.6.1)
loofah (2.22.0)
crass (~> 1.0.2)
Expand Down Expand Up @@ -729,6 +735,7 @@ DEPENDENCIES
pg (>= 0.18, < 2.0)
pluggy!
prefixed_ids
prop_initializer!
puma (~> 6.4)
rails!
rails-controller-testing
Expand Down
30 changes: 14 additions & 16 deletions app/components/avo/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@
class Avo::ActionsComponent < Avo::BaseComponent
include Avo::ApplicationHelper

ACTION_FILTER = _Set(_Class(Avo::BaseAction))

prop :as_row_control, _Boolean, default: false
prop :icon, _Nilable(String)
prop :size, Avo::ButtonComponent::SIZE, default: :md
prop :title, _Nilable(String)
prop :color, _Nilable(Symbol) do |value|
prop :as_row_control, default: false
prop :icon
prop :size, default: :md
prop :title
prop :color do |value|
value || :primary
end
prop :include, _Nilable(ACTION_FILTER), default: [].freeze do |include|
prop :include, default: [].freeze do |include|
Array(include).to_set
end
prop :custom_list, _Boolean, default: false
prop :label, _Nilable(String) do |label|
prop :custom_list, default: false
prop :label do |label|
if @custom_list
label
else
label || I18n.t("avo.actions")
end
end
prop :style, Avo::ButtonComponent::STYLE, default: :outline
prop :actions, _Array(_Any), default: [].freeze
prop :exclude, _Nilable(ACTION_FILTER), default: [].freeze do |exclude|
prop :style, default: :outline
prop :actions, default: [].freeze
prop :exclude, default: [].freeze do |exclude|
Array(exclude).to_set
end
prop :resource, _Nilable(Avo::BaseResource)
prop :view, _Nilable(Avo::ViewInquirer)
prop :host_component, _Nilable(_Any)
prop :resource
prop :view
prop :host_component

delegate_missing_to :@host_component

Expand Down
4 changes: 2 additions & 2 deletions app/components/avo/alert_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class Avo::AlertComponent < Avo::BaseComponent
include Avo::ApplicationHelper

prop :type, Symbol, :positional
prop :message, String, :positional
prop :type, kind: :positional
prop :message, kind: :positional

def icon
return "heroicons/solid/exclamation-circle" if is_error?
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/asset_manager/javascript_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Avo::AssetManager::JavascriptComponent < Avo::BaseComponent
prop :asset_manager, Avo::AssetManager
prop :asset_manager

delegate :javascripts, to: :@asset_manager
end
2 changes: 1 addition & 1 deletion app/components/avo/asset_manager/stylesheet_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Avo::AssetManager::StylesheetComponent < Avo::BaseComponent
prop :asset_manager, Avo::AssetManager
prop :asset_manager

delegate :stylesheets, to: :@asset_manager
end
2 changes: 1 addition & 1 deletion app/components/avo/backtrace_alert_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Avo::BacktraceAlertComponent < Avo::BaseComponent
include Avo::ApplicationHelper

prop :backtrace, _Nilable(Array)
prop :backtrace

def render?
@backtrace.present?
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/base_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Avo::BaseComponent < ViewComponent::Base
extend Literal::Properties
extend PropInitializer::Properties
include Turbo::FramesHelper
include Avo::Concerns::FindAssociationField

Expand Down
27 changes: 12 additions & 15 deletions app/components/avo/button_component.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# frozen_string_literal: true

class Avo::ButtonComponent < Avo::BaseComponent
SIZE = _Union(:xs, :sm, :md, :lg, :xl)
STYLE = _Union(:primary, :outline, :text, :icon)

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|
prop :path, kind: :positional
prop :size, default: :md
prop :style, default: :outline
prop :color, default: :gray
prop :icon 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)
prop :icon_class, default: ""
prop :is_link, default: false
prop :rounded, default: true
prop :compact, default: false
prop :aria, default: {}.freeze
prop :args, kind: :**, default: {}.freeze
prop :class

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

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

Expand Down
4 changes: 2 additions & 2 deletions app/components/avo/divider_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Avo::DividerComponent < Avo::BaseComponent
prop :label, _Nilable(String), :positional
prop :args, Hash, :**
prop :label, kind: :positional
prop :args, kind: :**
end
8 changes: 4 additions & 4 deletions app/components/avo/empty_state_component.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

class Avo::EmptyStateComponent < Avo::BaseComponent
prop :message, _Nilable(String)
prop :view_type, Symbol, default: :table do |value|
prop :message
prop :view_type, default: :table do |value|
value&.to_sym
end
prop :add_background, _Boolean, default: false
prop :by_association, _Boolean, default: false
prop :add_background, default: false
prop :by_association, default: false

def text
@message || locale_message
Expand Down
32 changes: 16 additions & 16 deletions app/components/avo/field_wrapper_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
class Avo::FieldWrapperComponent < Avo::BaseComponent
include Avo::Concerns::HasResourceStimulusControllers

prop :dash_if_blank, _Boolean, default: true
prop :data, Hash, default: {}.freeze
prop :compact, _Boolean, default: false
prop :help, _Nilable(String)
prop :field, _Nilable(Avo::Fields::BaseField)
prop :form, _Nilable(ActionView::Helpers::FormBuilder)
prop :full_width, _Boolean, default: false
prop :label, _Nilable(String)
prop :resource, _Nilable(Avo::BaseResource)
prop :short, _Boolean, default: false
prop :stacked, _Nilable(_Boolean)
prop :style, String, default: ""
prop :view, Avo::ViewInquirer, default: Avo::ViewInquirer.new(:show).freeze
prop :label_for, _Nilable(Symbol) do |value|
prop :dash_if_blank, default: true
prop :data, default: {}.freeze
prop :compact, default: false
prop :help
prop :field
prop :form
prop :full_width, default: false
prop :label
prop :resource
prop :short, default: false
prop :stacked
prop :style, default: ""
prop :view, default: Avo::ViewInquirer.new(:show).freeze
prop :label_for do |value|
value&.to_sym
end
prop :args, Hash, :**, default: {}.freeze
prop :classes, _Nilable(String) do |value|
prop :args, kind: :**, default: {}.freeze
prop :classes do |value|
@args&.dig(:class) || ""
end

Expand Down
4 changes: 2 additions & 2 deletions app/components/avo/fields/common/badge_viewer_component.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class Avo::Fields::Common::BadgeViewerComponent < Avo::BaseComponent
prop :value, _Union(_String, _Symbol)
prop :options, Hash
prop :value
prop :options

def after_initialize
@backgrounds = {
Expand Down
6 changes: 3 additions & 3 deletions app/components/avo/fields/common/boolean_check_component.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

class Avo::Fields::Common::BooleanCheckComponent < Avo::BaseComponent
prop :checked, _Boolean, default: false
prop :icon, _Nilable(String) do |value|
prop :checked, default: false
prop :icon do |value|
@checked ? "heroicons/outline/check-circle" : "heroicons/outline/x-circle"
end
prop :classes, _Nilable(String) do |value|
prop :classes do |value|
"h-6 #{@checked ? "text-green-600" : "text-red-500"}"
end
end
4 changes: 2 additions & 2 deletions app/components/avo/fields/common/boolean_group_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Avo::Fields::Common::BooleanGroupComponent < Avo::BaseComponent
prop :options, Hash, default: {}.freeze
prop :value, _Nilable(Hash)
prop :options, default: {}.freeze
prop :value
end
6 changes: 3 additions & 3 deletions app/components/avo/fields/common/files/controls_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class Avo::Fields::Common::Files::ControlsComponent < Avo::BaseComponent

delegate :id, to: :@field

prop :field, Avo::Fields::BaseField
prop :file, _Any
prop :resource, Avo::BaseResource
prop :field
prop :file
prop :resource

def destroy_path
Avo::Services::URIService.parse(@resource.record_path).append_paths("active_storage_attachments", id, @file.id).to_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class Avo::Fields::Common::Files::ListViewerComponent < Avo::BaseComponent
include Turbo::FramesHelper

prop :field, Avo::Fields::BaseField
prop :resource, Avo::BaseResource
prop :field
prop :resource

def classes
base_classes = "py-4 rounded-2xl max-w-full"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

class Avo::Fields::Common::Files::ViewType::GridItemComponent < Avo::BaseComponent
prop :field, Avo::Fields::BaseField
prop :resource, Avo::BaseResource
prop :file, _Nilable(_Any)
prop :extra_classes, _Nilable(String)
prop :field
prop :resource
prop :file
prop :extra_classes

def id
@field.id
Expand Down
14 changes: 7 additions & 7 deletions app/components/avo/fields/common/gravatar_viewer_component.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

class Avo::Fields::Common::GravatarViewerComponent < Avo::BaseComponent
prop :md5, _Nilable(String)
prop :link, _Nilable(String)
prop :default, _Nilable(String)
prop :size, _Nilable(Integer)
prop :rounded, _Boolean, default: false
prop :link_to_record, _Boolean, default: false
prop :title, _Nilable(String)
prop :md5
prop :link
prop :default
prop :size
prop :rounded, default: false
prop :link_to_record, default: false
prop :title
end
2 changes: 1 addition & 1 deletion app/components/avo/fields/common/heading_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Avo::Fields::Common::HeadingComponent < Avo::BaseComponent
include Avo::Concerns::HasResourceStimulusControllers

prop :field, Avo::Fields::BaseField
prop :field

def after_initialize
@view = @field.resource.view
Expand Down
6 changes: 3 additions & 3 deletions app/components/avo/fields/common/key_value_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Avo::Fields::Common::KeyValueComponent < Avo::BaseComponent
include Avo::ApplicationHelper

prop :field, Avo::Fields::BaseField
prop :form, _Nilable(ActionView::Helpers::FormBuilder)
prop :view, Avo::ViewInquirer, default: Avo::ViewInquirer.new(:show).freeze
prop :field
prop :form
prop :view, default: Avo::ViewInquirer.new(:show).freeze
end
10 changes: 5 additions & 5 deletions app/components/avo/fields/common/progress_bar_component.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

class Avo::Fields::Common::ProgressBarComponent < Avo::BaseComponent
prop :value, Integer
prop :display_value, _Boolean, default: false
prop :value_suffix, _Nilable(String)
prop :max, Integer, default: 100
prop :view, Avo::ViewInquirer, reader: :public, default: Avo::ViewInquirer.new(:index).freeze
prop :value
prop :display_value, default: false
prop :value_suffix
prop :max, default: 100
prop :view, reader: :public, default: Avo::ViewInquirer.new(:index).freeze

delegate :show?, :index?, to: :view
end
4 changes: 2 additions & 2 deletions app/components/avo/fields/common/status_viewer_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Avo::Fields::Common::StatusViewerComponent < Avo::BaseComponent
prop :status, String
prop :label, String
prop :status
prop :label
end
Loading
Loading