From f2e069213726a4fbc5570948e74327b9c4d50bed Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 28 Mar 2024 14:28:27 +0100 Subject: [PATCH] the StateTable now has a unique "suggested state name" for each state, by including the first character of each suspend ID. --- .../workflow/introspect/state_table.rb | 19 +++++++---- test/generate_test.rb | 24 +++++++------- test/introspect_test.rb | 32 +++++++++---------- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/lib/trailblazer/workflow/introspect/state_table.rb b/lib/trailblazer/workflow/introspect/state_table.rb index c1382e0..be1365c 100644 --- a/lib/trailblazer/workflow/introspect/state_table.rb +++ b/lib/trailblazer/workflow/introspect/state_table.rb @@ -5,6 +5,10 @@ module Introspect # Each row represents a configuration of suspends aka "state". # The state knows its possible resume events. # DISCUSS: does the state know which state fields belong to it? + + # A state table maintains all reachable combinations of suspend events in the collaboration ("configuration"). + # Each state has a suggested state name that includes the reachable catch events per suspend. + # This structure usually only changes when modifying the diagram. class StateTable < Trailblazer::Activity::Railway step :aggregate_by_state step :render_data @@ -51,17 +55,18 @@ def render_data(ctx, states:, lanes_cfg:, **) suggested_state_name = suggested_state_name_for(catch_events) + state_id_hint = suspend_id_hints.collect { |id_hint| id_hint[2] }.join("") - suggested_state_name = "⏸︎ #{suggested_state_name}" + suggested_state_name = "⏸︎ #{suggested_state_name} [#{state_id_hint}]" # 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. + # if suggested_state_names[suggested_state_name] + # last_lane = catch_events[0].activity # DISCUSS: could be more explicit. - suggested_state_name = "#{suggested_state_name}" - else - suggested_state_names[suggested_state_name] = true - end + # suggested_state_name = "#{suggested_state_name}" + # 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 } diff --git a/test/generate_test.rb b/test/generate_test.rb index bfdb8c9..1a2be80 100644 --- a/test/generate_test.rb +++ b/test/generate_test.rb @@ -7,22 +7,22 @@ class GenerateStateTableTest < Minitest::Spec _, (ctx, _) = Trailblazer::Workflow::Generate::StateTable.invoke([{iteration_set: iteration_set, lanes_cfg: lanes_cfg, namespace: "App::Posting"}, {}]) - # puts ctx[:snippet] + puts ctx[:snippet] assert_equal ctx[:snippet], %(# This file is generated by trailblazer-workflow. module App::Posting::Generated StateTable = { - "⏸︎ Archive" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_1hgscu3"], ["UI", "suspend-gw-to-catch-before-Activity_0fy41qq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0fy41qq"]]} - "⏸︎ Create" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-Gateway_14h0q7a"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1psp91r"]]} - "⏸︎ Create form" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-gw-to-catch-before-Activity_0wc2mcq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0wc2mcq"]]} - "⏸︎ Delete♦Cancel" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_100g9dn"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_15nnysv"], ["UI", "catch-before-Activity_1uhozy1"]]} - "⏸︎ Revise" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-Gateway_1xs96ik"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1wiumzv"]]} - "⏸︎ Revise form" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-gw-to-catch-before-Activity_0zsock2"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"]]} - "⏸︎ Revise form♦Notify approver" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1kl7pnm"], ["UI", "suspend-Gateway_00n4dsm"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"], ["UI", "catch-before-Activity_1dt5di5"]]} - "⏸︎ Update" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0nxerxv"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0j78uzd"]]} - "⏸︎ Update form♦Delete? form♦Publish" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_1sq41iq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_0ha7224"], ["UI", "catch-before-Activity_0bsjggk"]]} - "⏸︎ Update form♦Notify approver" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0kknfje"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]} - "⏸︎ Update form♦Notify approver" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1wzosup"], ["UI", "suspend-Gateway_1g3fhu2"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]} + "⏸︎ Archive [10u]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_1hgscu3"], ["UI", "suspend-gw-to-catch-before-Activity_0fy41qq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0fy41qq"]]} + "⏸︎ Create [01u]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-Gateway_14h0q7a"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1psp91r"]]} + "⏸︎ Create form [00u]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-gw-to-catch-before-Activity_0wc2mcq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0wc2mcq"]]} + "⏸︎ Delete♦Cancel [11u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_100g9dn"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_15nnysv"], ["UI", "catch-before-Activity_1uhozy1"]]} + "⏸︎ Revise [01u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-Gateway_1xs96ik"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1wiumzv"]]} + "⏸︎ Revise form [00u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-gw-to-catch-before-Activity_0zsock2"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"]]} + "⏸︎ Revise form♦Notify approver [10u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1kl7pnm"], ["UI", "suspend-Gateway_00n4dsm"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"], ["UI", "catch-before-Activity_1dt5di5"]]} + "⏸︎ Update [00u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0nxerxv"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0j78uzd"]]} + "⏸︎ Update form♦Delete? form♦Publish [11u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_1sq41iq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_0ha7224"], ["UI", "catch-before-Activity_0bsjggk"]]} + "⏸︎ Update form♦Notify approver [00u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0kknfje"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]} + "⏸︎ Update form♦Notify approver [11u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1wzosup"], ["UI", "suspend-Gateway_1g3fhu2"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]} } end ) diff --git a/test/introspect_test.rb b/test/introspect_test.rb index b57a729..14a2970 100644 --- a/test/introspect_test.rb +++ b/test/introspect_test.rb @@ -7,7 +7,7 @@ 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♦Cancel", "⏸︎ Revise", "⏸︎ Revise form", "⏸︎ Revise form♦Notify approver", "⏸︎ Update", "⏸︎ Update form♦Delete? form♦Publish", "⏸︎ Update form♦Notify approver", "⏸︎ Update form♦Notify approver"]) + %(["⏸︎ Archive [10u]", "⏸︎ Create [01u]", "⏸︎ Create form [00u]", "⏸︎ Delete♦Cancel [11u]", "⏸︎ Revise [01u]", "⏸︎ Revise form [00u]", "⏸︎ Revise form♦Notify approver [10u]", "⏸︎ Update [00u]", "⏸︎ Update form♦Delete? form♦Publish [11u]", "⏸︎ Update form♦Notify approver [00u]", "⏸︎ Update form♦Notify approver [11u]"]) assert_equal ctx[:rows].collect { |row| row["Suspend IDs"] }, [ "⛾ 1hgs ☝ 0fy4 ☑ uspe", "⛾ 0wwf ☝ 14h0 ☑ uspe", "⛾ 0wwf ☝ 0wc2 ☑ uspe", "⛾ 1hp2 ☝ 100g ☑ uspe", "⛾ 01p7 ☝ 1xs9 ☑ uspe", "⛾ 01p7 ☝ 0zso ☑ uspe", "⛾ 1kl7 ☝ 00n4 ☑ uspe", "⛾ 0fnb ☝ 0nxe ☑ uspe", "⛾ 1hp2 ☝ 1sq4 ☑ uspe", "⛾ 0fnb ☝ 0kkn ☑ uspe", "⛾ 1wzo ☝ 1g3f ☑ uspe" @@ -25,20 +25,20 @@ class IntrospectStateTableTest < Minitest::Spec _, (ctx, _) = Trailblazer::Workflow::Introspect::StateTable::Render.invoke([{iteration_set: iteration_set, lanes_cfg: lanes_cfg}, {}]) # puts ctx[:table] assert_equal ctx[:table], -%(+--------------------------------------+---------------------------------------------------+----------------------+ -| state name | triggerable events | Suspend IDs | -+--------------------------------------+---------------------------------------------------+----------------------+ -| "⏸︎ Archive" | "☝ ⏵︎Archive" | ⛾ 1hgs ☝ 0fy4 ☑ uspe | -| "⏸︎ Create" | "☝ ⏵︎Create" | ⛾ 0wwf ☝ 14h0 ☑ uspe | -| "⏸︎ Create form" | "☝ ⏵︎Create form" | ⛾ 0wwf ☝ 0wc2 ☑ uspe | -| "⏸︎ Delete♦Cancel" | "☝ ⏵︎Delete", "☝ ⏵︎Cancel" | ⛾ 1hp2 ☝ 100g ☑ uspe | -| "⏸︎ Revise" | "☝ ⏵︎Revise" | ⛾ 01p7 ☝ 1xs9 ☑ uspe | -| "⏸︎ Revise form" | "☝ ⏵︎Revise form" | ⛾ 01p7 ☝ 0zso ☑ uspe | -| "⏸︎ Revise form♦Notify approver" | "☝ ⏵︎Revise form", "☝ ⏵︎Notify approver" | ⛾ 1kl7 ☝ 00n4 ☑ uspe | -| "⏸︎ Update" | "☝ ⏵︎Update" | ⛾ 0fnb ☝ 0nxe ☑ uspe | -| "⏸︎ Update form♦Delete? form♦Publish" | "☝ ⏵︎Update form", "☝ ⏵︎Delete? form", "☝ ⏵︎Publish" | ⛾ 1hp2 ☝ 1sq4 ☑ uspe | -| "⏸︎ Update form♦Notify approver" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" | ⛾ 0fnb ☝ 0kkn ☑ uspe | -| "⏸︎ Update form♦Notify approver" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" | ⛾ 1wzo ☝ 1g3f ☑ uspe | -+--------------------------------------+---------------------------------------------------+----------------------+) +%(+--------------------------------------------+---------------------------------------------------+----------------------+ +| state name | triggerable events | Suspend IDs | ++--------------------------------------------+---------------------------------------------------+----------------------+ +| "⏸︎ Archive [10u]" | "☝ ⏵︎Archive" | ⛾ 1hgs ☝ 0fy4 ☑ uspe | +| "⏸︎ Create [01u]" | "☝ ⏵︎Create" | ⛾ 0wwf ☝ 14h0 ☑ uspe | +| "⏸︎ Create form [00u]" | "☝ ⏵︎Create form" | ⛾ 0wwf ☝ 0wc2 ☑ uspe | +| "⏸︎ Delete♦Cancel [11u]" | "☝ ⏵︎Delete", "☝ ⏵︎Cancel" | ⛾ 1hp2 ☝ 100g ☑ uspe | +| "⏸︎ Revise [01u]" | "☝ ⏵︎Revise" | ⛾ 01p7 ☝ 1xs9 ☑ uspe | +| "⏸︎ Revise form [00u]" | "☝ ⏵︎Revise form" | ⛾ 01p7 ☝ 0zso ☑ uspe | +| "⏸︎ Revise form♦Notify approver [10u]" | "☝ ⏵︎Revise form", "☝ ⏵︎Notify approver" | ⛾ 1kl7 ☝ 00n4 ☑ uspe | +| "⏸︎ Update [00u]" | "☝ ⏵︎Update" | ⛾ 0fnb ☝ 0nxe ☑ uspe | +| "⏸︎ Update form♦Delete? form♦Publish [11u]" | "☝ ⏵︎Update form", "☝ ⏵︎Delete? form", "☝ ⏵︎Publish" | ⛾ 1hp2 ☝ 1sq4 ☑ uspe | +| "⏸︎ Update form♦Notify approver [00u]" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" | ⛾ 0fnb ☝ 0kkn ☑ uspe | +| "⏸︎ Update form♦Notify approver [11u]" | "☝ ⏵︎Update form", "☝ ⏵︎Notify approver" | ⛾ 1wzo ☝ 1g3f ☑ uspe | ++--------------------------------------------+---------------------------------------------------+----------------------+) end end