refactor: remove app_data param from generate_lock()
insert data into FrameData instead
This commit is contained in:
@@ -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()
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
@@ -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>>,
|
||||
@@ -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(),
|
||||
};
|
||||
@@ -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| {
|
||||
@@ -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()
|
||||
@@ -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())
|
||||
|
||||
@@ -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>,
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user