Skip to content

Commit

Permalink
StateTable can now render multiple "identical" states (which are actu…
Browse files Browse the repository at this point in the history
…ally not identical

suspends, but point to the identical target catches).
  • Loading branch information
apotonick committed Mar 25, 2024
1 parent 8b03cc5 commit 6f5185e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
23 changes: 21 additions & 2 deletions lib/trailblazer/workflow/introspect/state_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module Introspect
# Rendering-specific code using {Iteration::Set}.
# Each row represents a configuration of suspends aka "state".
# The state knows its possible resume events.
# does the state know which state fields belong to it?
# DISCUSS: does the state know which state fields belong to it?
class StateTable < Trailblazer::Activity::Railway
step :aggregate_by_state
step :render_data

def aggregate_by_state(ctx, iteration_set:, **)
def aggregate_by_state(ctx, iteration_set:, lanes_cfg:, **)
# Key by lane_positions, which represent a state.
# State (lane_positions) => [events (start position)]
states = {}
Expand All @@ -32,15 +32,34 @@ def aggregate_by_state(ctx, iteration_set:, **)
end

def render_data(ctx, states:, lanes_cfg:, **)
suggested_state_names = {}

cli_rows = states.flat_map do |positions, catch_events|
suspend_tuples = positions.to_a.collect do |position|
Iteration::Set::Serialize.id_tuple_for(*position.to_a, lanes_cfg: lanes_cfg)
end

suggested_state_name = suggested_state_name_for(catch_events)

suggested_state_name = "⏸︎ #{suggested_state_name}"

# add an "ID hint" to the state name (part of the actual suspend gw's ID).
if suggested_state_names[suggested_state_name]
last_lane = catch_events[0].activity # DISCUSS: could be more explicit.
suspend_id_hint = positions[last_lane].to_h[:semantic][1][-8..]

suggested_state_name = "#{suggested_state_name} (#{suspend_id_hint})"
else
suggested_state_names[suggested_state_name] = true
end

triggerable_events = catch_events
.collect { |event_position| Present.readable_name_for_catch_event(*event_position.to_a, lanes_cfg: lanes_cfg).inspect }
.join(", ")

# key: row[:catch_events].collect { |position| Introspect::Present.id_for_position(position) }.uniq.sort



Hash[
"state name",
Expand Down
32 changes: 17 additions & 15 deletions test/introspect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@ class IntrospectStateTableTest < Minitest::Spec
signal, (ctx, _) = Trailblazer::Workflow::Introspect::StateTable.invoke([{iteration_set: iteration_set, lanes_cfg: lanes_cfg}, {}])

assert_equal ctx[:rows].collect { |row| row["state name"] }.inspect,
%(["⏸︎ Archive", "⏸︎ Create", "⏸︎ Create form", "⏸︎ Delete? form♦Publish", "⏸︎ Delete♦Cancel", "⏸︎ Revise", "⏸︎ Revise form", "⏸︎ Update", "⏸︎ Update form♦Notify approver"])
%(["⏸︎ Archive", "⏸︎ Create", "⏸︎ Create form", "⏸︎ Delete♦Cancel", "⏸︎ Revise", "⏸︎ Revise form", "⏸︎ Revise form♦Notify approver", "⏸︎ Update", "⏸︎ Update form♦Delete? form♦Publish", "⏸︎ Update form♦Notify approver", "⏸︎ Update form♦Notify approver (_1g3fhu2)"])
end

it "StateTable.render" do
iteration_set, lanes_cfg = fixtures()

_, (ctx, _) = Trailblazer::Workflow::Introspect::StateTable::Render.invoke([{iteration_set: iteration_set, lanes_cfg: lanes_cfg}, {}])
# puts ctx[:table]
puts ctx[:table]
assert_equal ctx[:table],
%(+---------------------------------+----------------------------------------+
| state name | triggerable events |
+---------------------------------+----------------------------------------+
| "⏸︎ Archive" | "☝ ⏵︎Archive" |
| "⏸︎ Create" | "☝ ⏵︎Create" |
| "⏸︎ Create form" | "☝ ⏵︎Create form" |
| "⏸︎ Delete? form♦Publish" | "☝ ⏵︎Delete? form", "☝ ⏵︎Publish" |
| "⏸︎ Delete♦Cancel" | "☝ ⏵︎Delete", "☝ ⏵︎Cancel" |
| "⏸︎ Revise" | "☝ ⏵︎Revise" |
| "⏸︎ Revise form" | "☝ ⏵︎Revise form" |
| "⏸︎ Update" | "☝ ⏵︎Update" |
| "⏸︎ Update form♦Notify approver" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" |
+---------------------------------+----------------------------------------+)
%(+--------------------------------------------+---------------------------------------------------+
| state name | triggerable events |
+--------------------------------------------+---------------------------------------------------+
| "⏸︎ Archive" | "☝ ⏵︎Archive" |
| "⏸︎ Create" | "☝ ⏵︎Create" |
| "⏸︎ Create form" | "☝ ⏵︎Create form" |
| "⏸︎ Delete♦Cancel" | "☝ ⏵︎Delete", "☝ ⏵︎Cancel" |
| "⏸︎ Revise" | "☝ ⏵︎Revise" |
| "⏸︎ Revise form" | "☝ ⏵︎Revise form" |
| "⏸︎ Revise form♦Notify approver" | "☝ ⏵︎Revise form", "☝ ⏵︎Notify approver" |
| "⏸︎ Update" | "☝ ⏵︎Update" |
| "⏸︎ Update form♦Delete? form♦Publish" | "☝ ⏵︎Update form", "☝ ⏵︎Delete? form", "☝ ⏵︎Publish" |
| "⏸︎ Update form♦Notify approver" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" |
| "⏸︎ Update form♦Notify approver (_1g3fhu2)" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" |
+--------------------------------------------+---------------------------------------------------+)
end
end

0 comments on commit 6f5185e

Please sign in to comment.