Skip to content

Commit

Permalink
State table contains suspend and catch tuples.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Mar 28, 2024
1 parent 2090bdd commit 551a1b6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
7 changes: 4 additions & 3 deletions lib/trailblazer/workflow/generate/state_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ 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

# formatting, find longest state name.
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.
Expand Down
10 changes: 9 additions & 1 deletion lib/trailblazer/workflow/introspect/state_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions test/generate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions test/introspect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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~"]]
]
Expand Down

0 comments on commit 551a1b6

Please sign in to comment.