Skip to content

Commit

Permalink
Introduced NewTypes for name, description, tags
Browse files Browse the repository at this point in the history
Introduced NewTypes due to be consistent over our code base.
  • Loading branch information
mtwardawski committed Feb 1, 2024
1 parent a20d574 commit a040e82
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
20 changes: 15 additions & 5 deletions opendut-cleo/src/commands/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct DeviceTable {
#[table(title = "Description")]
description: DeviceDescription,
#[table(title = "Tags")]
tags: String,
tags: Vec<DeviceTag>,
}

pub async fn list_devices(carl: &mut CarlClient, output: ListOutputFormat) -> crate::Result<()> {
Expand Down Expand Up @@ -115,7 +115,7 @@ pub mod describe {
use uuid::Uuid;

use opendut_carl_api::carl::CarlClient;
use opendut_types::topology::{DeviceId};
use opendut_types::topology::{DeviceDescription, DeviceId};

use crate::DescribeOutputFormat;

Expand All @@ -136,8 +136,18 @@ pub mod describe {
Description: {}
Interface: {}
Tags: [{}]\
"), device.name, device.id, device.description.unwrap_or_default(), device.interface,
device.tags.iter().map(|tag| tag.value()).collect::<Vec<_>>().join(", "))
"),
device.name,
device.id,
device.description
.map(DeviceDescription::from)
.unwrap_or_default(),
device.interface,
device.tags
.iter()
.map(|tag| tag.value())
.collect::<Vec<_>>()
.join(", "))
}
DescribeOutputFormat::Json => {
serde_json::to_string(&device).unwrap()
Expand Down Expand Up @@ -234,7 +244,7 @@ impl From<DeviceDescriptor> for DeviceTable {
name: device.name,
id: device.id,
description: device.description.unwrap_or_default(),
tags: device.tags.iter().map(|tag| tag.value()).collect::<Vec<_>>().join(", "),
tags: device.tags,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ pub fn DeviceInfo(device: DeviceDescriptor, peer_id: PeerId) -> impl IntoView {
<div class="field">
<label class="label">Tags</label>
<div class="control">
<p>{device.tags.into_iter().map(|tag| tag.value()).collect()}</p>
<p>{device.tags.into_iter().map(|tag| tag.value()).collect::<Vec<_>>()}</p>
</div>
</div>
<div class="field">
<label class="label">Description</label>
<div class="control">
<p>{device.description}</p>
<p>{device.description.unwrap_or_default().to_string()}</p>
</div>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn LeaderSelector(cluster_configuration: RwSignal<UserClusterConfiguration>)
{&peer.id.to_string()}
</td>
<td>
{&peer.location.to_string()}
{&peer.location.unwrap_or_default().to_string()}
</td>
<td class="is-narrow" style="text-align: center">
<div class="control">
Expand Down
4 changes: 2 additions & 2 deletions opendut-lea/src/peers/configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ pub fn PeerConfigurator() -> impl IntoView {
user_configuration.devices = configuration.topology.devices.into_iter().map(|device| {
create_rw_signal(UserDeviceConfiguration {
id: device.id,
name: UserInputValue::Right(device.name.value()),
name: UserInputValue::Right(device.name.to_string()),
interface: UserInputValue::Right(device.interface.name()),
description: device.description.unwrap_or_default().value(),
description: device.description.unwrap_or_default().to_string(),
is_collapsed: true
})
}).collect::<Vec<_>>();
Expand Down
10 changes: 6 additions & 4 deletions opendut-lea/src/peers/configurator/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use leptos::{RwSignal, SignalGetUntracked};

use opendut_types::peer::{PeerDescriptor, PeerId, PeerLocation, PeerName};
use opendut_types::topology::{DeviceDescriptor, DeviceId, Topology};
use opendut_types::topology::{DeviceDescription, DeviceDescriptor, DeviceId, DeviceName, Topology};
use opendut_types::util::net::NetworkInterfaceName;

use crate::components::UserInputValue;
Expand Down Expand Up @@ -74,7 +74,7 @@ impl TryFrom<UserPeerConfiguration> for PeerDescriptor {
Ok(PeerDescriptor {
id: configuration.id,
name,
location,
location: Some(location),
topology: Topology::new(devices),
})
}
Expand All @@ -94,10 +94,12 @@ impl TryFrom<UserDeviceConfiguration> for DeviceDescriptor {
NetworkInterfaceName::try_from(interface_name)
.map_err(|_| DeviceMisconfigurationError::InvalidDeviceInterface)
})?;
let description = DeviceDescription::try_from(configuration.description)
.map_err(|error| error.to_string())?;
Ok(DeviceDescriptor {
id: configuration.id,
name,
description: configuration.description,
name: DeviceName::try_from(name).map_err(|error| error.to_string())?,
description: Some(description),
interface,
tags: vec![],
})
Expand Down

0 comments on commit a040e82

Please sign in to comment.