use std::path::PathBuf;
use crate::db::differ::DatabaseDiff;
use crate::db::types::{DatabaseSummary, Snapshot, TablePage, TableQuery};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum WorkspaceView {
Table,
Diff,
SchemaDiff,
Snapshots,
SqlExport,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DiffDisplayMode {
Grid,
Unified,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProgressState {
pub label: String,
pub completed_steps: usize,
pub total_steps: Option<usize>,
}
impl ProgressState {
pub fn new(
label: impl Into<String>,
completed_steps: usize,
total_steps: Option<usize>,
) -> Self {
Self {
label: label.into(),
completed_steps,
total_steps,
}
}
pub fn fraction(&self) -> Option<f32> {
self.total_steps.map(|total| {
if total == 0 {
0.0
} else {
(self.completed_steps.min(total) as f32) / (total as f32)
}
})
}
pub fn step_label(&self) -> Option<String> {
self.total_steps.map(|total| {
format!(
"Step {} of {}",
(self.completed_steps + 1).min(total),
total
)
})
}
}
#[derive(Clone, Debug, Default)]
pub struct DatabasePaneState {
pub path: Option<PathBuf>,
pub is_loading: bool,
pub summary: Option<DatabaseSummary>,
pub selected_table: Option<String>,
pub is_loading_table: bool,
pub progress: Option<ProgressState>,
pub table_page: Option<TablePage>,
pub table_query: TableQuery,
pub snapshots: Vec<Snapshot>,
pub error: Option<String>,
}
#[derive(Clone, Debug)]
pub struct DiffState {
pub result: Option<DatabaseDiff>,
pub is_computing: bool,
pub progress: Option<ProgressState>,
pub selected_table: Option<String>,
pub display_mode: DiffDisplayMode,
pub error: Option<String>,
}
impl Default for DiffState {
fn default() -> Self {
Self {
result: None,
is_computing: false,
progress: None,
selected_table: None,
display_mode: DiffDisplayMode::Grid,
error: None,
}
}
}
#[derive(Debug)]
pub struct WorkspaceState {
pub left: DatabasePaneState,
pub right: DatabasePaneState,
pub active_view: WorkspaceView,
pub diff: DiffState,
pub snapshot_name: String,
pub status_message: Option<String>,
}
impl Default for WorkspaceState {
fn default() -> Self {
Self {
left: DatabasePaneState::default(),
right: DatabasePaneState::default(),
active_view: WorkspaceView::Table,
diff: DiffState::default(),
snapshot_name: "Snapshot".to_owned(),
status_message: None,
}
}
}