add logic is now using canvas library now
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// src/pages/admin_panel/add_logic/ui.rs
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::pages::admin_panel::add_logic::state::{AddLogicFocus, AddLogicState};
|
||||
use crate::pages::admin_panel::add_logic::state::{AddLogicFocus, AddLogicState, AddLogicFormState};
|
||||
use canvas::{render_canvas, FormEditor};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
@@ -19,7 +19,7 @@ pub fn render_add_logic(
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
app_state: &AppState,
|
||||
add_logic_state: &mut AddLogicState,
|
||||
add_logic_state: &mut AddLogicFormState,
|
||||
) {
|
||||
let main_block = Block::default()
|
||||
.title(" Add New Logic Script ")
|
||||
@@ -32,9 +32,13 @@ pub fn render_add_logic(
|
||||
f.render_widget(main_block, area);
|
||||
|
||||
// Handle full-screen script editing
|
||||
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
||||
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
|
||||
let border_style_color = if crate::components::common::text_editor::TextEditor::is_vim_insert_mode(&add_logic_state.vim_state) {
|
||||
if add_logic_state.current_focus() == AddLogicFocus::InsideScriptContent {
|
||||
let mut editor_ref = add_logic_state
|
||||
.state
|
||||
.script_content_editor
|
||||
.borrow_mut();
|
||||
|
||||
let border_style_color = if crate::components::common::text_editor::TextEditor::is_vim_insert_mode(add_logic_state.vim_state()) {
|
||||
theme.highlight
|
||||
} else {
|
||||
theme.secondary
|
||||
@@ -44,13 +48,13 @@ pub fn render_add_logic(
|
||||
editor_ref.set_cursor_line_style(Style::default());
|
||||
editor_ref.set_cursor_style(Style::default().add_modifier(Modifier::REVERSED));
|
||||
|
||||
let script_title_hint = match add_logic_state.editor_keybinding_mode {
|
||||
let script_title_hint = match add_logic_state.editor_keybinding_mode() {
|
||||
EditorKeybindingMode::Vim => {
|
||||
let vim_mode_status = crate::components::common::text_editor::TextEditor::get_vim_mode_status(&add_logic_state.vim_state);
|
||||
let vim_mode_status = crate::components::common::text_editor::TextEditor::get_vim_mode_status(add_logic_state.vim_state());
|
||||
format!("Script {}", vim_mode_status)
|
||||
}
|
||||
EditorKeybindingMode::Emacs | EditorKeybindingMode::Default => {
|
||||
if crate::components::common::text_editor::TextEditor::is_vim_insert_mode(&add_logic_state.vim_state) {
|
||||
if crate::components::common::text_editor::TextEditor::is_vim_insert_mode(add_logic_state.vim_state()) {
|
||||
"Script (Editing)".to_string()
|
||||
} else {
|
||||
"Script".to_string()
|
||||
@@ -72,10 +76,10 @@ pub fn render_add_logic(
|
||||
drop(editor_ref);
|
||||
|
||||
// === SCRIPT EDITOR AUTOCOMPLETE RENDERING ===
|
||||
if add_logic_state.script_editor_autocomplete_active && !add_logic_state.script_editor_suggestions.is_empty() {
|
||||
if add_logic_state.script_editor_autocomplete_active() && !add_logic_state.script_editor_suggestions().is_empty() {
|
||||
// Get the current cursor position from textarea
|
||||
let current_cursor = {
|
||||
let editor_borrow = add_logic_state.script_content_editor.borrow();
|
||||
let editor_borrow = add_logic_state.script_content_editor().borrow();
|
||||
editor_borrow.cursor() // Returns (row, col) as (usize, usize)
|
||||
};
|
||||
|
||||
@@ -103,8 +107,8 @@ pub fn render_add_logic(
|
||||
input_rect,
|
||||
f.area(), // Full frame area for clamping
|
||||
theme,
|
||||
&add_logic_state.script_editor_suggestions,
|
||||
add_logic_state.script_editor_selected_suggestion_index,
|
||||
add_logic_state.script_editor_suggestions(),
|
||||
add_logic_state.script_editor_selected_suggestion_index(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,54 +132,54 @@ pub fn render_add_logic(
|
||||
let buttons_area = main_chunks[3];
|
||||
|
||||
// Top info
|
||||
let table_label = if let Some(name) = add_logic_state.selected_table_name() {
|
||||
name.clone()
|
||||
} else if let Some(id) = add_logic_state.selected_table_id() {
|
||||
format!("ID {}", id)
|
||||
} else {
|
||||
"Global (Not Selected)".to_string()
|
||||
};
|
||||
|
||||
let profile_text = Paragraph::new(vec![
|
||||
Line::from(Span::styled(
|
||||
format!("Profile: {}", add_logic_state.profile_name),
|
||||
Style::default().fg(theme.fg),
|
||||
format!("Profile: {}", add_logic_state.profile_name()),
|
||||
Style::default().fg(theme.fg),
|
||||
)),
|
||||
Line::from(Span::styled(
|
||||
format!(
|
||||
"Table: {}",
|
||||
add_logic_state
|
||||
.selected_table_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| add_logic_state.selected_table_id
|
||||
.map(|id| format!("ID {}", id))
|
||||
.unwrap_or_else(|| "Global (Not Selected)".to_string()))
|
||||
),
|
||||
Style::default().fg(theme.fg),
|
||||
format!("Table: {}", table_label),
|
||||
Style::default().fg(theme.fg),
|
||||
)),
|
||||
])
|
||||
.block(
|
||||
Block::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::BOTTOM)
|
||||
.border_style(Style::default().fg(theme.secondary)),
|
||||
);
|
||||
);
|
||||
f.render_widget(profile_text, top_info_area);
|
||||
|
||||
// Canvas - USING CANVAS LIBRARY
|
||||
let focus_on_canvas_inputs = matches!(
|
||||
add_logic_state.current_focus,
|
||||
add_logic_state.current_focus(),
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription
|
||||
);
|
||||
|
||||
let editor = FormEditor::new(add_logic_state.clone());
|
||||
let active_field_rect = render_canvas(f, canvas_area, &editor, theme);
|
||||
let editor = &add_logic_state.editor;
|
||||
let active_field_rect = render_canvas(f, canvas_area, editor, theme);
|
||||
|
||||
// --- Render Autocomplete for Target Column ---
|
||||
if editor.mode() == canvas::AppMode::Edit && editor.current_field() == 1 { // Target Column field
|
||||
if add_logic_state.in_target_column_suggestion_mode && add_logic_state.show_target_column_suggestions {
|
||||
if !add_logic_state.target_column_suggestions.is_empty() {
|
||||
if add_logic_state.in_target_column_suggestion_mode() && add_logic_state.show_target_column_suggestions() {
|
||||
if !add_logic_state.target_column_suggestions().is_empty() {
|
||||
if let Some(input_rect) = active_field_rect {
|
||||
autocomplete::render_autocomplete_dropdown(
|
||||
f,
|
||||
input_rect,
|
||||
f.area(), // Full frame area for clamping
|
||||
theme,
|
||||
&add_logic_state.target_column_suggestions,
|
||||
add_logic_state.selected_target_column_suggestion_index,
|
||||
add_logic_state.target_column_suggestions(),
|
||||
add_logic_state.selected_target_column_suggestion_index(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -184,10 +188,10 @@ pub fn render_add_logic(
|
||||
|
||||
// Script content preview
|
||||
{
|
||||
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
|
||||
let mut editor_ref = add_logic_state.script_content_editor().borrow_mut();
|
||||
editor_ref.set_cursor_line_style(Style::default());
|
||||
|
||||
let is_script_preview_focused = add_logic_state.current_focus == AddLogicFocus::ScriptContentPreview;
|
||||
let is_script_preview_focused = add_logic_state.current_focus() == AddLogicFocus::ScriptContentPreview;
|
||||
|
||||
if is_script_preview_focused {
|
||||
editor_ref.set_cursor_style(Style::default().add_modifier(Modifier::REVERSED));
|
||||
@@ -256,7 +260,7 @@ pub fn render_add_logic(
|
||||
let save_button = Paragraph::new(" Save Logic ")
|
||||
.style(get_button_style(
|
||||
AddLogicFocus::SaveButton,
|
||||
add_logic_state.current_focus,
|
||||
add_logic_state.current_focus(),
|
||||
))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
@@ -264,7 +268,7 @@ pub fn render_add_logic(
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(
|
||||
add_logic_state.current_focus == AddLogicFocus::SaveButton,
|
||||
add_logic_state.current_focus() == AddLogicFocus::SaveButton,
|
||||
theme,
|
||||
)),
|
||||
);
|
||||
@@ -273,7 +277,7 @@ pub fn render_add_logic(
|
||||
let cancel_button = Paragraph::new(" Cancel ")
|
||||
.style(get_button_style(
|
||||
AddLogicFocus::CancelButton,
|
||||
add_logic_state.current_focus,
|
||||
add_logic_state.current_focus(),
|
||||
))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
@@ -281,7 +285,7 @@ pub fn render_add_logic(
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(
|
||||
add_logic_state.current_focus == AddLogicFocus::CancelButton,
|
||||
add_logic_state.current_focus() == AddLogicFocus::CancelButton,
|
||||
theme,
|
||||
)),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user