canvas common needs redesign, sidebar displaying even when no profile selected

This commit is contained in:
filipriec
2025-03-24 16:46:02 +01:00
parent 36dc4302a0
commit 65ff1256aa
2 changed files with 35 additions and 76 deletions

View File

@@ -9,7 +9,8 @@ use crate::config::colors::themes::Theme;
use common::proto::multieko2::table_definition::{ProfileTreeResponse};
use ratatui::text::{Span, Line};
const SIDEBAR_WIDTH: u16 = 16;
// Reduced sidebar width
const SIDEBAR_WIDTH: u16 = 12;
pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) -> (Option<Rect>, Rect) {
if show_sidebar {
@@ -39,34 +40,43 @@ pub fn render_sidebar(
if let Some(profile_name) = selected_profile {
// Existing code for when a profile is selected...
} else {
// Show full profile tree when no profile is selected
// Show full profile tree when no profile is selected (compact version)
for (profile_idx, profile) in profile_tree.profiles.iter().enumerate() {
// Profile header
// Profile header - more compact
items.push(ListItem::new(Line::from(vec![
Span::styled("📁 ", Style::default().fg(theme.accent)),
Span::styled("", Style::default().fg(theme.accent)),
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
])));
// Tables
// Tables with compact prefixes
for (table_idx, table) in profile.tables.iter().enumerate() {
let is_last_table = table_idx == profile.tables.len() - 1;
let is_last_profile = profile_idx == profile_tree.profiles.len() - 1;
// Shorter prefix characters
let prefix = match (is_last_profile, is_last_table) {
(true, true) => " └─ ",
(true, false) => " ├─ ",
(false, true) => " └─ ",
(false, false) => " ├─ ",
(true, true) => " ",
(true, false) => " ",
(false, true) => "",
(false, false) => "",
};
// Get table name without year prefix to save space
let display_name = if table.name.starts_with("2025_") {
&table.name[5..] // Skip "2025_" prefix
} else {
&table.name
};
let mut line = vec![
Span::styled(prefix, Style::default().fg(theme.fg)),
Span::styled(&table.name, Style::default().fg(theme.fg)),
Span::styled(display_name, Style::default().fg(theme.fg)),
];
// Show a simple indicator for dependencies instead of listing them
if !table.depends_on.is_empty() {
line.push(Span::styled(
format!("{}", table.depends_on.join(", ")),
"",
Style::default().fg(theme.secondary)
));
}
@@ -74,7 +84,7 @@ pub fn render_sidebar(
items.push(ListItem::new(Line::from(line)));
}
// Add spacing between profiles
// Compact separator between profiles
if profile_idx < profile_tree.profiles.len() - 1 {
items.push(ListItem::new(Line::from(
Span::styled("", Style::default().fg(theme.secondary))
@@ -84,7 +94,7 @@ pub fn render_sidebar(
if profile_tree.profiles.is_empty() {
items.push(ListItem::new(Span::styled(
"No profiles available",
"No profiles",
Style::default().fg(theme.secondary)
)));
}
@@ -93,7 +103,7 @@ pub fn render_sidebar(
let list = List::new(items)
.block(sidebar_block)
.highlight_style(Style::default().fg(theme.highlight))
.highlight_symbol(">>");
.highlight_symbol(">");
f.render_widget(list, area);
}

View File

@@ -32,12 +32,19 @@ pub async fn handle_core_action(
Ok((false, message))
},
"force_quit" => {
let (should_exit, message) = command_handler.handle_command("force_quit", terminal).await?;
Ok((should_exit, message))
terminal.cleanup()?;
Ok((true, "Force exiting without saving.".to_string()))
},
"save_and_quit" => {
let (should_exit, message) = command_handler.handle_command("save_and_quit", terminal).await?;
Ok((should_exit, message))
let message = save(
form_state,
grpc_client,
&mut app_state.ui.is_saved,
current_position,
total_count,
).await?;
terminal.cleanup()?;
Ok((true, format!("{}. Exiting application.", message)))
},
"revert" => {
let message = revert(
@@ -132,64 +139,6 @@ pub async fn save(
Ok(message)
}
/// Shared logic for force quitting the application
pub fn force_quit() -> (bool, String) {
(true, "Force quitting application".to_string())
}
/// Shared logic for saving and quitting
pub async fn save_and_quit(
form_state: &mut FormState,
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
let is_new = *current_position == total_count + 1;
if is_new {
let post_request = PostAdresarRequest {
firma: form_state.values[0].clone(),
kz: form_state.values[1].clone(),
drc: form_state.values[2].clone(),
ulica: form_state.values[3].clone(),
psc: form_state.values[4].clone(),
mesto: form_state.values[5].clone(),
stat: form_state.values[6].clone(),
banka: form_state.values[7].clone(),
ucet: form_state.values[8].clone(),
skladm: form_state.values[9].clone(),
ico: form_state.values[10].clone(),
kontakt: form_state.values[11].clone(),
telefon: form_state.values[12].clone(),
skladu: form_state.values[13].clone(),
fax: form_state.values[14].clone(),
};
let _ = grpc_client.post_adresar(post_request).await?;
} else {
let put_request = PutAdresarRequest {
id: form_state.id,
firma: form_state.values[0].clone(),
kz: form_state.values[1].clone(),
drc: form_state.values[2].clone(),
ulica: form_state.values[3].clone(),
psc: form_state.values[4].clone(),
mesto: form_state.values[5].clone(),
stat: form_state.values[6].clone(),
banka: form_state.values[7].clone(),
ucet: form_state.values[8].clone(),
skladm: form_state.values[9].clone(),
ico: form_state.values[10].clone(),
kontakt: form_state.values[11].clone(),
telefon: form_state.values[12].clone(),
skladu: form_state.values[13].clone(),
fax: form_state.values[14].clone(),
};
let _ = grpc_client.put_adresar(put_request).await?;
}
Ok((true, "Saved and exiting application".to_string()))
}
/// Discard changes since last save
pub async fn revert(
form_state: &mut FormState,