Page MenuHomePhabricator

D8985.diff
No OneTemporary

D8985.diff

diff --git a/services/reports/src/config.rs b/services/reports/src/config.rs
--- a/services/reports/src/config.rs
+++ b/services/reports/src/config.rs
@@ -9,6 +9,16 @@
// environment variable names
const ENV_LOCALSTACK_ENDPOINT: &str = "LOCALSTACK_ENDPOINT";
const ENV_BLOB_SERVICE_URL: &str = "BLOB_SERVICE_URL";
+const ENV_PUBLIC_URL: &str = "PUBLIC_URL";
+
+/// Base URL on which Reports service is accessible.
+/// Used for sending e-mail links.
+pub static SERVICE_PUBLIC_URL: Lazy<String> = Lazy::new(|| {
+ std::env::var(ENV_PUBLIC_URL)
+ .ok()
+ .filter(|s| !s.is_empty())
+ .unwrap_or_else(|| "http://localhost:50056".to_string())
+});
#[derive(Parser)]
#[command(version, about, long_about = None)]
diff --git a/services/reports/src/email/template/mod.rs b/services/reports/src/email/template/mod.rs
--- a/services/reports/src/email/template/mod.rs
+++ b/services/reports/src/email/template/mod.rs
@@ -1,9 +1,12 @@
use maud::{html, Markup, Render};
+use tracing::error;
-use crate::report_types::*;
+use crate::{config::SERVICE_PUBLIC_URL, report_types::*};
mod html_layout;
+const MAX_JSON_LINES: usize = 100;
+
pub fn render_email_for_report(
report_input: &ReportInput,
report_id: &ReportID,
@@ -62,6 +65,8 @@
li { "Time: " b { (time) } }
li { "Report ID: " b { (report_id) } }
}
+ (further_actions(report_id, report.report_type.is_error()))
+ (display_contents(report, report_id))
}
}
@@ -102,6 +107,52 @@
.unwrap_or("completed")
}
+fn further_actions(
+ report_id: &ReportID,
+ display_download_link: bool,
+) -> Markup {
+ html! {
+ h3 { "Further actions" }
+ ul {
+ li { a href=(report_link(report_id)) { "Open raw report JSON" } }
+ @if display_download_link {
+ li { a href={ (report_link(report_id)) "/redux-devtools.json" } { "Redux Devtools import" } }
+ }
+ }
+ }
+}
+
+fn display_contents(report: &ReportInput, report_id: &ReportID) -> Markup {
+ let pretty = match serde_json::to_string_pretty(&report.report_content) {
+ Ok(string) => string,
+ Err(err) => {
+ error!("Failed to render report JSON: {err}");
+ return html! { pre { "ERROR: Failed to render JSON" } };
+ }
+ };
+
+ let content: String = pretty
+ .split('\n')
+ .take(MAX_JSON_LINES)
+ .collect::<Vec<&str>>()
+ .join("\n");
+
+ html! {
+ h3 { "Report contents" }
+ em {
+ "The content is truncated to " (MAX_JSON_LINES) " lines. To view more, "
+ a href=(report_link(report_id)) { "open full report" }
+ "."
+ }
+ pre { (content) }
+ }
+}
+
+fn report_link(id: &ReportID) -> String {
+ let base_url = SERVICE_PUBLIC_URL.as_str();
+ format!("{base_url}/reports/{}", id.as_str())
+}
+
impl Render for PlatformDetails {
fn render(&self) -> Markup {
let code_version = self

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 3:55 AM (17 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2568008
Default Alt Text
D8985.diff (2 KB)

Event Timeline