From 551a1b6c4644340a8bb2a0e9f01432a5bd0aa852 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 28 Mar 2024 13:50:48 +0100 Subject: [PATCH] State table contains suspend and catch tuples. --- .../workflow/generate/state_table.rb | 7 +++--- .../workflow/introspect/state_table.rb | 10 ++++++++- test/generate_test.rb | 22 ++++++++++--------- test/introspect_test.rb | 1 + 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/trailblazer/workflow/generate/state_table.rb b/lib/trailblazer/workflow/generate/state_table.rb index 68a3181..9037573 100644 --- a/lib/trailblazer/workflow/generate/state_table.rb +++ b/lib/trailblazer/workflow/generate/state_table.rb @@ -14,7 +14,8 @@ def render(ctx, rows:, namespace:, **) available_states = rows.collect do |row| { suggested_state_name: row["state name"], - key: row[:catch_events].collect { |position| Introspect::Present.id_for_position(position) }.uniq.sort + suspend_tuples: row[:suspend_tuples], # to "compute" the actual state configuration. + catch_events: row["Catch IDs"], } end @@ -22,9 +23,9 @@ def render(ctx, rows:, namespace:, **) max_length = available_states.collect { |row| row[:suggested_state_name].inspect.length }.max state_guard_rows = available_states.collect do |row| - id_snippet = %(id: #{row[:key].inspect}) # TODO: move me to serializer code. + id_snippet = %(suspend_tuples: #{row[:suspend_tuples].inspect}) # TODO: move me to serializer code. - %( #{row[:suggested_state_name].inspect.ljust(max_length)} => {#{id_snippet}},) # TODO: rename {:id} to {:catch_event[_id]s} + %( #{row[:suggested_state_name].inspect.ljust(max_length)} => {#{id_snippet}, catch_tuples: #{row[:catch_events]}}) end.join("\n") snippet = %(# This file is generated by trailblazer-workflow. diff --git a/lib/trailblazer/workflow/introspect/state_table.rb b/lib/trailblazer/workflow/introspect/state_table.rb index d39e1bc..c1382e0 100644 --- a/lib/trailblazer/workflow/introspect/state_table.rb +++ b/lib/trailblazer/workflow/introspect/state_table.rb @@ -45,6 +45,11 @@ def render_data(ctx, states:, lanes_cfg:, **) readable_suspend_id_hints = suspend_id_hints.join(" ") + catch_event_tuples = catch_events.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}" @@ -68,7 +73,10 @@ def render_data(ctx, states:, lanes_cfg:, **) suggested_state_name, "triggerable events", - triggerable_events, + triggerable_events, # DISCUSS: do we need that? + + "Catch IDs", + catch_event_tuples, "Suspend IDs", readable_suspend_id_hints, diff --git a/test/generate_test.rb b/test/generate_test.rb index 8093157..bfdb8c9 100644 --- a/test/generate_test.rb +++ b/test/generate_test.rb @@ -7,20 +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 = { - "⏸︎ Create form" => {id: ["catch-before-Activity_0wc2mcq"]}, - "⏸︎ Create" => {id: ["catch-before-Activity_1psp91r"]}, - "⏸︎ Update form♦Notify approver" => {id: ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"]}, - "⏸︎ Update" => {id: ["catch-before-Activity_0j78uzd"]}, - "⏸︎ Delete? form♦Publish" => {id: ["catch-before-Activity_0bsjggk", "catch-before-Activity_0ha7224"]}, - "⏸︎ Revise form" => {id: ["catch-before-Activity_0zsock2"]}, - "⏸︎ Delete♦Cancel" => {id: ["catch-before-Activity_15nnysv", "catch-before-Activity_1uhozy1"]}, - "⏸︎ Archive" => {id: ["catch-before-Activity_0fy41qq"]}, - "⏸︎ Revise" => {id: ["catch-before-Activity_1wiumzv"]}, + "⏸︎ 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"]]} } end ) diff --git a/test/introspect_test.rb b/test/introspect_test.rb index fb26a8c..b57a729 100644 --- a/test/introspect_test.rb +++ b/test/introspect_test.rb @@ -13,6 +13,7 @@ class IntrospectStateTableTest < Minitest::Spec "⛾ 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" ] + # required in {StateTable::Generate} assert_equal ctx[:rows].collect { |row| row[:suspend_tuples] }, [ [["lifecycle", "suspend-gw-to-catch-before-Activity_1hgscu3"], ["UI", "suspend-gw-to-catch-before-Activity_0fy41qq"], ["approver", "~suspend~"]], [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-Gateway_14h0q7a"], ["approver", "~suspend~"]], [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-gw-to-catch-before-Activity_0wc2mcq"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_100g9dn"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-Gateway_1xs96ik"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-gw-to-catch-before-Activity_0zsock2"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_1kl7pnm"], ["UI", "suspend-Gateway_00n4dsm"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0nxerxv"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_1sq41iq"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0kknfje"], ["approver", "~suspend~"]], [["lifecycle", "suspend-Gateway_1wzosup"], ["UI", "suspend-Gateway_1g3fhu2"], ["approver", "~suspend~"]] ]