Skip to content

Commit

Permalink
refactor: remove app_data param from generate_lock()
Browse files Browse the repository at this point in the history
insert data into FrameData instead
  • Loading branch information
mrjackwills committed Dec 3, 2024
1 parent 1b26997 commit 1a8dab6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app_data/container_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl ContainerPorts {
pub fn len_ip(&self) -> usize {
self.ip
.as_ref()
.map_or(0, |i|i.to_string().chars().count())
.map_or(0, |i| i.to_string().chars().count())
}
pub fn len_private(&self) -> usize {
format!("{}", self.private).chars().count()
Expand Down
2 changes: 1 addition & 1 deletion src/app_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl AppData {
}

/// Get title for containers section, add a suffix indicating if the containers are currently under filter
pub fn container_title(&self) -> String {
pub fn get_container_title(&self) -> String {
let suffix = if !self.hidden_containers.is_empty() && !self.containers.items.is_empty() {
" - filtered"
} else {
Expand Down
11 changes: 5 additions & 6 deletions src/ui/draw_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ fn max_line_width(text: &str) -> usize {
/// Generate block, add a border if is the selected panel,
/// add custom title based on state of each panel
fn generate_block<'a>(
app_data: &Arc<Mutex<AppData>>,
area: Rect,
fd: &FrameData,
gui_state: &Arc<Mutex<GuiState>>,
Expand All @@ -83,10 +82,10 @@ fn generate_block<'a>(
.update_region_map(Region::Panel(panel), area);
let mut title = match panel {
SelectablePanel::Containers => {
format!("{}{}", panel.title(), app_data.lock().container_title())
format!("{}{}", panel.title(), fd.container_title)
}
SelectablePanel::Logs => {
format!("{}{}", panel.title(), app_data.lock().get_log_title())
format!("{}{}", panel.title(), fd.log_title)
}
SelectablePanel::Commands => String::new(),
};
Expand All @@ -111,7 +110,7 @@ pub fn commands(
fd: &FrameData,
gui_state: &Arc<Mutex<GuiState>>,
) {
let block = generate_block(app_data, area, fd, gui_state, SelectablePanel::Commands);
let block = generate_block(area, fd, gui_state, SelectablePanel::Commands);
let items = app_data.lock().get_control_items().map_or(vec![], |i| {
i.iter()
.map(|c| {
Expand Down Expand Up @@ -220,7 +219,7 @@ pub fn containers(
fd: &FrameData,
gui_state: &Arc<Mutex<GuiState>>,
) {
let block = generate_block(app_data, area, fd, gui_state, SelectablePanel::Containers);
let block = generate_block(area, fd, gui_state, SelectablePanel::Containers);

let items = app_data
.lock()
Expand Down Expand Up @@ -259,7 +258,7 @@ pub fn logs(
fd: &FrameData,
gui_state: &Arc<Mutex<GuiState>>,
) {
let block = generate_block(app_data, area, fd, gui_state, SelectablePanel::Logs);
let block = generate_block(area, fd, gui_state, SelectablePanel::Logs);
if fd.init {
let paragraph = Paragraph::new(format!("parsing logs {}", fd.loading_icon))
.style(Style::default())
Expand Down
4 changes: 4 additions & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ impl Ui {
#[derive(Debug)]
pub struct FrameData {
columns: Columns,
container_title: String,
log_title: String,
delete_confirm: Option<ContainerId>,
has_containers: bool,
has_error: Option<AppError>,
Expand All @@ -248,6 +250,8 @@ impl From<(MutexGuard<'_, AppData>, MutexGuard<'_, GuiState>)> for FrameData {

Self {
columns: data.0.get_width(),
container_title: data.0.get_container_title(),
log_title: data.0.get_log_title(),
delete_confirm: data.1.get_delete_container(),
has_containers: data.0.get_container_len() > 0,
has_error: data.0.get_error(),
Expand Down

0 comments on commit 1a8dab6

Please sign in to comment.