Skip to main content

vantage_table/column/
flags.rs

1/// Column flags that define behavior and properties of columns.
2#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3pub enum ColumnFlag {
4    /// Mandatory will require read/write operations to always have value for this field, it cannot be missing
5    Mandatory,
6    /// Hidden columns are excluded from UI display. Display only: it says
7    /// nothing about whether rows carry the column.
8    Hidden,
9    /// IdField marks this column as the primary identifier for the table
10    IdField,
11    /// TitleField marks this column as the display title/name for records
12    TitleField,
13    /// Searchable marks this column as searchable in text searches
14    Searchable,
15    /// Indexed marks this column as cheap to sort or filter on, hinting to generic UIs that they can offer sort headers and filter inputs without a performance penalty
16    Indexed,
17    /// Label hints to generic UIs that this column is better shown as a
18    /// small status tag attached to the record's title than as its own
19    /// column (e.g. a status / state field with a per-value color map)
20    Label,
21    /// The column is a request parameter: its value is sent to the backend
22    /// (a URL placeholder, an API argument), and returned rows needn't carry
23    /// it. [`Table::row_fields`](crate::table::Table::row_fields) leaves it
24    /// out.
25    RequestParam,
26}
27
28impl ColumnFlag {
29    /// The Vista flag this flag becomes in a table's Vista metadata. Hints
30    /// for generic UIs (`Indexed`, `Label`) stay [`Other`] flags: they grant
31    /// no capability, so `Indexed` is not `Orderable`.
32    ///
33    /// [`Other`]: vantage_vista::ColumnFlag::Other
34    pub fn to_vista(&self) -> vantage_vista::ColumnFlag {
35        use vantage_vista::ColumnFlag as Vista;
36        match self {
37            ColumnFlag::Mandatory => Vista::Mandatory,
38            ColumnFlag::Hidden => Vista::Hidden,
39            ColumnFlag::IdField => Vista::Id,
40            ColumnFlag::TitleField => Vista::Title,
41            ColumnFlag::Searchable => Vista::Searchable,
42            ColumnFlag::Indexed => Vista::Other("indexed".into()),
43            ColumnFlag::Label => Vista::Other("label".into()),
44            ColumnFlag::RequestParam => Vista::RequestParam,
45        }
46    }
47}