diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index efe9804cf..225bbade3 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -790,6 +790,7 @@ name = "English" "Export {name}" = "Export {name}" "Export {n} layers" = { one = "Export {n} layer", other = "Export {n} layers" } "Exported {file}" = "Exported {file}" +"Exported {file} with {n} warnings, first: {warning}" = { one = "Exported {file} with {n} warning: {warning}", other = "Exported {file} with {n} warnings, first: {warning}" } "Exported {name}" = "Exported {name}" "Exported {name}; {n} kinds of content were changed or left out" = { one = "Exported {name}; {n} kind of content was changed or left out", other = "Exported {name}; {n} kinds of content were changed or left out" } "Exported {name}; {n} kinds of content were left out" = { one = "Exported {name}; {n} kind of content was left out", other = "Exported {name}; {n} kinds of content were left out" } diff --git a/crates/ui-egui/src/dialogs/variables_panel.rs b/crates/ui-egui/src/dialogs/variables_panel.rs index 23eed8a3a..38d0b8824 100644 --- a/crates/ui-egui/src/dialogs/variables_panel.rs +++ b/crates/ui-egui/src/dialogs/variables_panel.rs @@ -364,7 +364,7 @@ pub(crate) fn export_dialog(app: &mut FigApp, format: &str) { let Some(r) = app.run("variable.export", json!({"format": format})) else { return }; let text = r["text"].as_str().unwrap_or_default(); if app.services.download(&name, text.as_bytes()) { - app.toast(trf("Exported {file}", &[("file", &name)])); + exported(app, &name, &r); } else { app.toast(tr("Couldn't download the variables")); } @@ -373,13 +373,26 @@ pub(crate) fn export_dialog(app: &mut FigApp, format: &str) { let format = format.to_owned(); let ext = ext.to_owned(); app.pick_save(tr("Export variables"), &name, &[&ext], move |app, p| { - if app.run("variable.export", json!({"format": format, "path": p.to_string_lossy()})).is_some() { + if let Some(r) = app.run("variable.export", json!({"format": format, "path": p.to_string_lossy()})) { let file = p.file_name().map(|f| f.to_string_lossy().to_string()).unwrap_or_default(); - app.toast(trf("Exported {file}", &[("file", &file)])); + exported(app, &file, &r); } }); } +/// Say the export is done and, when the engine left something out, how much and the first thing. +fn exported(app: &mut FigApp, file: &str, r: &Value) { + let warnings = r["warnings"].as_array().map(Vec::as_slice).unwrap_or_default(); + app.toast(match warnings.first() { + None => trf("Exported {file}", &[("file", &file)]), + Some(first) => trn( + "Exported {file} with {n} warnings, first: {warning}", + warnings.len(), + &[("file", &file), ("warning", &first.as_str().unwrap_or_default())], + ), + }); +} + /// Import a variables JSON picked in an open dialog. fn import_dialog(app: &mut FigApp) { app.pick_open(tr("Import variables"), &["json"], |app, p| { diff --git a/crates/ui-egui/src/variables_export_ui_tests.rs b/crates/ui-egui/src/variables_export_ui_tests.rs index ce51a096d..c3996f2f7 100644 --- a/crates/ui-egui/src/variables_export_ui_tests.rs +++ b/crates/ui-egui/src/variables_export_ui_tests.rs @@ -76,6 +76,18 @@ fn css_export_downloads_custom_properties() { assert!(css.contains(":root") && css.contains("--"), "{css}"); } +#[test] +fn an_export_that_leaves_something_out_says_what() { + let (mut app, got) = browser(true); + app.session.execute("variable.createCollection", &json!({"name": "Brand", "modes": ["Light", "Dark", "Contrast"]})).unwrap(); + export_dialog(&mut app, "uno"); + let got = got.lock().unwrap(); + let [(name, _)] = got.as_slice() else { panic!("one download, got {}", got.len()) }; + assert!(name.ends_with(".variables.cs"), "{name}"); + let said = toast(&app); + assert!(said.contains(name.as_str()) && said.contains("Contrast"), "{said}"); +} + #[test] fn a_refused_download_says_so() { let (mut app, got) = browser(false);