Sha256: e427f92c73cd63ad4e8f71ea6aab49d76f788c019e82181682a979ff12a7b895
Contents?: true
Size: 1.86 KB
Versions: 3
Compression:
Stored size: 1.86 KB
Contents
# frozen_string_literal: true module RailsDevtools class DatabaseTables::TableCard < Components::ApplicationComponent def initialize(table:) @table = table end def view_template div(class: "card bg-white text-sm w-full shadow-sm") do div(class: "card-body") do h2(class: "card-title") { @table.table_name.capitalize } columns_list indexes_list end end end private def columns_list div(class: "flex flex-col gap-2 divide-y divide-base-200") do @table.columns.each do |column| div(class: "flex gap-x-2 text-neutral pt-2 justify-between items-center") do div(class: "flex gap-x-2") do div(class: "font-bold") { column.name } div(class: "text-neutral italic") { column.type } end span(class: "text-xs opacity-75") { column.default } if column.default div(class: "text-xs opacity-75") { "not null" } unless column.null end end end end def indexes_list div(class: "mt-8") do h3(class: "text-lg font-bold") { "#{@table.table_name.capitalize} indexes" } div(class: "mt-2 flex flex-col gap-2 divide-y divide-base-200") do @table.indexes.each do |index| div(class: "flex gap-x-2 text-neutral pt-2 justify-between items-center") do div do div(class: "font-bold") { index.name } div(class: "text-xs opacity-75") do [index.unique ? "unique" : nil, index_columns_text(index.columns)].compact.join(" ") end end end end end end end def index_columns_text(columns) columns_list = columns.join(", ") return columns_list if columns.size == 1 "composite of #{columns_list}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems