FIX: Scheduled PM with Data Explorer Results not sending PM (#250)

This PR fixes 2 issues that were picked up by users for the Scheduled Data Explorer Report automation script and a couple of small improvements to better match the format of manual data explorer query results.

The first issue is that within result_to_markdown the colrender contains null values, and we are currently checking length (previously treated as a packed array but it is actually a sparse array). Therefore we can check if the current index of the array is null rather than checking the size of the array.

The second issue addresses the blank query_params field. When the data explorer script does not require any params to be passed in via the automation script then it will have a nil value, however it should be defaulted to {} within the plugin.

To improve formatting the markdown table for PMs is now aligned to left and where values are substituted (for example user_id becomes username) we then include the id within brackets, for example:
user_id becomes username (user_id)
This commit is contained in:
David Battersby
2023-07-04 14:18:56 +08:00
committed by GitHub
parent 7bf6c7d3a3
commit ee308c637c
3 changed files with 38 additions and 4 deletions
+3 -3
View File
@@ -17,7 +17,7 @@ module ::DiscourseDataExplorer
row.each_with_index do |col, col_index|
col_name = pg_result.fields[col_index]
related = relations.dig(colrender[col_index].to_sym) if col_index < colrender.size
related = relations.dig(colrender[col_index].to_sym) unless colrender[col_index].nil?
if related.is_a?(ActiveModel::ArraySerializer)
related_row = related.object.find_by(id: col)
@@ -30,7 +30,7 @@ module ::DiscourseDataExplorer
if column.nil?
row_data[col_index] = col
else
row_data[col_index] = related_row[column]
row_data[col_index] = "#{related_row[column]} (#{col})"
end
else
row_data[col_index] = col
@@ -41,7 +41,7 @@ module ::DiscourseDataExplorer
end
table_headers = pg_result.fields.map { |c| " #{c.gsub("_id", "")} |" }.join
table_body = pg_result.fields.size.times.map { " :-----: |" }.join
table_body = pg_result.fields.size.times.map { " :----- |" }.join
"|#{table_headers}\n|#{table_body}\n#{result_data.join}"
end