Skip to content

Commit

Permalink
better formatting of start configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Feb 7, 2024
1 parent f6109be commit eb60e49
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/trailblazer/workflow/state/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 44 additions & 2 deletions lib/trailblazer/workflow/state/discovery/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")
Expand All @@ -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
Expand Down

0 comments on commit eb60e49

Please sign in to comment.