Skip to content

Commit

Permalink
we can now render the IDs of the positions, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jan 24, 2024
1 parent 0a00e89 commit 147f3ff
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
36 changes: 29 additions & 7 deletions lib/trailblazer/workflow/state/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def self.generate_state_table(discovery_states, lanes:)
state_table
end

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

lane_positions = row[:lane_positions].flat_map do |lane_position|
Expand All @@ -76,7 +76,8 @@ def self.render_cli_state_table(state_table)
]
end

Hash[
# The resulting hash represents one row.
state_row = Hash[
"event name",
row[:event_name].inspect,

Expand All @@ -85,15 +86,36 @@ def self.render_cli_state_table(state_table)

*lane_positions
]

rows = [
state_row,
]

# FIXME: use developer for coloring.
# def bg_gray(str); "\e[47m#{str}\e[0m" end

# TODO: optional feature, extract!
if render_ids
id_row = Hash[
"triggered catch event",
"\e[34m#{row[:start_position][:tuple][1]}\e[0m",
]

rows << id_row
end

rows
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"
"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
48 changes: 46 additions & 2 deletions test/collaboration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,13 @@ def render_states(states, lanes:, additional_state_data:, task_map:)


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

# currently, from this table we can read the discovery process, what states were discovered and what start lane positions those states imply.
# we still have redundant states here, as the discovery algorithm was instructed to invoke several events multiple times.
cli_state_table = Trailblazer::Workflow::State::Discovery.render_cli_state_table(state_table)
assert_equal cli_state_table, %(+-------------------+--------------------------------+-------------------------+------------------------------------+---------------------------------------------------------------+
# puts cli_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"> |
Expand All @@ -404,6 +407,47 @@ def render_states(states, lanes:, additional_state_data:, task_map:)
+-------------------+--------------------------------+-------------------------+------------------------------------+---------------------------------------------------------------+
15 rows in set)

cli_state_table_with_ids = Trailblazer::Workflow::State::Discovery.render_cli_state_table(state_table, render_ids: true)
puts cli_state_table_with_ids
# FIXME: we still have wrong formatting for ID rows with CLI coloring.
assert_equal cli_state_table_with_ids,
%(+-------------------+----------------------------------------+---------------------------------+--------------------------------------------+--------------------------------------------+
| event name | triggered catch event | lifecycle | UI | approver |
+-------------------+----------------------------------------+---------------------------------+--------------------------------------------+--------------------------------------------+
| \"Create form\" | UI / (?) --> [Create form] | [\"Create\"] | [\"Create form\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_0wc2mcq\e[0m | | | |
| \"Create\" | UI / (?) --> [Create] | [\"Create\"] | [\"Create\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_1psp91r\e[0m | | | |
| \"Create\" | UI / (?) --> [Create] | [\"Create\"] | [\"Create\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_1psp91r\e[0m | | | |
| \"Update form\" | UI / (?) --> [Update form] | [\"Update\", \"Notify approver\"] | [\"Update form\", \"Notify approver\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_1165bw9\e[0m | | | |
| \"Notify approver\" | UI / (?) --> [Notify approver] | [\"Update\", \"Notify approver\"] | [\"Update form\", \"Notify approver\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_1dt5di5\e[0m | | | |
| \"Update\" | UI / (?) --> [Update] | [\"Update\", \"Notify approver\"] | [\"Update\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_0j78uzd\e[0m | | | |
| \"Notify approver\" | UI / (?) --> [Notify approver] | [\"Update\", \"Notify approver\"] | [\"Update form\", \"Notify approver\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_1dt5di5\e[0m | | | |
| \"Delete? form\" | UI / (?) --> [Delete? form] | [\"Publish\", \"Delete\", \"Update\"] | [\"Update form\", \"Delete? form\", \"Publish\"] | [:terminus, :failure] |
| | \e[34mcatch-before-Activity_0ha7224\e[0m | | | |
| \"Publish\" | UI / (?) --> [Publish] | [\"Publish\", \"Delete\", \"Update\"] | [\"Update form\", \"Delete? form\", \"Publish\"] | [:terminus, :failure] |
| | \e[34mcatch-before-Activity_0bsjggk\e[0m | | | |
| \"Update\" | UI / (?) --> [Update] | [\"Update\", \"Notify approver\"] | [\"Update\"] | [#<Trailblazer::Workflow::Event::Throw ... |
| | \e[34mcatch-before-Activity_0j78uzd\e[0m | | | |
| \"Revise form\" | UI / (?) --> [Revise form] | [\"Revise\"] | [\"Revise form\"] | [:terminus, :success] |
| | \e[34mcatch-before-Activity_0zsock2\e[0m | | | |
| \"Delete\" | UI / (?) --> [Delete] | [\"Publish\", \"Delete\", \"Update\"] | [\"Delete\", \"Cancel\"] | [:terminus, :failure] |
| | \e[34mcatch-before-Activity_15nnysv\e[0m | | | |
| \"Cancel\" | UI / (?) --> [Cancel] | [\"Publish\", \"Delete\", \"Update\"] | [\"Delete\", \"Cancel\"] | [:terminus, :failure] |
| | \e[34mcatch-before-Activity_1uhozy1\e[0m | | | |
| \"Archive\" | UI / (?) --> [Archive] | [\"Archive\"] | [\"Archive\"] | [:terminus, :failure] |
| | \e[34mcatch-before-Activity_0fy41qq\e[0m | | | |
| \"Revise\" | UI / (?) --> [Revise] | [\"Revise\"] | [\"Revise\"] | [:terminus, :success] |
| | \e[34mcatch-before-Activity_1wiumzv\e[0m | | | |
+-------------------+----------------------------------------+---------------------------------+--------------------------------------------+--------------------------------------------+
30 rows in set)

raise "introduce 'suggested state name' column"


testing_json = Trailblazer::Workflow::State::Discovery::Testing.render_json(
Expand Down

0 comments on commit 147f3ff

Please sign in to comment.