diff --git a/lib/trailblazer/workflow/state/discovery.rb b/lib/trailblazer/workflow/state/discovery.rb index a98fe8e..f307513 100644 --- a/lib/trailblazer/workflow/state/discovery.rb +++ b/lib/trailblazer/workflow/state/discovery.rb @@ -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| @@ -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, @@ -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. diff --git a/test/collaboration_test.rb b/test/collaboration_test.rb index bf2479e..0151ce5 100644 --- a/test/collaboration_test.rb +++ b/test/collaboration_test.rb @@ -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 | # | @@ -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\"] | [# [Create] | [\"Create\"] | [\"Create\"] | [# [Create] | [\"Create\"] | [\"Create\"] | [# [Update form] | [\"Update\", \"Notify approver\"] | [\"Update form\", \"Notify approver\"] | [# [Notify approver] | [\"Update\", \"Notify approver\"] | [\"Update form\", \"Notify approver\"] | [# [Update] | [\"Update\", \"Notify approver\"] | [\"Update\"] | [# [Notify approver] | [\"Update\", \"Notify approver\"] | [\"Update form\", \"Notify approver\"] | [# [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\"] | [# [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(