feat(anatomy): an unnamed trigger carries the opened view's name per language

This commit is contained in:
bchanot committed 2026-10-15 01:00:44 +02:00
1 parent d8e9bd391a
commit 6882c6da4a
5 files changed
+168 -29

No files matched your search

+42
View File
@@ -35,3 +35,45 @@ pub fn tree_value(element: &Element) -> Value {
pub fn reread(element: &Element) -> Value {
tree_value(&parse_svg(&serialize(element)).unwrap())
}
/// Owner decision 2026-10-15 (R3): a trigger without a name of its own carries the opened
/// view's name in each language (the TypeScript freeze carries the French name twice). The
/// frozen trees stay as frozen; this declared change is applied to them before comparing:
/// `data-anno-name-en` takes the view's English name and the title reads "FR / EN".
pub fn with_trigger_names_per_language(tree: &mut Value, views: &[(String, String, String)]) {
if let Some(attrs) = tree.get_mut("attrs").and_then(Value::as_object_mut) {
let opened = attrs
.get("data-anno-opens-view")
.and_then(Value::as_str)
.map(str::to_owned);
let view = opened.and_then(|id| views.iter().find(|(v, _, _)| *v == id));
if let Some((_, fr, en)) = view
&& attrs.get("data-anno-name-en").and_then(Value::as_str) == Some(fr.as_str())
{
attrs.insert("data-anno-name-en".to_owned(), Value::String(en.clone()));
}
}
if let Some(text) = tree.get_mut("text") {
for (_, fr, en) in views {
if text.as_str() == Some(format!("{fr} / {fr}").as_str()) {
*text = Value::String(format!("{fr} / {en}"));
}
}
}
if let Some(children) = tree.get_mut("children").and_then(Value::as_array_mut) {
for child in children {
with_trigger_names_per_language(child, views);
}
}
}
/// (view id, FR name, EN name) of a document, for `with_trigger_names_per_language`.
pub fn view_names(
document: &faunosteo_core::domain::sheet::AnatomicalSheetDocument,
) -> Vec<(String, String, String)> {
document
.views
.iter()
.map(|v| (v.id().to_owned(), v.name().fr.clone(), v.name().en.clone()))
.collect()
}