22
33module Dashboard
44 class ReleaseCardComponent < ApplicationComponent
5- # Lock the stimulus identifier to match the V1 component's, so the
6- # existing `app_components/dashboard/release_card_component_controller.js`
7- # still resolves against this V2 component without duplication.
8- # Emitted `data-controller="dashboard--release-card-component"`.
9- class << self
10- def stimulus_identifier_path = "dashboard/release_card_component"
11- end
12-
135 prop :release_id , Integer
146 prop :name , String
157 prop :version , String
168 prop :environment , _Union ( :production , :staging , :preview ) , default : :staging
179 prop :status , _Union ( :pending , :deployed , :failed ) , default : :pending
1810
19- # `stimulus_outlet_host:` is inherited from Vident::Component. Passing
20- # the parent page at render time causes this card to call
21- # `host.add_stimulus_outlets(self)` in after_initialize, which wires a
22- # `data-dashboard--page-component-dashboard--release-card-component-outlet`
23- # attribute onto the host's root element.
24-
2511 stimulus do
26- # Mirrors the :release_id / :name / :status props straight through as
27- # Stimulus values. No second declaration needed — the Resolver reads
28- # the `@ivar` current value at render time.
2912 values_from_props :release_id , :name , :status
3013
31- # Proc evaluated in the component instance, so it sees @status. The DSL
32- # emits a `data-<controller>-status-class="..."` attribute on the root
33- # which Stimulus exposes as `this.statusClasses` in the JS controller.
34- # `class_list_for_stimulus_classes(:status)` below inlines the same
35- # resolved value into the `class=` attribute for the first render.
14+ # Procs run in the component instance at render time, so they see
15+ # `@status`. `class_list_for_stimulus_classes(:status)` inlines the
16+ # same value into `class=` for the first paint.
3617 classes status : -> {
3718 case @status
3819 when :deployed then "border-green-500 bg-green-50"
@@ -41,9 +22,6 @@ def stimulus_identifier_path = "dashboard/release_card_component"
4122 end
4223 }
4324
44- # Fluent builder: reads left-to-right as "the `select` method fires
45- # on the `click` event". Emits `click->implied#select`. Equivalent
46- # V1-style shorthand `actions [:click, :select]` still works.
4725 action ( :select ) . on ( :click )
4826 end
4927
@@ -64,12 +42,9 @@ def view_template
6442 p ( class : "mt-3 text-xs uppercase tracking-wide text-gray-500" ) { @status . to_s }
6543
6644 div ( class : "mt-3 flex gap-2" ) do
67- # Demo of Stimulus params: one `apply` handler for both buttons, with
68- # `stimulus_params: { kind: ... }` on the element so the handler reads
69- # `event.params.kind` to tell which button fired. In a real app you'd
70- # probably just keep separate `promote` / `cancel` handlers — this
71- # intentional "one dispatch switch" shape is a bit RPC-ish and is
72- # here to show what the params feature looks like.
45+ # Both buttons share an `apply` handler; the controller reads
46+ # `event.params.kind` to tell them apart, matching each button's
47+ # `stimulus_params:` declaration.
7348 card . child_element (
7449 :button ,
7550 stimulus_action : [ :click , :apply ] ,
0 commit comments