Variables export: the toast says how many warnings the export has and the first one, so a Uno or DTCG file with something left out says so

This commit is contained in:
bflatastic
2026-12-02 07:26:37 +07:00
parent 3e5612c170
commit 652ff16ec9
3 changed files with 29 additions and 3 deletions
+1
View File
@@ -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" }
+16 -3
View File
@@ -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| {
@@ -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);