Skip to content

Commit

Permalink
we can render the discovered runtime state table in cli.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jan 23, 2024
1 parent ef0d20f commit 0a00e89
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
42 changes: 36 additions & 6 deletions lib/trailblazer/workflow/state/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ def self.id_tuple_for(lanes, activity, task)
return activity_id, task_id
end

def self.generate_state_table(discovery_states, lanes:, initial_lane_positions:)
def self.generate_state_table(discovery_states, lanes:)
state_table = discovery_states.collect do |state| # state = {start_position, lane_states: [{activity, suspend, resumes}]}

# what we want:
# event_name => [activity, task], [lane_positions]
# [start_position]

lane_positions, start_position = state.to_a
# puts "@@@@@ #{start_position.inspect}"
# puts "@@@@@ #{lane_positions.inspect}"

# raise start_position.inspect

Expand All @@ -47,7 +45,7 @@ def self.generate_state_table(discovery_states, lanes:, initial_lane_positions:)
next if lane_position.nil? # FIXME: why do we have that?


Testing.serialize_lane_position(lane_position, lanes: lanes, initial_lane_positions: initial_lane_positions)
Testing.serialize_lane_position(lane_position, lanes: lanes)
end

{
Expand All @@ -61,9 +59,41 @@ def self.generate_state_table(discovery_states, lanes:, initial_lane_positions:)

end

pp state_table
raise
state_table
end

def self.render_cli_state_table(state_table)
rows = state_table.collect do |row|
start_lane_id, start_lane_task_id = row[:start_position][:tuple]

lane_positions = row[:lane_positions].flat_map do |lane_position|
lane_id, suspend_id = lane_position[:tuple]
comment = lane_position[:comment]

[
lane_id,
comment
]
end

Hash[
"event name",
row[:event_name].inspect,

"triggered catch event",
"#{start_lane_id} / (?) --> [#{row[:start_position][:comment][1]}]",

*lane_positions
]
end

lane_ids = state_table[0][:lane_positions].collect { |lane_position| lane_position[:tuple][0] }

Hirb::Helpers::Table.render(rows, fields: [
"event name",
"triggered catch event",
*lane_ids,
], max_width: 186) # 186 for laptop 13"
end

# Find the next connected task, usually outgoing from a catch event.
Expand Down
11 changes: 6 additions & 5 deletions lib/trailblazer/workflow/state/discovery/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.render_json(states, lanes:, additional_state_data:, initial_lane_positi
end

# A lane position is always a {Suspend} (or a terminus).
def self.serialize_lane_position(lane_position, lanes:, initial_lane_positions:)
def self.serialize_lane_position(lane_position, lanes:)
activity, suspend = lane_position.to_a

position_tuple = Discovery.id_tuple_for(lanes, activity, suspend) # usually, this is a suspend. sometimes a terminus {End}.
Expand All @@ -57,11 +57,12 @@ def self.serialize_lane_position(lane_position, lanes:, initial_lane_positions:)

comment = resumes_label

{
tuple: position_tuple,
comment: comment
}
end

{
tuple: position_tuple,
comment: comment
}
end

end # Testing
Expand Down
27 changes: 24 additions & 3 deletions test/collaboration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,30 @@ def render_states(states, lanes:, additional_state_data:, task_map:)
# raise "figure out how to build a generated state table"


state_table = Trailblazer::Workflow::State::Discovery.generate_state_table(states, lanes: ___lanes___, initial_lane_positions: initial_lane_positions)


state_table = Trailblazer::Workflow::State::Discovery.generate_state_table(states, lanes: ___lanes___)
# TODO: test the actual state table.

cli_state_table = Trailblazer::Workflow::State::Discovery.render_cli_state_table(state_table)
assert_equal cli_state_table, %(+-------------------+--------------------------------+-------------------------+------------------------------------+---------------------------------------------------------------+
| event name | triggered catch event | lifecycle | UI | approver |
+-------------------+--------------------------------+-------------------------+------------------------------------+---------------------------------------------------------------+
| "Create form" | UI / (?) --> [Create form] | Create | Create form | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Create" | UI / (?) --> [Create] | Create | Create | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Create" | UI / (?) --> [Create] | Create | Create | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Update form" | UI / (?) --> [Update form] | Update, Notify approver | Update form, Notify approver | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Notify approver" | UI / (?) --> [Notify approver] | Update, Notify approver | Update form, Notify approver | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Update" | UI / (?) --> [Update] | Update, Notify approver | Update | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Notify approver" | UI / (?) --> [Notify approver] | Update, Notify approver | Update form, Notify approver | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Delete? form" | UI / (?) --> [Delete? form] | Publish, Delete, Update | Update form, Delete? form, Publish | terminus, failure |
| "Publish" | UI / (?) --> [Publish] | Publish, Delete, Update | Update form, Delete? form, Publish | terminus, failure |
| "Update" | UI / (?) --> [Update] | Update, Notify approver | Update | #<Trailblazer::Workflow::Event::Throw semantic="xxx_approve"> |
| "Revise form" | UI / (?) --> [Revise form] | Revise | Revise form | terminus, success |
| "Delete" | UI / (?) --> [Delete] | Publish, Delete, Update | Delete, Cancel | terminus, failure |
| "Cancel" | UI / (?) --> [Cancel] | Publish, Delete, Update | Delete, Cancel | terminus, failure |
| "Archive" | UI / (?) --> [Archive] | Archive | Archive | terminus, failure |
| "Revise" | UI / (?) --> [Revise] | Revise | Revise | terminus, success |
+-------------------+--------------------------------+-------------------------+------------------------------------+---------------------------------------------------------------+
15 rows in set)



Expand Down

0 comments on commit 0a00e89

Please # to comment.