Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(launchpad): node actions #2444

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions node-launchpad/.config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"<h>": {"SwitchScene":"Help"},
"<H>": {"SwitchScene":"Help"},

"<Ctrl-s>": {"StatusActions":"StartNodes"},
"<Ctrl-S>": {"StatusActions":"StartNodes"},
"<Ctrl-s>": {"StatusActions":"StartStopNode"},
"<Ctrl-S>": {"StatusActions":"StartStopNode"},
"<Ctrl-Shift-s>": {"StatusActions":"StartNodes"},
"<Ctrl-x>": {"StatusActions":"StopNodes"},
"<Ctrl-X>": {"StatusActions":"StopNodes"},
Expand All @@ -19,6 +19,8 @@
"<Ctrl-Shift-b>": {"StatusActions":"TriggerRewardsAddress"},
"<l>": {"StatusActions":"TriggerNodeLogs"},
"<L>": {"StatusActions":"TriggerNodeLogs"},
"<+>": {"StatusActions":"AddNode"},
"<->": {"StatusActions":"TriggerRemoveNode"},

"up" : {"StatusActions":"PreviousTableItem"},
"down": {"StatusActions":"NextTableItem"},
Expand Down
58 changes: 49 additions & 9 deletions node-launchpad/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,65 @@ pub enum Action {

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Display, Deserialize)]
pub enum StatusActions {
AddNode,
StartNodes,
StopNodes,
StartNodesCompleted,
StopNodesCompleted,
ResetNodesCompleted { trigger_start_node: bool },
RemoveNodes,
StartStopNode,
StartNodesCompleted {
service_name: String,
},
StopNodesCompleted {
service_name: String,
},
ResetNodesCompleted {
trigger_start_node: bool,
},
RemoveNodesCompleted {
service_name: String,
},
AddNodesCompleted {
service_name: String,
},
UpdateNodesCompleted,
SuccessfullyDetectedNatStatus,
ErrorWhileRunningNatDetection,
ErrorLoadingNodeRegistry { raw_error: String },
ErrorGettingNodeRegistryPath { raw_error: String },
ErrorScalingUpNodes { raw_error: String },
ErrorStoppingNodes { raw_error: String },
ErrorResettingNodes { raw_error: String },
ErrorUpdatingNodes { raw_error: String },
ErrorLoadingNodeRegistry {
raw_error: String,
},
ErrorGettingNodeRegistryPath {
raw_error: String,
},
ErrorScalingUpNodes {
raw_error: String,
},
ErrorResettingNodes {
raw_error: String,
},
ErrorUpdatingNodes {
raw_error: String,
},
ErrorAddingNodes {
raw_error: String,
},
ErrorStartingNodes {
services: Vec<String>,
raw_error: String,
},
ErrorStoppingNodes {
services: Vec<String>,
raw_error: String,
},
ErrorRemovingNodes {
services: Vec<String>,
raw_error: String,
},
NodesStatsObtained(NodeStats),

TriggerManageNodes,
TriggerRewardsAddress,
TriggerNodeLogs,
TriggerRemoveNode,

PreviousTableItem,
NextTableItem,
Expand Down
10 changes: 7 additions & 3 deletions node-launchpad/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use crate::{
options::Options,
popup::{
change_drive::ChangeDrivePopup, connection_mode::ChangeConnectionModePopUp,
manage_nodes::ManageNodes, port_range::PortRangePopUp, reset_nodes::ResetNodesPopup,
rewards_address::RewardsAddress, upgrade_nodes::UpgradeNodesPopUp,
manage_nodes::ManageNodes, port_range::PortRangePopUp, remove_node::RemoveNodePopUp,
reset_nodes::ResetNodesPopup, rewards_address::RewardsAddress,
upgrade_nodes::UpgradeNodesPopUp,
},
status::{Status, StatusConfig},
Component,
Expand Down Expand Up @@ -98,6 +99,7 @@ impl App {
connection_mode,
port_from: Some(port_from),
port_to: Some(port_to),
storage_mountpoint: storage_mountpoint.clone(),
};

let status = Status::new(status_config).await?;
Expand All @@ -120,7 +122,8 @@ impl App {
let change_connection_mode = ChangeConnectionModePopUp::new(connection_mode)?;
let port_range = PortRangePopUp::new(connection_mode, port_from, port_to);
let rewards_address = RewardsAddress::new(app_data.discord_username.clone());
let upgrade_nodes = UpgradeNodesPopUp::new(app_data.nodes_to_start);
let upgrade_nodes = UpgradeNodesPopUp::new();
let remove_node = RemoveNodePopUp::default();

Ok(Self {
config,
Expand Down Expand Up @@ -148,6 +151,7 @@ impl App {
Box::new(reset_nodes),
Box::new(manage_nodes),
Box::new(upgrade_nodes),
Box::new(remove_node),
],
should_quit: false,
should_suspend: false,
Expand Down
124 changes: 87 additions & 37 deletions node-launchpad/src/components/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::style::{COOL_GREY, EUCALYPTUS, GHOST_WHITE, LIGHT_PERIWINKLE};
use ratatui::{prelude::*, widgets::*};

pub enum NodesToStart {
Configured,
NotConfigured,
Running,
NotRunning,
RunningSelected,
NotRunningSelected,
}

#[derive(Default)]
Expand All @@ -22,50 +23,99 @@ impl StatefulWidget for Footer {
type State = NodesToStart;

fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
let (text_style, command_style) = if matches!(state, NodesToStart::Configured) {
(
Style::default().fg(EUCALYPTUS),
Style::default().fg(GHOST_WHITE),
)
} else {
(
Style::default().fg(COOL_GREY),
Style::default().fg(LIGHT_PERIWINKLE),
)
};
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints(vec![Constraint::Length(3)])
.split(area);

let command_enabled = Style::default().fg(GHOST_WHITE);
let text_enabled = Style::default().fg(EUCALYPTUS);
let command_disabled = Style::default().fg(LIGHT_PERIWINKLE);
let text_disabled = Style::default().fg(COOL_GREY);

let mut remove_command_style = command_disabled;
let mut remove_text_style = text_disabled;
let mut start_stop_command_style = command_disabled;
let mut start_stop_text_style = text_disabled;
let mut open_logs_command_style = command_disabled;
let mut open_logs_text_style = text_disabled;
let mut stop_all_command_style = command_disabled;
let mut stop_all_text_style = text_disabled;

match state {
NodesToStart::Running => {
stop_all_command_style = command_enabled;
stop_all_text_style = text_enabled;
}
NodesToStart::RunningSelected => {
remove_command_style = command_enabled;
remove_text_style = text_enabled;
start_stop_command_style = command_enabled;
start_stop_text_style = text_enabled;
open_logs_command_style = command_enabled;
open_logs_text_style = text_enabled;
stop_all_command_style = command_enabled;
stop_all_text_style = text_enabled;
}
NodesToStart::NotRunning => {}
NodesToStart::NotRunningSelected => {
remove_command_style = command_enabled;
remove_text_style = text_enabled;
start_stop_command_style = command_enabled;
start_stop_text_style = text_enabled;
open_logs_command_style = command_enabled;
open_logs_text_style = text_enabled;
}
}

let commands = vec![
Span::styled("[Ctrl+G] ", Style::default().fg(GHOST_WHITE)),
Span::styled("Manage Nodes", Style::default().fg(EUCALYPTUS)),
Span::styled("[+] ", command_enabled),
Span::styled("Add", text_enabled),
Span::styled(" ", Style::default()),
Span::styled("[Ctrl+S] ", command_style),
Span::styled("Start Nodes", text_style),
Span::styled("[-] ", remove_command_style),
Span::styled("Remove", remove_text_style),
Span::styled(" ", Style::default()),
Span::styled("[L] ", command_style),
Span::styled("Open Logs", Style::default().fg(EUCALYPTUS)),
Span::styled("[Ctrl+S] ", start_stop_command_style),
Span::styled("Start/Stop Node", start_stop_text_style),
Span::styled(" ", Style::default()),
Span::styled("[Ctrl+X] ", command_style),
Span::styled(
"Stop All",
if matches!(state, NodesToStart::Running) {
Style::default().fg(EUCALYPTUS)
} else {
Style::default().fg(COOL_GREY)
},
),
Span::styled("[L] ", open_logs_command_style),
Span::styled("Open Logs", open_logs_text_style),
];

let stop_all = vec![
Span::styled("[Ctrl+X] ", stop_all_command_style),
Span::styled("Stop All", stop_all_text_style),
];

let total_width = (layout[0].width - 1) as usize;
let spaces = " ".repeat(total_width.saturating_sub(
commands.iter().map(|s| s.width()).sum::<usize>()
+ stop_all.iter().map(|s| s.width()).sum::<usize>(),
));

let commands_length = 6 + commands.iter().map(|s| s.width()).sum::<usize>() as u16;
let spaces_length = spaces.len().saturating_sub(6) as u16;
let stop_all_length = stop_all.iter().map(|s| s.width()).sum::<usize>() as u16;

let cell1 = Cell::from(Line::from(commands));
let row = Row::new(vec![cell1]);
let cell2 = Cell::from(Line::raw(spaces));
let cell3 = Cell::from(Line::from(stop_all));
let row = Row::new(vec![cell1, cell2, cell3]);

let table = Table::new(vec![row], vec![Constraint::Max(1)])
.block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(EUCALYPTUS))
.padding(Padding::horizontal(1)),
)
.widths(vec![Constraint::Fill(1)]);
let table = Table::new(
[row],
[
Constraint::Length(commands_length),
Constraint::Length(spaces_length),
Constraint::Length(stop_all_length),
],
)
.block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(EUCALYPTUS))
.padding(Padding::horizontal(1)),
);

StatefulWidget::render(table, area, buf, &mut TableState::default());
}
Expand Down
4 changes: 1 addition & 3 deletions node-launchpad/src/components/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Component for Options {
.constraints(
[
Constraint::Length(1),
Constraint::Length(7),
Constraint::Length(5),
Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(4),
Expand All @@ -93,7 +93,6 @@ impl Component for Options {
.border_style(Style::default().fg(VERY_LIGHT_AZURE));
let storage_drivename = Table::new(
vec![
Row::new(vec![Line::from(vec![])]),
Row::new(vec![
Cell::from(
Line::from(vec![Span::styled(
Expand Down Expand Up @@ -177,7 +176,6 @@ impl Component for Options {
.alignment(Alignment::Right),
),
]),
Row::new(vec![Line::from(vec![])]),
],
&[
Constraint::Length(18),
Expand Down
1 change: 1 addition & 0 deletions node-launchpad/src/components/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod change_drive;
pub mod connection_mode;
pub mod manage_nodes;
pub mod port_range;
pub mod remove_node;
pub mod reset_nodes;
pub mod rewards_address;
pub mod upgrade_nodes;
6 changes: 5 additions & 1 deletion node-launchpad/src/components/popup/manage_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ impl Component for ManageNodes {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
let send_back = match action {
Action::SwitchScene(scene) => match scene {
Scene::ManageNodesPopUp => {
Scene::ManageNodesPopUp { amount_of_nodes } => {
self.nodes_to_start_input = self
.nodes_to_start_input
.clone()
.with_value(amount_of_nodes.to_string());
self.active = true;
self.old_value = self.nodes_to_start_input.value().to_string();
// set to entry input mode as we want to handle everything within our handle_key_events
Expand Down
Loading
Loading