#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct FacetedFilterIcon {
path: String,
}
impl FacetedFilterIcon {
pub fn from_path(path: impl Into<String>) -> Self {
Self { path: path.into() }
}
pub fn path(&self) -> &str {
&self.path
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FacetedFilterOption {
pub group: Option<String>,
pub label: String,
pub value: String,
pub count: Option<usize>,
pub icon: Option<FacetedFilterIcon>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FilterConfig {
pub column_index: usize,
pub filter_type: FilterType,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FilterType {
Faceted(Vec<FacetedFilterOption>),
DateRange,
NumberRange,
Text,
}
#[cfg(test)]
mod tests {
use super::{FacetedFilterIcon, FacetedFilterOption, FilterConfig, FilterType};
#[test]
fn faceted_filter_metadata_preserves_icons_and_option_details() {
let icon = FacetedFilterIcon::from_path("icons/check.svg");
assert_eq!(icon.path(), "icons/check.svg");
let option = FacetedFilterOption {
group: Some("State".into()),
label: "Active".into(),
value: "active".into(),
count: Some(3),
icon: Some(icon),
};
let config = FilterConfig {
column_index: 2,
filter_type: FilterType::Faceted(vec![option.clone()]),
};
assert_eq!(config.column_index, 2);
assert_eq!(config.filter_type, FilterType::Faceted(vec![option]));
assert_ne!(FilterType::DateRange, FilterType::NumberRange);
assert_ne!(FilterType::Text, FilterType::NumberRange);
}
}