moved add_table and add_logic, needs more things done tho
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// src/pages/admin/admin/state.rs
|
||||
use ratatui::widgets::ListState;
|
||||
use crate::pages::admin_panel::add_table::state::AddTableState;
|
||||
use crate::state::pages::add_logic::AddLogicState;
|
||||
use crate::pages::admin_panel::add_logic::state::AddLogicState;
|
||||
use crate::movement::{move_focus, MovementAction};
|
||||
use crate::state::app::state::AppState;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::config::binds::config::Config;
|
||||
use crate::buffer::state::{BufferState, AppView};
|
||||
use crate::pages::admin_panel::add_table::state::{AddTableState, LinkDefinition};
|
||||
use ratatui::widgets::ListState;
|
||||
use crate::state::pages::add_logic::{AddLogicState, AddLogicFocus}; // Added AddLogicFocus import
|
||||
use crate::pages::admin_panel::add_logic::state::{AddLogicState, AddLogicFocus};
|
||||
|
||||
// Helper functions list_select_next and list_select_previous remain the same
|
||||
fn list_select_next(list_state: &mut ListState, item_count: usize) {
|
||||
|
||||
5
client/src/pages/admin_panel/add_logic/mod.rs
Normal file
5
client/src/pages/admin_panel/add_logic/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
// src/pages/admin_panel/add_logic/mod.rs
|
||||
|
||||
pub mod ui;
|
||||
pub mod nav;
|
||||
pub mod state;
|
||||
531
client/src/pages/admin_panel/add_logic/nav.rs
Normal file
531
client/src/pages/admin_panel/add_logic/nav.rs
Normal file
@@ -0,0 +1,531 @@
|
||||
// src/pages/admin_panel/add_logic/nav.rs
|
||||
|
||||
use crate::config::binds::config::{Config, EditorKeybindingMode};
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::pages::admin_panel::add_logic::state::{AddLogicFocus, AddLogicState};
|
||||
use crate::buffer::{AppView, BufferState};
|
||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||
use crate::services::GrpcClient;
|
||||
use tokio::sync::mpsc;
|
||||
use anyhow::Result;
|
||||
use crate::components::common::text_editor::TextEditor;
|
||||
use crate::services::ui_service::UiService;
|
||||
use tui_textarea::CursorMove;
|
||||
use crate::pages::admin::AdminState;
|
||||
use crate::pages::routing::{Router, Page};
|
||||
|
||||
pub type SaveLogicResultSender = mpsc::Sender<Result<String>>;
|
||||
|
||||
pub fn handle_add_logic_navigation(
|
||||
key_event: KeyEvent,
|
||||
config: &Config,
|
||||
app_state: &mut AppState,
|
||||
buffer_state: &mut BufferState,
|
||||
grpc_client: GrpcClient,
|
||||
save_logic_sender: SaveLogicResultSender,
|
||||
command_message: &mut String,
|
||||
router: &mut Router,
|
||||
) -> bool {
|
||||
if let Page::AddLogic(add_logic_state) = &mut router.current {
|
||||
// === FULLSCREEN SCRIPT EDITING ===
|
||||
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
||||
// === AUTOCOMPLETE HANDLING ===
|
||||
if add_logic_state.script_editor_autocomplete_active {
|
||||
match key_event.code {
|
||||
KeyCode::Char(c) if c.is_alphanumeric() || c == '_' => {
|
||||
add_logic_state.script_editor_filter_text.push(c);
|
||||
add_logic_state.update_script_editor_suggestions();
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
*command_message =
|
||||
format!("Filtering: @{}", add_logic_state.script_editor_filter_text);
|
||||
return true;
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
if !add_logic_state.script_editor_filter_text.is_empty() {
|
||||
add_logic_state.script_editor_filter_text.pop();
|
||||
add_logic_state.update_script_editor_suggestions();
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
*command_message =
|
||||
if add_logic_state.script_editor_filter_text.is_empty() {
|
||||
"Autocomplete: @".to_string()
|
||||
} else {
|
||||
format!(
|
||||
"Filtering: @{}",
|
||||
add_logic_state.script_editor_filter_text
|
||||
)
|
||||
};
|
||||
} else {
|
||||
let should_deactivate =
|
||||
if let Some((trigger_line, trigger_col)) =
|
||||
add_logic_state.script_editor_trigger_position
|
||||
{
|
||||
let current_cursor = {
|
||||
let editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow();
|
||||
editor_borrow.cursor()
|
||||
};
|
||||
current_cursor.0 == trigger_line
|
||||
&& current_cursor.1 == trigger_col + 1
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if should_deactivate {
|
||||
add_logic_state.deactivate_script_editor_autocomplete();
|
||||
*command_message = "Autocomplete cancelled".to_string();
|
||||
}
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
KeyCode::Tab | KeyCode::Down => {
|
||||
if !add_logic_state.script_editor_suggestions.is_empty() {
|
||||
let current = add_logic_state
|
||||
.script_editor_selected_suggestion_index
|
||||
.unwrap_or(0);
|
||||
let next =
|
||||
(current + 1) % add_logic_state.script_editor_suggestions.len();
|
||||
add_logic_state.script_editor_selected_suggestion_index = Some(next);
|
||||
*command_message = format!(
|
||||
"Selected: {}",
|
||||
add_logic_state.script_editor_suggestions[next]
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
KeyCode::Up => {
|
||||
if !add_logic_state.script_editor_suggestions.is_empty() {
|
||||
let current = add_logic_state
|
||||
.script_editor_selected_suggestion_index
|
||||
.unwrap_or(0);
|
||||
let prev = if current == 0 {
|
||||
add_logic_state.script_editor_suggestions.len() - 1
|
||||
} else {
|
||||
current - 1
|
||||
};
|
||||
add_logic_state.script_editor_selected_suggestion_index = Some(prev);
|
||||
*command_message = format!(
|
||||
"Selected: {}",
|
||||
add_logic_state.script_editor_suggestions[prev]
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let Some(selected_idx) =
|
||||
add_logic_state.script_editor_selected_suggestion_index
|
||||
{
|
||||
if let Some(suggestion) = add_logic_state
|
||||
.script_editor_suggestions
|
||||
.get(selected_idx)
|
||||
.cloned()
|
||||
{
|
||||
let trigger_pos =
|
||||
add_logic_state.script_editor_trigger_position;
|
||||
let filter_len =
|
||||
add_logic_state.script_editor_filter_text.len();
|
||||
|
||||
add_logic_state.deactivate_script_editor_autocomplete();
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
|
||||
if let Some(pos) = trigger_pos {
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
|
||||
if suggestion == "sql" {
|
||||
replace_autocomplete_text(
|
||||
&mut editor_borrow,
|
||||
pos,
|
||||
filter_len,
|
||||
"sql",
|
||||
);
|
||||
editor_borrow.insert_str("('')");
|
||||
editor_borrow.move_cursor(CursorMove::Back);
|
||||
editor_borrow.move_cursor(CursorMove::Back);
|
||||
*command_message = "Inserted: @sql('')".to_string();
|
||||
} else {
|
||||
let is_table_selection =
|
||||
add_logic_state.is_table_name_suggestion(&suggestion);
|
||||
replace_autocomplete_text(
|
||||
&mut editor_borrow,
|
||||
pos,
|
||||
filter_len,
|
||||
&suggestion,
|
||||
);
|
||||
|
||||
if is_table_selection {
|
||||
editor_borrow.insert_str(".");
|
||||
let new_cursor = editor_borrow.cursor();
|
||||
drop(editor_borrow);
|
||||
|
||||
add_logic_state.script_editor_trigger_position =
|
||||
Some(new_cursor);
|
||||
add_logic_state.script_editor_autocomplete_active = true;
|
||||
add_logic_state.script_editor_filter_text.clear();
|
||||
add_logic_state
|
||||
.trigger_column_autocomplete_for_table(
|
||||
suggestion.clone(),
|
||||
);
|
||||
|
||||
let profile_name =
|
||||
add_logic_state.profile_name.clone();
|
||||
let table_name_for_fetch = suggestion.clone();
|
||||
let mut client_clone = grpc_client.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = UiService::fetch_columns_for_table(
|
||||
&mut client_clone,
|
||||
&profile_name,
|
||||
&table_name_for_fetch,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::error!(
|
||||
"Failed to fetch columns for {}.{}: {}",
|
||||
profile_name,
|
||||
table_name_for_fetch,
|
||||
e
|
||||
);
|
||||
}
|
||||
});
|
||||
*command_message = format!(
|
||||
"Selected table '{}', fetching columns...",
|
||||
suggestion
|
||||
);
|
||||
} else {
|
||||
*command_message =
|
||||
format!("Inserted: {}", suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
add_logic_state.deactivate_script_editor_autocomplete();
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
KeyCode::Esc => {
|
||||
add_logic_state.deactivate_script_editor_autocomplete();
|
||||
*command_message = "Autocomplete cancelled".to_string();
|
||||
}
|
||||
_ => {
|
||||
add_logic_state.deactivate_script_editor_autocomplete();
|
||||
*command_message = "Autocomplete cancelled".to_string();
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger autocomplete with '@'
|
||||
if key_event.code == KeyCode::Char('@') && key_event.modifiers == KeyModifiers::NONE {
|
||||
let should_trigger = match add_logic_state.editor_keybinding_mode {
|
||||
EditorKeybindingMode::Vim => {
|
||||
TextEditor::is_vim_insert_mode(&add_logic_state.vim_state)
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
if should_trigger {
|
||||
let cursor_before = {
|
||||
let editor_borrow = add_logic_state.script_content_editor.borrow();
|
||||
editor_borrow.cursor()
|
||||
};
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
add_logic_state.script_editor_trigger_position = Some(cursor_before);
|
||||
add_logic_state.script_editor_autocomplete_active = true;
|
||||
add_logic_state.script_editor_filter_text.clear();
|
||||
add_logic_state.update_script_editor_suggestions();
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
*command_message = "Autocomplete: @ (Tab/↑↓ to navigate, Enter to select, Esc to cancel)".to_string();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Esc handling
|
||||
if key_event.code == KeyCode::Esc && key_event.modifiers == KeyModifiers::NONE {
|
||||
match add_logic_state.editor_keybinding_mode {
|
||||
EditorKeybindingMode::Vim => {
|
||||
let was_insert =
|
||||
TextEditor::is_vim_insert_mode(&add_logic_state.vim_state);
|
||||
{
|
||||
let mut editor_borrow =
|
||||
add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
);
|
||||
}
|
||||
if was_insert {
|
||||
*command_message =
|
||||
"VIM: Normal Mode. Esc again to exit script.".to_string();
|
||||
} else {
|
||||
add_logic_state.current_focus =
|
||||
AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
*command_message = "Exited script editing.".to_string();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
add_logic_state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
*command_message = "Exited script editing.".to_string();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Normal text input
|
||||
let changed = {
|
||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
||||
TextEditor::handle_input(
|
||||
&mut editor_borrow,
|
||||
key_event,
|
||||
&add_logic_state.editor_keybinding_mode,
|
||||
&mut add_logic_state.vim_state,
|
||||
)
|
||||
};
|
||||
if changed {
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// === NON-FULLSCREEN NAVIGATION ===
|
||||
let action = config.get_general_action(key_event.code, key_event.modifiers);
|
||||
let current_focus = add_logic_state.current_focus;
|
||||
let mut handled = true;
|
||||
let mut new_focus = current_focus;
|
||||
|
||||
match action.as_deref() {
|
||||
Some("exit_table_scroll") => {
|
||||
handled = false;
|
||||
}
|
||||
Some("move_up") => {
|
||||
match current_focus {
|
||||
AddLogicFocus::InputLogicName => {}
|
||||
AddLogicFocus::InputTargetColumn => new_focus = AddLogicFocus::InputLogicName,
|
||||
AddLogicFocus::InputDescription => {
|
||||
new_focus = AddLogicFocus::InputTargetColumn
|
||||
}
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
new_focus = AddLogicFocus::InputDescription
|
||||
}
|
||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::ScriptContentPreview,
|
||||
AddLogicFocus::CancelButton => new_focus = AddLogicFocus::SaveButton,
|
||||
_ => handled = false,
|
||||
}
|
||||
}
|
||||
Some("move_down") => {
|
||||
match current_focus {
|
||||
AddLogicFocus::InputLogicName => {
|
||||
new_focus = AddLogicFocus::InputTargetColumn
|
||||
}
|
||||
AddLogicFocus::InputTargetColumn => {
|
||||
new_focus = AddLogicFocus::InputDescription
|
||||
}
|
||||
AddLogicFocus::InputDescription => {
|
||||
add_logic_state.last_canvas_field = 2;
|
||||
new_focus = AddLogicFocus::ScriptContentPreview;
|
||||
}
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
new_focus = AddLogicFocus::SaveButton
|
||||
}
|
||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::CancelButton,
|
||||
AddLogicFocus::CancelButton => {}
|
||||
_ => handled = false,
|
||||
}
|
||||
}
|
||||
Some("next_option") => {
|
||||
match current_focus {
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {
|
||||
new_focus = AddLogicFocus::ScriptContentPreview
|
||||
}
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
new_focus = AddLogicFocus::SaveButton
|
||||
}
|
||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::CancelButton,
|
||||
AddLogicFocus::CancelButton => {}
|
||||
_ => handled = false,
|
||||
}
|
||||
}
|
||||
Some("previous_option") => {
|
||||
match current_focus {
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {}
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
new_focus = AddLogicFocus::InputDescription
|
||||
}
|
||||
AddLogicFocus::SaveButton => {
|
||||
new_focus = AddLogicFocus::ScriptContentPreview
|
||||
}
|
||||
AddLogicFocus::CancelButton => new_focus = AddLogicFocus::SaveButton,
|
||||
_ => handled = false,
|
||||
}
|
||||
}
|
||||
Some("next_field") => {
|
||||
new_focus = match current_focus {
|
||||
AddLogicFocus::InputLogicName => AddLogicFocus::InputTargetColumn,
|
||||
AddLogicFocus::InputTargetColumn => AddLogicFocus::InputDescription,
|
||||
AddLogicFocus::InputDescription => AddLogicFocus::ScriptContentPreview,
|
||||
AddLogicFocus::ScriptContentPreview => AddLogicFocus::SaveButton,
|
||||
AddLogicFocus::SaveButton => AddLogicFocus::CancelButton,
|
||||
AddLogicFocus::CancelButton => AddLogicFocus::InputLogicName,
|
||||
_ => current_focus,
|
||||
};
|
||||
}
|
||||
Some("prev_field") => {
|
||||
new_focus = match current_focus {
|
||||
AddLogicFocus::InputLogicName => AddLogicFocus::CancelButton,
|
||||
AddLogicFocus::InputTargetColumn => AddLogicFocus::InputLogicName,
|
||||
AddLogicFocus::InputDescription => AddLogicFocus::InputTargetColumn,
|
||||
AddLogicFocus::ScriptContentPreview => AddLogicFocus::InputDescription,
|
||||
AddLogicFocus::SaveButton => AddLogicFocus::ScriptContentPreview,
|
||||
AddLogicFocus::CancelButton => AddLogicFocus::SaveButton,
|
||||
_ => current_focus,
|
||||
};
|
||||
}
|
||||
Some("select") => {
|
||||
match current_focus {
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
new_focus = AddLogicFocus::InsideScriptContent;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
let mode_hint = match add_logic_state.editor_keybinding_mode {
|
||||
EditorKeybindingMode::Vim => {
|
||||
"VIM mode - 'i'/'a'/'o' to edit"
|
||||
}
|
||||
_ => "Enter/Ctrl+E to edit",
|
||||
};
|
||||
*command_message = format!(
|
||||
"Fullscreen script editing. {} or Esc to exit.",
|
||||
mode_hint
|
||||
);
|
||||
handled = true;
|
||||
}
|
||||
AddLogicFocus::SaveButton => {
|
||||
*command_message = "Save logic action".to_string();
|
||||
handled = true;
|
||||
}
|
||||
AddLogicFocus::CancelButton => {
|
||||
buffer_state.update_history(AppView::Admin);
|
||||
*command_message = "Cancelled Add Logic".to_string();
|
||||
handled = true;
|
||||
}
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {
|
||||
// Focus canvas inputs; let canvas keymap handle editing
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
handled = false; // forward to canvas
|
||||
}
|
||||
_ => handled = false,
|
||||
}
|
||||
}
|
||||
Some("toggle_edit_mode") => {
|
||||
match current_focus {
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
*command_message =
|
||||
"Focus moved to input. Use i/a (Vim) or type to edit.".to_string();
|
||||
handled = true;
|
||||
}
|
||||
_ => {
|
||||
*command_message = "Cannot toggle edit mode here.".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => handled = false,
|
||||
}
|
||||
|
||||
if handled && current_focus != new_focus {
|
||||
add_logic_state.current_focus = new_focus;
|
||||
let new_is_canvas_input_focus = matches!(
|
||||
new_focus,
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription
|
||||
);
|
||||
if new_is_canvas_input_focus {
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
} else {
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
}
|
||||
}
|
||||
handled
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn replace_autocomplete_text(
|
||||
editor: &mut tui_textarea::TextArea,
|
||||
trigger_pos: (usize, usize),
|
||||
filter_len: usize,
|
||||
replacement: &str,
|
||||
) {
|
||||
let filter_start_pos = (trigger_pos.0, trigger_pos.1 + 1);
|
||||
editor.move_cursor(CursorMove::Jump(filter_start_pos.0 as u16, filter_start_pos.1 as u16));
|
||||
for _ in 0..filter_len {
|
||||
editor.delete_next_char();
|
||||
}
|
||||
editor.insert_str(replacement);
|
||||
}
|
||||
317
client/src/pages/admin_panel/add_logic/state.rs
Normal file
317
client/src/pages/admin_panel/add_logic/state.rs
Normal file
@@ -0,0 +1,317 @@
|
||||
// src/pages/admin_panel/add_logic/state.rs
|
||||
use crate::config::binds::config::{EditorConfig, EditorKeybindingMode};
|
||||
use crate::components::common::text_editor::{TextEditor, VimState};
|
||||
use canvas::{DataProvider, AppMode};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use tui_textarea::TextArea;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum AddLogicFocus {
|
||||
#[default]
|
||||
InputLogicName,
|
||||
InputTargetColumn,
|
||||
InputDescription,
|
||||
ScriptContentPreview,
|
||||
InsideScriptContent,
|
||||
SaveButton,
|
||||
CancelButton,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AddLogicState {
|
||||
pub profile_name: String,
|
||||
pub selected_table_id: Option<i64>,
|
||||
pub selected_table_name: Option<String>,
|
||||
pub logic_name_input: String,
|
||||
pub target_column_input: String,
|
||||
pub script_content_editor: Rc<RefCell<TextArea<'static>>>,
|
||||
pub description_input: String,
|
||||
pub current_focus: AddLogicFocus,
|
||||
pub last_canvas_field: usize,
|
||||
pub logic_name_cursor_pos: usize,
|
||||
pub target_column_cursor_pos: usize,
|
||||
pub description_cursor_pos: usize,
|
||||
pub has_unsaved_changes: bool,
|
||||
pub editor_keybinding_mode: EditorKeybindingMode,
|
||||
pub vim_state: VimState,
|
||||
|
||||
// New fields for Target Column Autocomplete
|
||||
pub table_columns_for_suggestions: Vec<String>, // All columns for the table
|
||||
pub target_column_suggestions: Vec<String>, // Filtered suggestions
|
||||
pub show_target_column_suggestions: bool,
|
||||
pub selected_target_column_suggestion_index: Option<usize>,
|
||||
pub in_target_column_suggestion_mode: bool,
|
||||
|
||||
// Script Editor Autocomplete
|
||||
pub script_editor_autocomplete_active: bool,
|
||||
pub script_editor_suggestions: Vec<String>,
|
||||
pub script_editor_selected_suggestion_index: Option<usize>,
|
||||
pub script_editor_trigger_position: Option<(usize, usize)>, // (line, column)
|
||||
pub all_table_names: Vec<String>,
|
||||
pub script_editor_filter_text: String,
|
||||
|
||||
// New fields for same-profile table names and column autocomplete
|
||||
pub same_profile_table_names: Vec<String>, // Tables from same profile only
|
||||
pub script_editor_awaiting_column_autocomplete: Option<String>, // Table name waiting for column fetch
|
||||
pub app_mode: canvas::AppMode,
|
||||
}
|
||||
|
||||
impl AddLogicState {
|
||||
pub fn new(editor_config: &EditorConfig) -> Self {
|
||||
let editor = TextEditor::new_textarea(editor_config);
|
||||
AddLogicState {
|
||||
profile_name: "default".to_string(),
|
||||
selected_table_id: None,
|
||||
selected_table_name: None,
|
||||
logic_name_input: String::new(),
|
||||
target_column_input: String::new(),
|
||||
script_content_editor: Rc::new(RefCell::new(editor)),
|
||||
description_input: String::new(),
|
||||
current_focus: AddLogicFocus::InputLogicName,
|
||||
last_canvas_field: 2,
|
||||
logic_name_cursor_pos: 0,
|
||||
target_column_cursor_pos: 0,
|
||||
description_cursor_pos: 0,
|
||||
has_unsaved_changes: false,
|
||||
editor_keybinding_mode: editor_config.keybinding_mode.clone(),
|
||||
vim_state: VimState::default(),
|
||||
|
||||
table_columns_for_suggestions: Vec::new(),
|
||||
target_column_suggestions: Vec::new(),
|
||||
show_target_column_suggestions: false,
|
||||
selected_target_column_suggestion_index: None,
|
||||
in_target_column_suggestion_mode: false,
|
||||
|
||||
script_editor_autocomplete_active: false,
|
||||
script_editor_suggestions: Vec::new(),
|
||||
script_editor_selected_suggestion_index: None,
|
||||
script_editor_trigger_position: None,
|
||||
all_table_names: Vec::new(),
|
||||
script_editor_filter_text: String::new(),
|
||||
|
||||
same_profile_table_names: Vec::new(),
|
||||
script_editor_awaiting_column_autocomplete: None,
|
||||
app_mode: canvas::AppMode::Edit,
|
||||
}
|
||||
}
|
||||
|
||||
pub const INPUT_FIELD_COUNT: usize = 3;
|
||||
|
||||
/// Updates the target_column_suggestions based on current input.
|
||||
pub fn update_target_column_suggestions(&mut self) {
|
||||
let current_input = self.target_column_input.to_lowercase();
|
||||
if self.table_columns_for_suggestions.is_empty() {
|
||||
self.target_column_suggestions.clear();
|
||||
self.show_target_column_suggestions = false;
|
||||
self.selected_target_column_suggestion_index = None;
|
||||
return;
|
||||
}
|
||||
|
||||
if current_input.is_empty() {
|
||||
self.target_column_suggestions = self.table_columns_for_suggestions.clone();
|
||||
} else {
|
||||
self.target_column_suggestions = self
|
||||
.table_columns_for_suggestions
|
||||
.iter()
|
||||
.filter(|name| name.to_lowercase().contains(¤t_input))
|
||||
.cloned()
|
||||
.collect();
|
||||
}
|
||||
|
||||
self.show_target_column_suggestions = !self.target_column_suggestions.is_empty();
|
||||
if self.show_target_column_suggestions {
|
||||
if let Some(selected_idx) = self.selected_target_column_suggestion_index {
|
||||
if selected_idx >= self.target_column_suggestions.len() {
|
||||
self.selected_target_column_suggestion_index = Some(0);
|
||||
}
|
||||
} else {
|
||||
self.selected_target_column_suggestion_index = Some(0);
|
||||
}
|
||||
} else {
|
||||
self.selected_target_column_suggestion_index = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates script editor suggestions based on current filter text
|
||||
pub fn update_script_editor_suggestions(&mut self) {
|
||||
let mut suggestions = vec!["sql".to_string()];
|
||||
|
||||
if self.selected_table_name.is_some() {
|
||||
suggestions.extend(self.table_columns_for_suggestions.clone());
|
||||
}
|
||||
|
||||
let current_selected_table_name = self.selected_table_name.as_deref();
|
||||
suggestions.extend(
|
||||
self.same_profile_table_names
|
||||
.iter()
|
||||
.filter(|tn| Some(tn.as_str()) != current_selected_table_name)
|
||||
.cloned()
|
||||
);
|
||||
|
||||
if self.script_editor_filter_text.is_empty() {
|
||||
self.script_editor_suggestions = suggestions;
|
||||
} else {
|
||||
let filter_lower = self.script_editor_filter_text.to_lowercase();
|
||||
self.script_editor_suggestions = suggestions
|
||||
.into_iter()
|
||||
.filter(|suggestion| suggestion.to_lowercase().contains(&filter_lower))
|
||||
.collect();
|
||||
}
|
||||
|
||||
// Update selection index
|
||||
if self.script_editor_suggestions.is_empty() {
|
||||
self.script_editor_selected_suggestion_index = None;
|
||||
self.script_editor_autocomplete_active = false;
|
||||
} else if let Some(selected_idx) = self.script_editor_selected_suggestion_index {
|
||||
if selected_idx >= self.script_editor_suggestions.len() {
|
||||
self.script_editor_selected_suggestion_index = Some(0);
|
||||
}
|
||||
} else {
|
||||
self.script_editor_selected_suggestion_index = Some(0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if a suggestion is a table name (for triggering column autocomplete)
|
||||
pub fn is_table_name_suggestion(&self, suggestion: &str) -> bool {
|
||||
// Not "sql"
|
||||
if suggestion == "sql" {
|
||||
return false;
|
||||
}
|
||||
if self.table_columns_for_suggestions.contains(&suggestion.to_string()) {
|
||||
return false;
|
||||
}
|
||||
self.same_profile_table_names.contains(&suggestion.to_string())
|
||||
}
|
||||
|
||||
/// Sets table columns for autocomplete suggestions
|
||||
pub fn set_table_columns(&mut self, columns: Vec<String>) {
|
||||
self.table_columns_for_suggestions = columns.clone();
|
||||
if !columns.is_empty() {
|
||||
self.update_target_column_suggestions();
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets all available table names for autocomplete suggestions
|
||||
pub fn set_all_table_names(&mut self, table_names: Vec<String>) {
|
||||
self.all_table_names = table_names;
|
||||
}
|
||||
|
||||
/// Sets table names from the same profile for autocomplete suggestions
|
||||
pub fn set_same_profile_table_names(&mut self, table_names: Vec<String>) {
|
||||
self.same_profile_table_names = table_names;
|
||||
}
|
||||
|
||||
/// Triggers waiting for column autocomplete for a specific table
|
||||
pub fn trigger_column_autocomplete_for_table(&mut self, table_name: String) {
|
||||
self.script_editor_awaiting_column_autocomplete = Some(table_name);
|
||||
}
|
||||
|
||||
/// Updates autocomplete with columns for a specific table
|
||||
pub fn set_columns_for_table_autocomplete(&mut self, columns: Vec<String>) {
|
||||
self.script_editor_suggestions = columns;
|
||||
self.script_editor_selected_suggestion_index = if self.script_editor_suggestions.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(0)
|
||||
};
|
||||
self.script_editor_autocomplete_active = !self.script_editor_suggestions.is_empty();
|
||||
self.script_editor_awaiting_column_autocomplete = None;
|
||||
}
|
||||
|
||||
/// Deactivates script editor autocomplete and clears related state
|
||||
pub fn deactivate_script_editor_autocomplete(&mut self) {
|
||||
self.script_editor_autocomplete_active = false;
|
||||
self.script_editor_suggestions.clear();
|
||||
self.script_editor_selected_suggestion_index = None;
|
||||
self.script_editor_trigger_position = None;
|
||||
self.script_editor_filter_text.clear();
|
||||
}
|
||||
|
||||
/// Helper method to validate and save logic
|
||||
pub fn save_logic(&mut self) -> Option<String> {
|
||||
if self.logic_name_input.trim().is_empty() {
|
||||
return Some("Logic name is required".to_string());
|
||||
}
|
||||
|
||||
if self.target_column_input.trim().is_empty() {
|
||||
return Some("Target column is required".to_string());
|
||||
}
|
||||
|
||||
let script_content = {
|
||||
let editor_borrow = self.script_content_editor.borrow();
|
||||
editor_borrow.lines().join("\n")
|
||||
};
|
||||
|
||||
if script_content.trim().is_empty() {
|
||||
return Some("Script content is required".to_string());
|
||||
}
|
||||
|
||||
// Here you would typically save to database/storage
|
||||
// For now, just clear the form and mark as saved
|
||||
self.has_unsaved_changes = false;
|
||||
Some(format!("Logic '{}' saved successfully", self.logic_name_input.trim()))
|
||||
}
|
||||
|
||||
/// Helper method to clear the form
|
||||
pub fn clear_form(&mut self) -> Option<String> {
|
||||
let profile = self.profile_name.clone();
|
||||
let table_id = self.selected_table_id;
|
||||
let table_name = self.selected_table_name.clone();
|
||||
let editor_config = EditorConfig::default(); // You might want to preserve the actual config
|
||||
|
||||
*self = Self::new(&editor_config);
|
||||
self.profile_name = profile;
|
||||
self.selected_table_id = table_id;
|
||||
self.selected_table_name = table_name;
|
||||
|
||||
Some("Form cleared".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AddLogicState {
|
||||
fn default() -> Self {
|
||||
let mut state = Self::new(&EditorConfig::default());
|
||||
state.app_mode = canvas::AppMode::Edit;
|
||||
state
|
||||
}
|
||||
}
|
||||
|
||||
impl DataProvider for AddLogicState {
|
||||
fn field_count(&self) -> usize {
|
||||
3 // Logic Name, Target Column, Description
|
||||
}
|
||||
|
||||
fn field_name(&self, index: usize) -> &str {
|
||||
match index {
|
||||
0 => "Logic Name",
|
||||
1 => "Target Column",
|
||||
2 => "Description",
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
|
||||
fn field_value(&self, index: usize) -> &str {
|
||||
match index {
|
||||
0 => &self.logic_name_input,
|
||||
1 => &self.target_column_input,
|
||||
2 => &self.description_input,
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
|
||||
fn set_field_value(&mut self, index: usize, value: String) {
|
||||
match index {
|
||||
0 => self.logic_name_input = value,
|
||||
1 => self.target_column_input = value,
|
||||
2 => self.description_input = value,
|
||||
_ => {}
|
||||
}
|
||||
self.has_unsaved_changes = true;
|
||||
}
|
||||
|
||||
fn supports_suggestions(&self, field_index: usize) -> bool {
|
||||
// Only Target Column supports suggestions
|
||||
field_index == 1
|
||||
}
|
||||
}
|
||||
303
client/src/pages/admin_panel/add_logic/ui.rs
Normal file
303
client/src/pages/admin_panel/add_logic/ui.rs
Normal file
@@ -0,0 +1,303 @@
|
||||
// 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 canvas::{render_canvas, FormEditor};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use crate::components::common::autocomplete;
|
||||
use crate::dialog;
|
||||
use crate::config::binds::config::EditorKeybindingMode;
|
||||
|
||||
pub fn render_add_logic(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
app_state: &AppState,
|
||||
add_logic_state: &mut AddLogicState,
|
||||
) {
|
||||
let main_block = Block::default()
|
||||
.title(" Add New Logic Script ")
|
||||
.title_alignment(Alignment::Center)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(theme.border))
|
||||
.style(Style::default().bg(theme.bg));
|
||||
let inner_area = main_block.inner(area);
|
||||
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) {
|
||||
theme.highlight
|
||||
} else {
|
||||
theme.secondary
|
||||
};
|
||||
let border_style = Style::default().fg(border_style_color);
|
||||
|
||||
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 {
|
||||
EditorKeybindingMode::Vim => {
|
||||
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) {
|
||||
"Script (Editing)".to_string()
|
||||
} else {
|
||||
"Script".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
editor_ref.set_block(
|
||||
Block::default()
|
||||
.title(Span::styled(script_title_hint, Style::default().fg(theme.fg)))
|
||||
.title_alignment(Alignment::Center)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(border_style),
|
||||
);
|
||||
f.render_widget(&*editor_ref, inner_area);
|
||||
|
||||
// Drop the editor borrow before accessing autocomplete state
|
||||
drop(editor_ref);
|
||||
|
||||
// === SCRIPT EDITOR AUTOCOMPLETE RENDERING ===
|
||||
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();
|
||||
editor_borrow.cursor() // Returns (row, col) as (usize, usize)
|
||||
};
|
||||
|
||||
let (cursor_line, cursor_col) = current_cursor;
|
||||
|
||||
// Account for TextArea's block borders (1 for each side)
|
||||
let block_offset_x = 1;
|
||||
let block_offset_y = 1;
|
||||
|
||||
// Position autocomplete at current cursor position
|
||||
// Add 1 to column to position dropdown right after the cursor
|
||||
let autocomplete_x = cursor_col + 1;
|
||||
let autocomplete_y = cursor_line;
|
||||
|
||||
let input_rect = Rect {
|
||||
x: (inner_area.x + block_offset_x + autocomplete_x as u16).min(inner_area.right().saturating_sub(20)),
|
||||
y: (inner_area.y + block_offset_y + autocomplete_y as u16).min(inner_area.bottom().saturating_sub(5)),
|
||||
width: 1, // Minimum width for positioning
|
||||
height: 1,
|
||||
};
|
||||
|
||||
// Render autocomplete dropdown
|
||||
autocomplete::render_autocomplete_dropdown(
|
||||
f,
|
||||
input_rect,
|
||||
f.area(), // Full frame area for clamping
|
||||
theme,
|
||||
&add_logic_state.script_editor_suggestions,
|
||||
add_logic_state.script_editor_selected_suggestion_index,
|
||||
);
|
||||
}
|
||||
|
||||
return; // Exit early for fullscreen mode
|
||||
}
|
||||
|
||||
// Regular layout with preview
|
||||
let main_chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(3), // Top info
|
||||
Constraint::Length(9), // Canvas for 3 inputs (each 1 line + 1 padding = 2 lines * 3 + 2 border = 8, +1 for good measure)
|
||||
Constraint::Min(5), // Script preview
|
||||
Constraint::Length(3), // Buttons
|
||||
])
|
||||
.split(inner_area);
|
||||
|
||||
let top_info_area = main_chunks[0];
|
||||
let canvas_area = main_chunks[1];
|
||||
let script_content_area = main_chunks[2];
|
||||
let buttons_area = main_chunks[3];
|
||||
|
||||
// Top info
|
||||
let profile_text = Paragraph::new(vec![
|
||||
Line::from(Span::styled(
|
||||
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),
|
||||
)),
|
||||
])
|
||||
.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,
|
||||
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);
|
||||
|
||||
// --- 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 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Script content preview
|
||||
{
|
||||
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;
|
||||
|
||||
if is_script_preview_focused {
|
||||
editor_ref.set_cursor_style(Style::default().add_modifier(Modifier::REVERSED));
|
||||
} else {
|
||||
let underscore_cursor_style = Style::default()
|
||||
.add_modifier(Modifier::UNDERLINED)
|
||||
.fg(theme.secondary);
|
||||
editor_ref.set_cursor_style(underscore_cursor_style);
|
||||
}
|
||||
|
||||
let border_style_color = if is_script_preview_focused {
|
||||
theme.highlight
|
||||
} else {
|
||||
theme.secondary
|
||||
};
|
||||
|
||||
let title_text = "Script Preview"; // Title doesn't need to change based on focus here
|
||||
|
||||
let title_style = if is_script_preview_focused {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.fg)
|
||||
};
|
||||
|
||||
editor_ref.set_block(
|
||||
Block::default()
|
||||
.title(Span::styled(title_text, title_style))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(border_style_color)),
|
||||
);
|
||||
f.render_widget(&*editor_ref, script_content_area);
|
||||
}
|
||||
|
||||
// Buttons
|
||||
let get_button_style = |button_focus: AddLogicFocus, current_focus_state: AddLogicFocus| {
|
||||
let is_focused = current_focus_state == button_focus;
|
||||
let base_style = Style::default().fg(if is_focused {
|
||||
theme.highlight
|
||||
} else {
|
||||
theme.secondary
|
||||
});
|
||||
if is_focused {
|
||||
base_style.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
base_style
|
||||
}
|
||||
};
|
||||
|
||||
let get_button_border_style = |is_focused: bool, current_theme: &Theme| {
|
||||
if is_focused {
|
||||
Style::default().fg(current_theme.highlight)
|
||||
} else {
|
||||
Style::default().fg(current_theme.secondary)
|
||||
}
|
||||
};
|
||||
|
||||
let button_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([
|
||||
Constraint::Percentage(50),
|
||||
Constraint::Percentage(50),
|
||||
])
|
||||
.split(buttons_area);
|
||||
|
||||
let save_button = Paragraph::new(" Save Logic ")
|
||||
.style(get_button_style(
|
||||
AddLogicFocus::SaveButton,
|
||||
add_logic_state.current_focus,
|
||||
))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(
|
||||
add_logic_state.current_focus == AddLogicFocus::SaveButton,
|
||||
theme,
|
||||
)),
|
||||
);
|
||||
f.render_widget(save_button, button_chunks[0]);
|
||||
|
||||
let cancel_button = Paragraph::new(" Cancel ")
|
||||
.style(get_button_style(
|
||||
AddLogicFocus::CancelButton,
|
||||
add_logic_state.current_focus,
|
||||
))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(
|
||||
add_logic_state.current_focus == AddLogicFocus::CancelButton,
|
||||
theme,
|
||||
)),
|
||||
);
|
||||
f.render_widget(cancel_button, button_chunks[1]);
|
||||
|
||||
// Dialog
|
||||
if app_state.ui.dialog.dialog_show {
|
||||
dialog::render_dialog(
|
||||
f,
|
||||
f.area(),
|
||||
theme,
|
||||
&app_state.ui.dialog.dialog_title,
|
||||
&app_state.ui.dialog.dialog_message,
|
||||
&app_state.ui.dialog.dialog_buttons,
|
||||
app_state.ui.dialog.dialog_active_button_index,
|
||||
app_state.ui.dialog.is_loading,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// src/pages/admin_panel/mod.rs
|
||||
|
||||
pub mod add_table;
|
||||
pub mod add_logic;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// src/pages/routing/router.rs
|
||||
use crate::state::pages::{
|
||||
auth::AuthState,
|
||||
add_logic::AddLogicState,
|
||||
};
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::pages::admin_panel::add_logic::state::AddLogicState;
|
||||
use crate::pages::admin_panel::add_table::state::AddTableState;
|
||||
use crate::pages::admin::AdminState;
|
||||
use crate::pages::forms::FormState;
|
||||
|
||||
Reference in New Issue
Block a user