Skip to main content

opal/ui/
types.rs

1use crate::history::{HistoryCache, HistoryEntry, HistoryJob, HistoryStatus};
2use std::path::PathBuf;
3
4pub const LOG_SCROLL_STEP: usize = 3;
5pub const LOG_SCROLL_HALF: usize = 20;
6pub const LOG_SCROLL_PAGE: usize = 60;
7pub const CURRENT_HISTORY_KEY: &str = "__current_run__";
8
9#[derive(Clone, Copy, PartialEq, Eq)]
10pub enum PaneFocus {
11    History,
12    Jobs,
13}
14
15#[derive(Clone)]
16pub enum HistoryAction {
17    SelectJob(usize),
18    ViewLog { title: String, path: PathBuf },
19    ViewRun(String),
20    ViewHistoryJob { run_id: String, job_name: String },
21    ViewDir { title: String, path: PathBuf },
22    ViewFile { title: String, path: PathBuf },
23}
24
25#[derive(Clone)]
26pub struct UiJobInfo {
27    pub name: String,
28    pub stage: String,
29    pub log_path: PathBuf,
30    pub log_hash: String,
31}
32
33#[derive(Clone, Default)]
34pub struct UiJobResources {
35    pub artifact_dir: Option<String>,
36    pub artifact_paths: Vec<String>,
37    pub caches: Vec<HistoryCache>,
38    pub container_name: Option<String>,
39    pub service_network: Option<String>,
40    pub service_containers: Vec<String>,
41    pub runtime_summary_path: Option<String>,
42}
43
44impl From<&HistoryJob> for UiJobResources {
45    fn from(job: &HistoryJob) -> Self {
46        Self {
47            artifact_dir: job.artifact_dir.clone(),
48            artifact_paths: job.artifacts.clone(),
49            caches: job.caches.clone(),
50            container_name: job.container_name.clone(),
51            service_network: job.service_network.clone(),
52            service_containers: job.service_containers.clone(),
53            runtime_summary_path: job.runtime_summary_path.clone(),
54        }
55    }
56}
57
58#[derive(Clone)]
59pub enum UiCommand {
60    RestartJob { name: String },
61    StartManual { name: String },
62    CancelJob { name: String },
63    AbortPipeline,
64}
65
66#[derive(Clone)]
67pub enum UiEvent {
68    JobStarted {
69        name: String,
70    },
71    JobRestarted {
72        name: String,
73    },
74    JobLog {
75        name: String,
76        line: String,
77    },
78    JobFinished {
79        name: String,
80        status: UiJobStatus,
81        duration: f32,
82        error: Option<String>,
83    },
84    JobManual {
85        name: String,
86    },
87    HistoryUpdated {
88        entry: HistoryEntry,
89    },
90    PipelineFinished,
91}
92
93#[derive(Clone, Copy, PartialEq, Eq)]
94pub enum UiJobStatus {
95    Pending,
96    Running,
97    Success,
98    Failed,
99    Skipped,
100}
101
102impl UiJobStatus {
103    pub fn is_finished(self) -> bool {
104        matches!(
105            self,
106            UiJobStatus::Success | UiJobStatus::Failed | UiJobStatus::Skipped
107        )
108    }
109
110    pub fn is_restartable(self) -> bool {
111        matches!(self, UiJobStatus::Success | UiJobStatus::Failed)
112    }
113
114    pub fn label(self) -> &'static str {
115        match self {
116            UiJobStatus::Pending => "pending",
117            UiJobStatus::Running => "running",
118            UiJobStatus::Success => "success",
119            UiJobStatus::Failed => "failed",
120            UiJobStatus::Skipped => "skipped",
121        }
122    }
123
124    pub fn from_history(status: HistoryStatus) -> Self {
125        match status {
126            HistoryStatus::Success => UiJobStatus::Success,
127            HistoryStatus::Failed => UiJobStatus::Failed,
128            HistoryStatus::Skipped => UiJobStatus::Skipped,
129            HistoryStatus::Running => UiJobStatus::Running,
130        }
131    }
132}