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 {
|
pub fn len_ip(&self) -> usize {
|
||||||
self.ip
|
self.ip
|
||||||
.as_ref()
|
.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 {
|
pub fn len_private(&self) -> usize {
|
||||||
format!("{}", self.private).chars().count()
|
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
|
/// 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() {
|
let suffix = if !self.hidden_containers.is_empty() && !self.containers.items.is_empty() {
|
||||||
" - filtered"
|
" - filtered"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ fn max_line_width(text: &str) -> usize {
|
|||||||
/// Generate block, add a border if is the selected panel,
|
/// Generate block, add a border if is the selected panel,
|
||||||
/// add custom title based on state of each panel
|
/// add custom title based on state of each panel
|
||||||
fn generate_block<'a>(
|
fn generate_block<'a>(
|
||||||
app_data: &Arc<Mutex<AppData>>,
|
|
||||||
area: Rect,
|
area: Rect,
|
||||||
fd: &FrameData,
|
fd: &FrameData,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
@@ -83,10 +82,10 @@ fn generate_block<'a>(
|
|||||||
.update_region_map(Region::Panel(panel), area);
|
.update_region_map(Region::Panel(panel), area);
|
||||||
let mut title = match panel {
|
let mut title = match panel {
|
||||||
SelectablePanel::Containers => {
|
SelectablePanel::Containers => {
|
||||||
format!("{}{}", panel.title(), app_data.lock().container_title())
|
format!("{}{}", panel.title(), fd.container_title)
|
||||||
}
|
}
|
||||||
SelectablePanel::Logs => {
|
SelectablePanel::Logs => {
|
||||||
format!("{}{}", panel.title(), app_data.lock().get_log_title())
|
format!("{}{}", panel.title(), fd.log_title)
|
||||||
}
|
}
|
||||||
SelectablePanel::Commands => String::new(),
|
SelectablePanel::Commands => String::new(),
|
||||||
};
|
};
|
||||||
@@ -111,7 +110,7 @@ pub fn commands(
|
|||||||
fd: &FrameData,
|
fd: &FrameData,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
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| {
|
let items = app_data.lock().get_control_items().map_or(vec![], |i| {
|
||||||
i.iter()
|
i.iter()
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
@@ -220,7 +219,7 @@ pub fn containers(
|
|||||||
fd: &FrameData,
|
fd: &FrameData,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
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
|
let items = app_data
|
||||||
.lock()
|
.lock()
|
||||||
@@ -259,7 +258,7 @@ pub fn logs(
|
|||||||
fd: &FrameData,
|
fd: &FrameData,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
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 {
|
if fd.init {
|
||||||
let paragraph = Paragraph::new(format!("parsing logs {}", fd.loading_icon))
|
let paragraph = Paragraph::new(format!("parsing logs {}", fd.loading_icon))
|
||||||
.style(Style::default())
|
.style(Style::default())
|
||||||
|
|||||||
@@ -224,6 +224,8 @@ impl Ui {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FrameData {
|
pub struct FrameData {
|
||||||
columns: Columns,
|
columns: Columns,
|
||||||
|
container_title: String,
|
||||||
|
log_title: String,
|
||||||
delete_confirm: Option<ContainerId>,
|
delete_confirm: Option<ContainerId>,
|
||||||
has_containers: bool,
|
has_containers: bool,
|
||||||
has_error: Option<AppError>,
|
has_error: Option<AppError>,
|
||||||
@@ -248,6 +250,8 @@ impl From<(MutexGuard<'_, AppData>, MutexGuard<'_, GuiState>)> for FrameData {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
columns: data.0.get_width(),
|
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(),
|
delete_confirm: data.1.get_delete_container(),
|
||||||
has_containers: data.0.get_container_len() > 0,
|
has_containers: data.0.get_container_len() > 0,
|
||||||
has_error: data.0.get_error(),
|
has_error: data.0.get_error(),
|
||||||
|
|||||||
Reference in New Issue
Block a user