diff --git a/src/app.rs b/src/app.rs index 2cab8d8..1dcab65 100644 --- a/src/app.rs +++ b/src/app.rs @@ -183,12 +183,11 @@ impl App { Some(self.record_table.filter.input_str()) }, orders, - header_icons, ) .await?; self.record_table.update( records, - headers, + self.concat_headers(headers, header_icons), database.clone(), table.clone(), hold_cursor_position, @@ -242,7 +241,7 @@ impl App { .pool .as_ref() .unwrap() - .get_records(&database, &table, 0, None, None, None) + .get_records(&database, &table, 0, None, None) .await?; self.record_table.update( records, @@ -315,7 +314,6 @@ impl App { Some(self.record_table.filter.input_str()) }, None, - None, ) .await?; if !records.is_empty() { @@ -406,6 +404,24 @@ impl App { } Ok(EventState::NotConsumed) } + + fn concat_headers( + &self, + headers: Vec, + header_icons: Option>, + ) -> Vec { + if let Some(header_icons) = &header_icons { + let mut new_headers = vec![String::new(); headers.len()]; + for (index, header) in headers.iter().enumerate() { + new_headers[index] = format!("{} {}", header, header_icons[index]) + .trim() + .to_string(); + } + return new_headers; + } + + headers + } } #[cfg(test)] @@ -441,4 +457,25 @@ mod test { ); assert_eq!(app.left_main_chunk_percentage, 15); } + + #[test] + fn test_concat_headers() { + let app = App::new(Config::default()); + let headers = vec![ + "ID".to_string(), + "NAME".to_string(), + "TIMESTAMP".to_string(), + ]; + let header_icons = vec!["".to_string(), "↑1".to_string(), "↓2".to_string()]; + let concat_headers: Vec = app.concat_headers(headers, Some(header_icons)); + + assert_eq!( + concat_headers, + vec![ + "ID".to_string(), + "NAME ↑1".to_string(), + "TIMESTAMP ↓2".to_string() + ] + ) + } } diff --git a/src/database/mod.rs b/src/database/mod.rs index 059fb3b..76a874a 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -23,7 +23,6 @@ pub trait Pool: Send + Sync { page: u16, filter: Option, orders: Option, - header_icons: Option>, ) -> anyhow::Result<(Vec, Vec>)>; async fn get_columns( &self, @@ -48,20 +47,6 @@ pub trait Pool: Send + Sync { async fn close(&self); } -fn concat_headers(headers: Vec, header_icons: Option>) -> Vec { - if let Some(header_icons) = &header_icons { - let mut new_headers = vec![String::new(); headers.len()]; - for (index, header) in headers.iter().enumerate() { - new_headers[index] = format!("{} {}", header, header_icons[index]) - .trim() - .to_string(); - } - return new_headers; - } - - headers -} - pub enum ExecuteResult { Read { headers: Vec, @@ -85,27 +70,3 @@ macro_rules! get_or_null { $value.map_or("NULL".to_string(), |v| v.to_string()) }; } - -#[cfg(test)] -mod test { - use super::concat_headers; - #[test] - fn test_concat_headers() { - let headers = vec![ - "ID".to_string(), - "NAME".to_string(), - "TIMESTAMP".to_string(), - ]; - let header_icons = vec!["".to_string(), "↑1".to_string(), "↓2".to_string()]; - let concat_headers: Vec = concat_headers(headers, Some(header_icons)); - - assert_eq!( - concat_headers, - vec![ - "ID".to_string(), - "NAME ↑1".to_string(), - "TIMESTAMP ↓2".to_string() - ] - ) - } -} diff --git a/src/database/mysql.rs b/src/database/mysql.rs index c810cdd..1f70f73 100644 --- a/src/database/mysql.rs +++ b/src/database/mysql.rs @@ -1,6 +1,6 @@ use crate::get_or_null; -use super::{concat_headers, ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; +use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; use async_trait::async_trait; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use database_tree::{Child, Database, Table}; @@ -229,7 +229,6 @@ impl Pool for MySqlPool { page: u16, filter: Option, orders: Option, - header_icons: Option>, ) -> anyhow::Result<(Vec, Vec>)> { let query = if let (Some(filter), Some(orders)) = (&filter, &orders) { format!( @@ -283,7 +282,7 @@ impl Pool for MySqlPool { } records.push(new_row) } - Ok((concat_headers(headers, header_icons), records)) + Ok((headers, records)) } async fn get_columns( diff --git a/src/database/postgres.rs b/src/database/postgres.rs index 78b6bc0..f7493a0 100644 --- a/src/database/postgres.rs +++ b/src/database/postgres.rs @@ -1,6 +1,6 @@ use crate::get_or_null; -use super::{concat_headers, ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; +use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; use async_trait::async_trait; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use database_tree::{Child, Database, Schema, Table}; @@ -246,7 +246,6 @@ impl Pool for PostgresPool { page: u16, filter: Option, orders: Option, - header_icons: Option>, ) -> anyhow::Result<(Vec, Vec>)> { let query = if let (Some(filter), Some(orders)) = (&filter, &orders) { format!( @@ -344,7 +343,7 @@ impl Pool for PostgresPool { } records.push(new_row) } - Ok((concat_headers(headers, header_icons), records)) + Ok((headers, records)) } async fn get_columns( diff --git a/src/database/sqlite.rs b/src/database/sqlite.rs index 166f069..5a0d5f4 100644 --- a/src/database/sqlite.rs +++ b/src/database/sqlite.rs @@ -1,6 +1,6 @@ use crate::get_or_null; -use super::{concat_headers, ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; +use super::{ExecuteResult, Pool, TableRow, RECORDS_LIMIT_PER_PAGE}; use async_trait::async_trait; use chrono::NaiveDateTime; use database_tree::{Child, Database, Table}; @@ -231,7 +231,6 @@ impl Pool for SqlitePool { page: u16, filter: Option, orders: Option, - header_icons: Option>, ) -> anyhow::Result<(Vec, Vec>)> { let query = if let (Some(filter), Some(orders)) = (&filter, &orders) { format!( @@ -281,7 +280,7 @@ impl Pool for SqlitePool { } records.push(new_row) } - Ok((concat_headers(headers, header_icons), records)) + Ok((headers, records)) } async fn get_columns(