From 6f5185e7f4c64a0c8004635f9a3431fae5dc8eda Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Mon, 25 Mar 2024 12:40:01 +0100 Subject: [PATCH] StateTable can now render multiple "identical" states (which are actually not identical suspends, but point to the identical target catches). --- .../workflow/introspect/state_table.rb | 23 +++++++++++-- test/introspect_test.rb | 32 ++++++++++--------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/lib/trailblazer/workflow/introspect/state_table.rb b/lib/trailblazer/workflow/introspect/state_table.rb index 2df67c0..091ce33 100644 --- a/lib/trailblazer/workflow/introspect/state_table.rb +++ b/lib/trailblazer/workflow/introspect/state_table.rb @@ -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 = {} @@ -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", diff --git a/test/introspect_test.rb b/test/introspect_test.rb index 293e39e..966e9e8 100644 --- a/test/introspect_test.rb +++ b/test/introspect_test.rb @@ -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