Skip to content

Commit

Permalink
refactor filter into widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbuel committed Dec 9, 2024
1 parent 6420cb0 commit 2560ae4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 57 deletions.
17 changes: 3 additions & 14 deletions src/app/model/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crossterm::event::KeyCode;
use log::debug;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Modifier, Styled, Stylize};
use ratatui::style::{Modifier, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{Block, BorderType, Borders, Paragraph, Row, StatefulWidget, Table, Widget};
use ratatui::widgets::{Block, BorderType, Borders, Row, StatefulWidget, Table, Widget};

use crate::airflow::config::AirflowConfig;
use crate::app::events::custom::FlowrsEvent;
Expand Down Expand Up @@ -122,18 +122,7 @@ impl Widget for &mut ConfigModel {
.margin(0)
.split(area);

let filter = self.filter.prefix().clone();

let paragraph = Paragraph::new(filter.unwrap_or("".to_string()))
.block(
Block::default()
.border_type(BorderType::Rounded)
.borders(Borders::ALL)
.title("filter"),
)
.set_style(DEFAULT_STYLE);

Widget::render(paragraph, rects[1], buf);
self.filter.render(rects[1], buf);

rects
} else {
Expand Down
16 changes: 2 additions & 14 deletions src/app/model/dagruns.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crossterm::event::KeyCode;
use log::debug;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Modifier, Style, Styled, Stylize};
use ratatui::style::{Modifier, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{
Block, BorderType, Borders, Clear, Paragraph, Row, Scrollbar, ScrollbarOrientation,
Expand Down Expand Up @@ -308,19 +308,7 @@ impl Widget for &mut DagRunModel {
.margin(0)
.split(area);

let filter = self.filter.prefix().clone();

let paragraph = Paragraph::new(filter.unwrap_or("".to_string()))
.block(
Block::default()
.border_type(BorderType::Rounded)
.borders(Borders::ALL)
.title("filter"),
)
.set_style(DEFAULT_STYLE);

Widget::render(paragraph, rects[1], buf);

self.filter.render(rects[1], buf);
rects
} else {
Layout::default()
Expand Down
17 changes: 3 additions & 14 deletions src/app/model/dags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crossterm::event::KeyCode;
use log::debug;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Flex, Layout, Rect};
use ratatui::style::{Color, Modifier, Style, Styled, Stylize};
use ratatui::style::{Color, Modifier, Style, Stylize};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, BorderType, Borders, Paragraph, Row, StatefulWidget, Table, Widget};
use ratatui::widgets::{Block, BorderType, Borders, Row, StatefulWidget, Table, Widget};
use time::OffsetDateTime;

use crate::airflow::model::dag::Dag;
Expand Down Expand Up @@ -186,18 +186,7 @@ impl Widget for &mut DagModel {
.margin(0)
.split(area);

let filter = self.filter.prefix().clone();

let paragraph = Paragraph::new(filter.unwrap_or("".to_string()))
.block(
Block::default()
.border_type(BorderType::Rounded)
.borders(Borders::ALL)
.title("filter"),
)
.set_style(DEFAULT_STYLE);

Widget::render(paragraph, rects[1], buf);
self.filter.render(rects[1], buf);

rects
} else {
Expand Down
25 changes: 25 additions & 0 deletions src/app/model/filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
buffer::Buffer,
layout::Rect,
style::Styled,
widgets::{Block, BorderType, Borders, Paragraph, Widget},
};

use crate::ui::constants::DEFAULT_STYLE;

pub struct Filter {
pub enabled: bool,
Expand Down Expand Up @@ -58,3 +66,20 @@ impl Default for Filter {
Self::new()
}
}

impl Widget for &Filter {
fn render(self, area: Rect, buf: &mut Buffer) {
let filter = self.prefix().clone();

let paragraph = Paragraph::new(filter.unwrap_or("".to_string()))
.block(
Block::default()
.border_type(BorderType::Rounded)
.borders(Borders::ALL)
.title("filter"),
)
.set_style(DEFAULT_STYLE);

Widget::render(paragraph, area, buf);
}
}
18 changes: 3 additions & 15 deletions src/app/model/taskinstances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crossterm::event::KeyCode;
use log::debug;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::style::{Modifier, Style, Styled, Stylize};
use ratatui::style::{Modifier, Style, Stylize};
use ratatui::text::Line;
use ratatui::widgets::{Block, BorderType, Borders, Paragraph, Row, StatefulWidget, Table, Widget};
use ratatui::widgets::{Block, BorderType, Borders, Row, StatefulWidget, Table, Widget};
use time::format_description;

use crate::airflow::model::taskinstance::TaskInstance;
Expand Down Expand Up @@ -251,19 +251,7 @@ impl Widget for &mut TaskInstanceModel {
.margin(0)
.split(area);

let filter = self.filter.prefix().clone();

let paragraph = Paragraph::new(filter.unwrap_or("".to_string()))
.block(
Block::default()
.border_type(BorderType::Rounded)
.borders(Borders::ALL)
.title("filter"),
)
.set_style(DEFAULT_STYLE);

Widget::render(paragraph, rects[1], buffer);

self.filter.render(rects[1], buffer);
rects
} else {
Layout::default()
Expand Down

0 comments on commit 2560ae4

Please sign in to comment.