Skip to content

Commit

Permalink
Update lea for better user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
voelkera committed Feb 7, 2024
1 parent 6390646 commit cafa8a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions opendut-lea/src/peers/configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub fn PeerConfigurator() -> impl IntoView {
is_collapsed: true
})
}).collect::<Vec<_>>();
user_configuration.network_interfaces = configuration.network_configuration.interfaces.into_iter()
.map(|interface| interface.name)
.collect();
});
}
}
Expand Down
1 change: 1 addition & 0 deletions opendut-lea/src/peers/configurator/tabs/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn NetworkTab(peer_configuration: RwSignal<UserPeerConfiguration>) -> impl I

view! {
<NetworkInterfaceNameInput
interface_names = interface_names_getter
on_action = move |name| {
let mut interface_names = interface_names_getter.get_untracked();
interface_names.push(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ use crate::components::{ButtonColor, ButtonSize, ButtonState, FontAwesomeIcon, I

#[component]
pub fn NetworkInterfaceNameInput<A>(
interface_names: Signal<Vec<NetworkInterfaceName>>,
on_action: A
) -> impl IntoView
where A: Fn(NetworkInterfaceName) + 'static {

let (getter, setter) = create_signal(UserInputValue::Left(String::from("The network interface name must not be empty.")));

let validator = |input: String| {
let validator = move |input: String| {
match NetworkInterfaceName::try_from(input) {
Ok(name) => {
UserInputValue::Right(name.name())
if interface_names.get_untracked().contains(&name) {
UserInputValue::Both(format!("A network interface with that name has already been configured."), name.name())
} else {
UserInputValue::Right(name.name())
}

}
Err(cause) => {
match cause {
Expand All @@ -30,6 +36,14 @@ where A: Fn(NetworkInterfaceName) + 'static {
}
};

let button_state = MaybeSignal::derive(move || {
if getter.get().is_left() || getter.get().is_both() {
ButtonState::Disabled
} else {
ButtonState::Enabled
}
});

view! {
<div class="is-flex is-align-items-center">
<UserInput
Expand All @@ -44,7 +58,7 @@ where A: Fn(NetworkInterfaceName) + 'static {
icon = FontAwesomeIcon::Plus
color = ButtonColor::Success
size = ButtonSize::Normal
state = ButtonState::Enabled
state = button_state
label = "Add network interface"
on_action = move || {
if let UserInputValue::Right(value) = getter.get_untracked() {
Expand Down
2 changes: 1 addition & 1 deletion opendut-types/src/util/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ pub enum NetworkInterfaceNameError {
#[error("Name for network interface may not be empty!")]
Empty,
#[error("Due to operating system limitations, the name for network interfaces may not be longer than {max} characters!")]
TooLong { value: String, max: usize }
TooLong { value: String, max: usize },
}

0 comments on commit cafa8a7

Please sign in to comment.