From eb60e49ec881414e250308ec10b6ac31893663f5 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Wed, 7 Feb 2024 12:25:16 +0100 Subject: [PATCH] better formatting of start configurations. --- lib/trailblazer/workflow/state/discovery.rb | 4 +- .../workflow/state/discovery/testing.rb | 46 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/trailblazer/workflow/state/discovery.rb b/lib/trailblazer/workflow/state/discovery.rb index 09f8350..baddb96 100644 --- a/lib/trailblazer/workflow/state/discovery.rb +++ b/lib/trailblazer/workflow/state/discovery.rb @@ -126,12 +126,14 @@ def self.readable_name_for_catch_event(position, envelope_icon: false) "#{position[:tuple][0]}: #{envelope_icon}[#{position[:comment][1]}]" end - def self.readable_name_for_resume_event(position) + def self.readable_name_for_resume_event(position, tuple: false) resume_labels = position[:comment][1] catch_events = resume_labels.collect { |catch_label| "▶#{catch_label}" } .join(" ") + return [position[:tuple][0], catch_events] if tuple + "#{position[:tuple][0]}: [#{catch_events}]" end diff --git a/lib/trailblazer/workflow/state/discovery/testing.rb b/lib/trailblazer/workflow/state/discovery/testing.rb index 430990c..d18a7e0 100644 --- a/lib/trailblazer/workflow/state/discovery/testing.rb +++ b/lib/trailblazer/workflow/state/discovery/testing.rb @@ -56,10 +56,15 @@ def self.render_comment_header(structure) cli_rows = structure.collect do |testing_row| # row = :start_position, :start_configuration, :expected_lane_positions triggered_catch_event_label = Discovery.readable_name_for_catch_event(testing_row[:start_position]) + # TODO: remove start_configuration_cols = testing_row[:start_configuration].collect do |lane_position| - content = "#{Discovery.readable_name_for_resume_event(lane_position)}" + content = Discovery.readable_name_for_resume_event(lane_position) end.join(", ") + start_configuration = testing_row[:start_configuration].collect do |lane_position| + Discovery.readable_name_for_resume_event(lane_position, tuple: true) + end + expected_lane_positions = testing_row[:expected_lane_positions].collect do |lane_position| content = "#{readable_name_for_resume_event_or_terminus(lane_position)}" end.join(", ") @@ -71,24 +76,61 @@ def self.render_comment_header(structure) "input ctx", nil, + # TODO: remove "start configuration", start_configuration_cols, + :start_configuration, + start_configuration, + + "expected lane positions", expected_lane_positions ] end + cli_rows = format_start_positions_for(cli_rows, column_name: :start_configuration) + Hirb::Helpers::Table.render(cli_rows, fields: [ "triggered catch", - "start configuration", + :start_configuration_formatted, "expected lane positions", ], max_width: 186, ) # 186 for laptop 13" end + def self.format_start_positions_for(rows, column_name:) + # pp rows + + columns = {} + + rows.each do |row| + row[column_name].each do |lane_label, catch_label| + columns[lane_label] ||= [] + columns[lane_label] << catch_label.length + end + end + + columns_2_length = columns.collect { |lane_label, lengths| [lane_label, lengths.sort.last] }.to_h + + # TODO: always same col order!!! + rows = rows.collect do |row| + columns = row[column_name].collect do |lane_label, catch_label| + col_length = columns_2_length[lane_label] + + "#{lane_label}: " + catch_label.ljust(col_length, " ") + end + + content = columns.join(" | ") + + row = row.merge(:start_configuration_formatted => content) + end + + rows + end + # A lane position is always a {Suspend} (or a terminus). def self.serialize_lane_position(lane_position, lanes:) activity, suspend = lane_position.to_a