Skip to content

Commit

Permalink
Updates (#51)
Browse files Browse the repository at this point in the history
* fix: clear area before render filter widget

* update: move ft_search_panel area

* fix: panic while scanning with  Pattern '*'
  • Loading branch information
honhimW authored Jan 17, 2025
1 parent fe52518 commit 4dd2902
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 65 deletions.
23 changes: 1 addition & 22 deletions ratisui-core/src/redis_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use deadpool_redis::redis::cmd;
use deadpool_redis::{Pool, Runtime};
use futures::future::join_all;
use futures::StreamExt;
use log::{info};
use log::info;
use once_cell::sync::Lazy;
use redis::ConnectionAddr::{Tcp, TcpTls};
use redis::{AsyncCommands, AsyncIter, Client, Cmd, ConnectionAddr, ConnectionInfo, ConnectionLike, FromRedisValue, JsonAsyncCommands, RedisConnectionInfo, ScanOptions, ToRedisArgs, Value, VerbatimFormat};
Expand Down Expand Up @@ -1052,27 +1052,6 @@ impl RedisOperations {
}
}

// pub async fn sscan<K: ToRedisArgs + Send + Sync>(&self, key: K) -> Result<Vec<String>> {
// if self.is_cluster() {
// let pool = &self.cluster_pool.clone().context("should be cluster")?;
// let mut connection = pool.get().await?;
// let mut iter: AsyncIter<String> = connection.sscan(key).await?;
// let mut vec = vec![];
// while let Some(item) = iter.next_item().await {
// vec.push(item);
// }
// Ok(vec)
// } else {
// let mut connection = self.get_standalone_connection().await?;
// let mut iter: AsyncIter<String> = connection.sscan(key).await?;
// let mut vec = vec![];
// while let Some(item) = iter.next_item().await {
// vec.push(item);
// }
// Ok(vec)
// }
// }

pub async fn del<K: ToRedisArgs + Send + Sync>(&self, key: K) -> Result<()> {
if self.is_cluster() {
let mut connection = self.get_cluster_connection().await?;
Expand Down
26 changes: 9 additions & 17 deletions src/components/ft_search_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'a> FtSearchPanel<'a> {

fn get_index_items(&self, input: &str, cursor_x: usize) -> (Vec<CompletionItem>, String) {
if let Some(ref indexes) = self.indexes {
let items = indexes
let mut items = indexes
.iter()
.map(|index_name| {
let mut item = CompletionItem::custom(index_name, "Index");
Expand All @@ -201,18 +201,14 @@ impl<'a> FtSearchPanel<'a> {
"attributes_count ",
index_info.attributes.len().to_string(),
);
// for info in index_info.attributes.iter() {
// doc = doc
// .attribute("type ", info.kind.clone())
// .attribute("identifier ", info.identifier.clone())
// .attribute("attribute ", info.attribute.clone())
// ;
// }
item = item.description(doc);
};
item
})
.collect::<Vec<CompletionItem>>();
items = items.into_iter().filter(|x| {
x.label.label.to_lowercase().contains(&input.to_lowercase())
}).collect();
return (items, input.to_string());
}
(vec![], "".to_string())
Expand Down Expand Up @@ -566,16 +562,12 @@ If you use the LIMIT option without sorting, the results returned are non-determ
impl Renderable for FtSearchPanel<'_> {
fn render_frame(&mut self, frame: &mut Frame, rect: Rect) -> Result<()> {
frame.render_widget(Clear::default(), rect);
let horizontal = if matches!(self.editing, Editing::Index) {
Layout::horizontal([Percentage(30), Fill(1)]).split(rect)
} else {
Layout::horizontal([Percentage(20), Fill(1)]).split(rect)
};
let vertical = Layout::vertical([Percentage(50), Percentage(50)]).split(rect);

let index_area = self.index_block.inner(horizontal[0]);
let search_area = self.index_block.inner(horizontal[1]);
frame.render_widget(&self.index_block, horizontal[0]);
frame.render_widget(&self.search_block, horizontal[1]);
let index_area = self.index_block.inner(vertical[0]);
let search_area = self.index_block.inner(vertical[1]);
frame.render_widget(&self.index_block, vertical[0]);
frame.render_widget(&self.search_block, vertical[1]);
let block = Block::bordered();
let inner_area = block.inner(rect);
let frame_area = frame.area();
Expand Down
49 changes: 23 additions & 26 deletions src/tabs/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use anyhow::{anyhow, Context, Error, Result};
use crossbeam_channel::{unbounded, Receiver, Sender};
use log::info;
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use ratatui::layout::Constraint::{Fill, Length, Min};
use ratatui::layout::Constraint::{Length, Min};
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use ratatui::prelude::{Line, Style, Stylize, Text};
use ratatui::style::{Color, Modifier};
use ratatui::text::Span;
use ratatui::widgets::block::Position;
use ratatui::widgets::{Block, Borders, Padding, Paragraph, Scrollbar, ScrollbarOrientation};
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Scrollbar, ScrollbarOrientation};
use ratatui::{symbols, Frame};
use ratisui_core::bus::{publish_event, publish_msg, GlobalEvent, Message};
use ratisui_core::marcos::KeyAsserter;
Expand Down Expand Up @@ -288,19 +288,22 @@ impl ExplorerTab {
}

fn render_keys_block(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
self.render_tree(frame, area)?;
if self.show_filter {
let vertical = Layout::vertical([Min(0), Length(3), Length(1)]).split(area);
let horizontal = Layout::horizontal([Length(1), Min(0), Length(1)]).split(vertical[1]);
self.render_filter_input(frame, horizontal[1])?;
}

if self.show_rename {
let vertical = Layout::vertical([Min(0), Length(3), Length(1)]).split(area);
let horizontal = Layout::horizontal([Length(1), Min(0), Length(1)]).split(vertical[1]);
self.render_rename_key_input(frame, horizontal[1])?;
if self.show_filter || self.show_rename {
let vertical = Layout::vertical([Min(0), Length(3)]).split(area);
self.render_tree(frame, vertical[0])?;
if self.show_filter {
self.render_filter_input(frame, vertical[1])?;
}
if self.show_rename {
self.render_rename_key_input(frame, vertical[1])?;
}
} else if self.show_search_popup {
let vertical = Layout::vertical([Min(0), Length(6)]).split(area);
self.render_tree(frame, vertical[0])?;
self.ft_search_panel.render_frame(frame, vertical[1])?;
} else {
self.render_tree(frame, area)?;
}

Ok(())
}

Expand Down Expand Up @@ -407,6 +410,7 @@ impl ExplorerTab {
.border_style(self.border_color(KeysTree))
.title(format!("Scan Keys ({})", self.scan_keys_result.len()))
);
frame.render_widget(Clear::default(), area);
frame.render_widget(&self.filter_text_area, area);
Ok(())
}
Expand Down Expand Up @@ -444,13 +448,6 @@ impl ExplorerTab {
}
}

fn render_search_popup(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let popup_area = centered_rect(60, 60, area);
let vertical = Layout::vertical([Length(3), Fill(1)]).split(popup_area);
self.ft_search_panel.render_frame(frame, vertical[0])?;
Ok(())
}

fn render_tree(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let tree = Tree::new(&self.tree_items)?
.block(
Expand Down Expand Up @@ -581,6 +578,9 @@ impl ExplorerTab {
match self.filter_mod {
FilterMod::Fuzzy => contains = redis_key.name.contains(filter_text),
FilterMod::Pattern => {
if filter_text == "*" {
return true;
}
let fuzzy_start = filter_text.starts_with("*");
let fuzzy_end = filter_text.ends_with("*");
let mut _filter_text = filter_text.clone();
Expand Down Expand Up @@ -869,7 +869,7 @@ impl ExplorerTab {
match key_event.code {
KeyCode::Enter => {
self.do_ft_search()?;
self.show_search_popup = false;
// self.show_search_popup = false;
return Ok(true);
}
KeyCode::Esc => {
Expand Down Expand Up @@ -1109,18 +1109,15 @@ impl Renderable for ExplorerTab {
.constraints([Constraint::Percentage(20), Constraint::Percentage(80)])
.split(rect)
};
self.render_keys_block(frame, chunks[0])?;
self.render_values_block(frame, chunks[1])?;
self.render_keys_block(frame, chunks[0])?;

if self.show_delete_popup {
self.render_delete_popup(frame, rect);
}
if self.show_create {
self.render_create_key_form(frame, frame.area())?;
}
if self.show_search_popup {
self.render_search_popup(frame, frame.area())?;
}

Ok(())
}
Expand Down

0 comments on commit 4dd2902

Please sign in to comment.