mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-11 16:31:32 -06:00
LR-FILT-LABEL: group the plural labels in the chip when label and labels exclude each other
This commit is contained in:
@@ -332,7 +332,7 @@ fn filter_label_and_labels_together_chip() {
|
||||
// nothing passes both: the chip names both constraints
|
||||
s.execute("library.filter", &json!({"label": "red", "labels": ["yellow", "green"]})).unwrap();
|
||||
assert_eq!(s.visible_cloned().len(), 0);
|
||||
assert_eq!(chip(&s).label, "Label: Red and Yellow or Green");
|
||||
assert_eq!(chip(&s).label, "Label: Red and (Yellow or Green)");
|
||||
s.execute("library.filter", &chip(&s).clear).unwrap();
|
||||
assert_eq!((s.filter.label, s.filter.labels.len()), (None, 0));
|
||||
}
|
||||
|
||||
@@ -164,8 +164,13 @@ pub fn filter_chips(f: &Filter, cat: &Catalog) -> Vec<FilterChip> {
|
||||
if let Some(shown) = f.labels_shown() {
|
||||
let or = |ls: &[lightcraft_catalog::ColorLabel]| ls.iter().map(|l| cat.label_name(*l)).collect::<Vec<_>>().join(" or ");
|
||||
// empty: `label` and `labels` exclude each other, so name both constraints
|
||||
let names =
|
||||
if shown.is_empty() { format!("{} and {}", f.label.map(|l| cat.label_name(l)).unwrap_or_default(), or(&f.labels)) } else { or(&shown) };
|
||||
let names = if shown.is_empty() {
|
||||
// parenthesised when plural, so "Red and Yellow or Green" cannot read as "(Red and Yellow) or Green"
|
||||
let plural = if f.labels.len() > 1 { format!("({})", or(&f.labels)) } else { or(&f.labels) };
|
||||
format!("{} and {plural}", f.label.map(|l| cat.label_name(l)).unwrap_or_default())
|
||||
} else {
|
||||
or(&shown)
|
||||
};
|
||||
add(format!("Label: {names}"), json!({"label": Null, "labels": []}));
|
||||
}
|
||||
if let Some(k) = f.kind {
|
||||
|
||||
Reference in New Issue
Block a user