fixed issues with the import
This commit is contained in:
@@ -302,11 +302,12 @@ pub(crate) async fn import_progress(
|
||||
|
||||
let response = match &snapshot.outcome {
|
||||
None => Html(ui::render_progress(locale, &id, &snapshot)).into_response(),
|
||||
Some(Outcome::Succeeded) => Html(ui::render_success(
|
||||
Some(Outcome::Succeeded { warnings }) => Html(ui::render_success(
|
||||
locale,
|
||||
snapshot.inserted,
|
||||
snapshot.total_rows,
|
||||
&snapshot.table_name,
|
||||
warnings,
|
||||
))
|
||||
.into_response(),
|
||||
Some(Outcome::RowFailed {
|
||||
@@ -445,8 +446,21 @@ async fn run_import(job: Running) {
|
||||
};
|
||||
match committed {
|
||||
Ok(response) => {
|
||||
let inserted = usize::try_from(response.into_inner().inserted_rows).unwrap_or(staged);
|
||||
jobs.finish(&job.id, inserted, Outcome::Succeeded);
|
||||
let response = response.into_inner();
|
||||
let inserted = usize::try_from(response.inserted_rows).unwrap_or(staged);
|
||||
let warnings = response
|
||||
.warnings
|
||||
.into_iter()
|
||||
.map(|warning| {
|
||||
format!(
|
||||
"CSV row {} ({}): {}",
|
||||
warning.row_index + 2,
|
||||
warning.table_name,
|
||||
warning.message,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
jobs.finish(&job.id, inserted, Outcome::Succeeded { warnings });
|
||||
}
|
||||
Err(error) => {
|
||||
abort_import(&job, &import_id).await;
|
||||
|
||||
@@ -34,7 +34,7 @@ const KEEP_FINISHED: Duration = Duration::from_secs(300);
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum Outcome {
|
||||
/// Every staged row was committed atomically.
|
||||
Succeeded,
|
||||
Succeeded { warnings: Vec<String> },
|
||||
/// The backend stopped on one row. No rows from the import were committed.
|
||||
RowFailed {
|
||||
status: StatusCode,
|
||||
@@ -255,7 +255,7 @@ mod tests {
|
||||
assert!(jobs.is_running("session"));
|
||||
assert!(!jobs.is_running("other"));
|
||||
|
||||
jobs.finish(&id, 10, Outcome::Succeeded);
|
||||
jobs.finish(&id, 10, Outcome::Succeeded { warnings: Vec::new() });
|
||||
assert!(!jobs.is_running("session"));
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ mod tests {
|
||||
inserted: 0,
|
||||
total_rows: 0,
|
||||
elapsed: Duration::from_secs(1),
|
||||
outcome: Some(Outcome::Succeeded),
|
||||
outcome: Some(Outcome::Succeeded { warnings: Vec::new() }),
|
||||
};
|
||||
|
||||
assert_eq!(snapshot.percent(), 100);
|
||||
|
||||
@@ -169,17 +169,27 @@ pub(crate) fn render_success(
|
||||
inserted: usize,
|
||||
prepared_rows: usize,
|
||||
table_name: &str,
|
||||
warnings: &[String],
|
||||
) -> String {
|
||||
let mut message = tr!(
|
||||
locale,
|
||||
"import-success-message",
|
||||
"inserted" => inserted as i64,
|
||||
"source_rows" => prepared_rows as i64,
|
||||
"table" => table_name.to_string(),
|
||||
);
|
||||
if !warnings.is_empty() {
|
||||
message.push(' ');
|
||||
message.push_str(&tr!(
|
||||
locale,
|
||||
"import-success-warnings",
|
||||
"warnings" => warnings.join("; "),
|
||||
));
|
||||
}
|
||||
render(&ImportSuccessDialog {
|
||||
locale,
|
||||
title: &tr!(locale, "import-success-title"),
|
||||
message: &tr!(
|
||||
locale,
|
||||
"import-success-message",
|
||||
"inserted" => inserted as i64,
|
||||
"source_rows" => prepared_rows as i64,
|
||||
"table" => table_name.to_string(),
|
||||
),
|
||||
message: &message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -485,7 +495,7 @@ mod tests {
|
||||
/// dialog the user has to actively dismiss, not a toast on its own timer.
|
||||
#[test]
|
||||
fn a_finished_import_answers_with_a_dismissible_dialog_not_a_toast() {
|
||||
let html = render_success(Locale::English, 500, 500, "customers");
|
||||
let html = render_success(Locale::English, 500, 500, "customers", &[]);
|
||||
|
||||
assert!(!html.contains("Template error"), "{html}");
|
||||
assert!(html.contains(r#"role="dialog""#), "{html}");
|
||||
@@ -497,4 +507,19 @@ mod tests {
|
||||
assert!(!html.contains("$dispatch('notify'"), "{html}");
|
||||
assert!(html.contains("keydown.esc"), "{html}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_finished_import_displays_non_blocking_warnings() {
|
||||
let html = render_success(
|
||||
Locale::English,
|
||||
1,
|
||||
1,
|
||||
"customers",
|
||||
&["CSV row 2 (customers): Deleted row omitted required column 'name'".to_string()],
|
||||
);
|
||||
|
||||
assert!(html.contains("Warnings:"), "{html}");
|
||||
assert!(html.contains("CSV row 2"), "{html}");
|
||||
assert!(html.contains("Deleted row omitted required column"), "{html}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user