Module: Athar::Dashboard::CellHelper

Included in:
Athar::DashboardHelper
Defined in:
app/helpers/athar/dashboard/cell_helper.rb

Overview

Visual atoms for the deletion-feed table cells: capture-mode/mask pills, the kind glyph, copy buttons, the inline metadata preview, and the actor-cell label/role helpers.

Instance Method Summary collapse

Instance Method Details

#actor_label(deletion) ⇒ Object

Fallback used by _row.html.erb only when @actor_labels is missing an entry, which happens for rows with NULL actor_id (system or anonymous). Any row with a present actor_id has already been batch-resolved in the controller.



68
69
70
71
72
73
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 68

def actor_label(deletion)
  return "#{deletion[:actor_type]}##{deletion[:actor_id]}" if deletion[:actor_id].present?
  return deletion.dig(:metadata, "actor") if deletion[:metadata].is_a?(Hash) && deletion[:metadata]["actor"]

  ""
end

#actor_role(row) ⇒ Object

Returns one of: “engineer” (AR-backed actor), “job” (system actor via metadata.actor), or “anonymous” (no actor info).



77
78
79
80
81
82
83
84
85
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 77

def actor_role(row)
  if row[:actor_id].present?
    "engineer"
  elsif row[:metadata].is_a?(Hash) && row[:metadata]["actor"]
    "job"
  else
    "anonymous"
  end
end

#copy_button(value, label:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 23

def copy_button(value, label:)
  button_tag(type: "button",
             class: "copy-btn",
             aria: { label: "Copy #{label}" },
             data: {
               athar_copy: value,
               athar_copy_label: label
             }) do
    raw(icon_copy)
  end
end

#kind_icon(kind) ⇒ Object



19
20
21
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 19

def kind_icon(kind)
  (:span, raw(kind == "truncate" ? icon_trunc : icon_del), class: "kind-icon kind-#{kind}")
end

#mask_pill(masks) ⇒ Object



13
14
15
16
17
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 13

def mask_pill(masks)
  return nil if masks.blank?

  (:span, "m#{masks.length}", class: "pill mask-pill", title: "masks: #{masks.join(", ")}")
end

#metadata_preview(metadata) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 35

def () # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
  # Drop "actor" since the actor column already renders it; the expanded
  # detail still shows the full unfiltered metadata.
   = ( || {}).to_h.except("actor")

  return (:span, "{}", class: "muted") if .empty?

  keys = .keys
  pairs = keys.first(4).map do |key|
    value = [key]
    value_text = value.is_a?(String) ? value : value.to_json

    (:span, class: "meta-kv") do
      safe_join(
        [
          (:span, ERB::Util.html_escape(key), class: "meta-k"),
          (:span, ERB::Util.html_escape(value_text), class: "meta-v")
        ],
        " "
      )
    end
  end

  separator = (:span, "·", class: "dot-sep")
  html = pairs.flat_map.with_index { |pair, index| index.zero? ? [pair] : [separator, pair] }
  html << (:span, "+#{keys.length - 4}", class: "dim") if keys.length > 4
  (:span, safe_join(html, " "), class: "summary-bits")
end

#mode_pill(mode) ⇒ Object



9
10
11
# File 'app/helpers/athar/dashboard/cell_helper.rb', line 9

def mode_pill(mode)
  (:span, mode, class: "pill mode-pill mode-#{mode}")
end