gitlab_tracker_core/columns.rs
1/// A single optional column in the MR table.
2///
3/// Plugins register their columns via `inventory::submit!(ColumnDef { … })` — no
4/// change to `config.rs`, `mod.rs` or `storage.rs` is needed when a new column
5/// is added by a plugin crate.
6///
7/// # Display order
8/// Columns are sorted by `priority` (ascending) when `collect_all_columns` is called.
9/// Convention:
10/// - `0–99` → built-in columns (Activity, Target, Labels, Milestone, Notes, Diff)
11/// - `100–199` → first-party tracker plugin columns (Redmine Ticket, Jira Issue, …)
12/// - `200+` → community / third-party plugin columns
13pub struct ColumnDef {
14 /// Unique machine-readable identifier (e.g. `"activity"`, `"tracker_ticket"`).
15 /// Used as the persistence key in `projects.toml` — must be stable across versions.
16 pub id: &'static str,
17
18 /// Human-readable label shown in the column picker popup (e.g. `"Activity"`).
19 pub label: &'static str,
20
21 /// Whether this column is visible by default on a fresh install.
22 pub default_visible: bool,
23
24 /// Display order — lower values appear first in the column picker.
25 pub priority: u16,
26
27 /// When `Some`, the column is only shown when the runtime condition is met
28 /// (e.g. a tracker provider is configured). The closure receives a single `bool`
29 /// context value whose meaning is defined per-column in the orchestrator.
30 ///
31 /// `None` means the column is always available regardless of runtime state.
32 pub requires_feature: Option<&'static str>,
33}
34
35// Global registry — every `inventory::submit!(ColumnDef { … })` anywhere in the
36// dependency graph is collected here at startup.
37inventory::collect!(ColumnDef);
38
39/// Collects all registered [`ColumnDef`]s from every linked crate,
40/// sorted by `priority` (ascending).
41///
42/// Call this once at startup to build the ordered column list.
43pub fn collect_all_columns() -> Vec<&'static ColumnDef> {
44 let mut cols: Vec<&'static ColumnDef> = inventory::iter::<ColumnDef>.into_iter().collect();
45 cols.sort_by_key(|c| c.priority);
46 cols
47}