From b32f163cdc8f39ec5b06c176f23bedc0bd665852 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 19 Sep 2023 14:25:40 +0200 Subject: [PATCH] Fix rendering of tables with broken metadata in docx reports [SCI-9327] --- app/services/reports/docx/draw_result_table.rb | 8 ++++---- app/services/reports/docx/draw_step_table.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/services/reports/docx/draw_result_table.rb b/app/services/reports/docx/draw_result_table.rb index e9850673d..11100b0c0 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -9,8 +9,8 @@ module Reports::Docx::DrawResultTable table_data = JSON.parse(table.contents_utf_8)['data'] table_data = obj.add_headers_to_table(table_data, false) - if table.metadata.present? - table.metadata['cells']&.each do |cell| + if table.metadata.present? && table.metadata['cells'].is_a?(Array) + table.metadata['cells'].each do |cell| next unless cell['row'].present? && cell['col'].present? row_index = cell['row'].to_i + 1 @@ -27,8 +27,8 @@ module Reports::Docx::DrawResultTable cell_style rows[0], bold: true, background: color[:concrete] cell_style cols[0], bold: true, background: color[:concrete] - if table.metadata.present? - table.metadata['cells']&.each do |cell| + if table.metadata.present? && table.metadata['cells'].is_a?(Array) + table.metadata['cells'].each do |cell| next unless cell.present? && cell['row'].present? && cell['col'].present? && cell['className'].present? cell_style rows.dig(cell['row'].to_i + 1, cell['col'].to_i + 1), diff --git a/app/services/reports/docx/draw_step_table.rb b/app/services/reports/docx/draw_step_table.rb index 96f1be45e..a0826741a 100644 --- a/app/services/reports/docx/draw_step_table.rb +++ b/app/services/reports/docx/draw_step_table.rb @@ -8,8 +8,8 @@ module Reports::Docx::DrawStepTable table_data = JSON.parse(table.contents_utf_8)['data'] table_data = obj.add_headers_to_table(table_data, table_type == 'step_well_plates_table') - if table.metadata.present? - table.metadata['cells']&.each do |cell| + if table.metadata.present? && table.metadata['cells'].is_a?(Array) + table.metadata['cells'].each do |cell| next unless cell['row'].present? && cell['col'].present? row_index = cell['row'].to_i + 1 @@ -26,8 +26,8 @@ module Reports::Docx::DrawStepTable cell_style rows[0], bold: true, background: color[:concrete] cell_style cols[0], bold: true, background: color[:concrete] - if table.metadata.present? - table.metadata['cells']&.each do |cell| + if table.metadata.present? && table.metadata['cells'].is_a?(Array) + table.metadata['cells'].each do |cell| data = cell[1] next unless data.present? && data['row'].present? && data['col'].present? && data['className'].present?