Sha256: b2694a5688332c1fbe177e57fba5f6a2e98a3338392b86a312abcc8979534caa

Contents?: true

Size: 1.72 KB

Versions: 10

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Tables
    module Selectable
      class FormComponent < ViewComponent::Base # :nodoc:
        include Katalyst::HtmlAttributes
        include Katalyst::Tables::Identifiable::Defaults

        attr_reader :id, :primary_key

        # @param collection [Katalyst::Tables::Collection::Core] the collection to render
        # @param id [String] the id of the form element (defaults to <resources>_selection_form)
        # @param primary_key [String] the primary key of the record in the collection (defaults to :id)
        def initialize(collection:,
                       id: nil,
                       primary_key: :id)
          super()

          @collection  = collection
          @id          = id || Selectable.default_form_id(collection)
          @primary_key = primary_key
        end

        def inspect
          "#<#{self.class.name} id: #{id.inspect}, primary_key: #{primary_key.inspect}>"
        end

        private

        def default_html_attributes
          {
            id:,
            class: "tables--selection--form",
            data:  {
              controller:   form_controller,
              turbo_action: "replace",
            },
            html:  { action: false, hidden: "" },
          }
        end

        def form_controller
          FORM_CONTROLLER
        end

        def form_target(value)
          "#{FORM_CONTROLLER}-target=#{value}"
        end

        def singular_name
          @collection.model_name.human(count: 1, default: @collection.model_name.human).downcase
        end

        def plural_name
          @collection.model_name.human(count: 2, default: @collection.model_name.human.pluralize).downcase
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
katalyst-tables-3.8.0 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.7.0 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.6.2 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.6.1 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.6.0 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.5.5 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.5.4 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.5.3 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.5.2 app/components/katalyst/tables/selectable/form_component.rb
katalyst-tables-3.5.1 app/components/katalyst/tables/selectable/form_component.rb