Skip to content

Commit

Permalink
Cherry-pick on main
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
sunshowers committed Oct 26, 2023
2 parents 32b595b + c862ad3 commit 4f28d8f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 62 deletions.
32 changes: 12 additions & 20 deletions wicket/src/state/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use anyhow::anyhow;
use once_cell::sync::Lazy;
use ratatui::text::Text;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fmt::Display;
Expand Down Expand Up @@ -184,7 +185,7 @@ impl Component {
}
}

/// The component type and its slot.
// The component type and its slot.
#[derive(
Debug,
Clone,
Expand All @@ -204,24 +205,27 @@ pub enum ComponentId {
}

impl ComponentId {
pub fn to_string_uppercase(&self) -> String {
let mut s = self.to_string();
s.make_ascii_uppercase();
s
pub fn name(&self) -> String {
self.to_string()
}
}

/// Prints the component type in standard case.
impl Display for ComponentId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ComponentId::Sled(i) => write!(f, "sled {}", i),
ComponentId::Switch(i) => write!(f, "switch {}", i),
ComponentId::Sled(i) => write!(f, "SLED {}", i),
ComponentId::Switch(i) => write!(f, "SWITCH {}", i),
ComponentId::Psc(i) => write!(f, "PSC {}", i),
}
}
}

impl From<ComponentId> for Text<'_> {
fn from(value: ComponentId) -> Self {
value.to_string().into()
}
}

pub struct ParsableComponentId<'a> {
pub sp_type: &'a str,
pub i: &'a str,
Expand Down Expand Up @@ -265,15 +269,3 @@ impl PowerState {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn component_id_display() {
assert_eq!(ComponentId::Sled(0).to_string(), "sled 0");
assert_eq!(ComponentId::Switch(1).to_string(), "switch 1");
assert_eq!(ComponentId::Psc(2).to_string(), "PSC 2");
}
}
2 changes: 1 addition & 1 deletion wicket/src/ui/panes/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl Control for InventoryView {
let title_bar = Paragraph::new(Line::from(vec![
Span::styled("OXIDE RACK / ", border_style),
Span::styled(
state.rack_state.selected.to_string_uppercase(),
state.rack_state.selected.to_string(),
component_style,
),
]))
Expand Down
52 changes: 12 additions & 40 deletions wicket/src/ui/panes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl UpdatePane {
tree_state,
items: ALL_COMPONENT_IDS
.iter()
.map(|id| TreeItem::new(id.to_string_uppercase(), vec![]))
.map(|id| TreeItem::new(*id, vec![]))
.collect(),
help: vec![
("Expand", "<e>"),
Expand Down Expand Up @@ -531,10 +531,7 @@ impl UpdatePane {
) {
let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"START UPDATE: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("START UPDATE: {}", state.rack_state.selected),
style::header(true),
)]),
body: Text::from(vec![Line::from(vec![Span::styled(
Expand Down Expand Up @@ -564,10 +561,7 @@ impl UpdatePane {
) {
let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"START UPDATE: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("START UPDATE: {}", state.rack_state.selected),
style::header(true),
)]),
body: Text::from(vec![Line::from(vec![Span::styled(
Expand Down Expand Up @@ -600,10 +594,7 @@ impl UpdatePane {

let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"START UPDATE FAILED: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("START UPDATE FAILED: {}", state.rack_state.selected),
style::failed_update(),
)]),
body,
Expand Down Expand Up @@ -644,10 +635,7 @@ impl UpdatePane {

let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"ABORT UPDATE: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("ABORT UPDATE: {}", state.rack_state.selected),
style::header(true),
)]),
body,
Expand All @@ -674,10 +662,7 @@ impl UpdatePane {
) {
let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"ABORT UPDATE: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("ABORT UPDATE: {}", state.rack_state.selected),
style::header(true),
)]),
body: Text::from(vec![Line::from(vec![Span::styled(
Expand Down Expand Up @@ -710,10 +695,7 @@ impl UpdatePane {

let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"ABORT UPDATE FAILED: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("ABORT UPDATE FAILED: {}", state.rack_state.selected),
style::failed_update(),
)]),
body,
Expand All @@ -739,10 +721,7 @@ impl UpdatePane {
) {
let popup_builder = PopupBuilder {
header: Line::from(vec![Span::styled(
format!(
"CLEAR UPDATE STATE: {}",
state.rack_state.selected.to_string_uppercase()
),
format!("CLEAR UPDATE STATE: {}", state.rack_state.selected),
style::header(true),
)]),
body: Text::from(vec![Line::from(vec![Span::styled(
Expand Down Expand Up @@ -777,7 +756,7 @@ impl UpdatePane {
header: Line::from(vec![Span::styled(
format!(
"CLEAR UPDATE STATE FAILED: {}",
state.rack_state.selected.to_string_uppercase()
state.rack_state.selected
),
style::failed_update(),
)]),
Expand Down Expand Up @@ -851,7 +830,7 @@ impl UpdatePane {
})
})
.collect();
TreeItem::new(id.to_string_uppercase(), children)
TreeItem::new(*id, children)
})
.collect();
}
Expand Down Expand Up @@ -1128,11 +1107,7 @@ impl UpdatePane {
// `overview` pane.
let command = self.ignition.selected_command();
let selected = state.rack_state.selected;
info!(
self.log,
"Sending {command:?} to {}",
selected.to_string_uppercase()
);
info!(self.log, "Sending {command:?} to {selected}");
self.popup = None;
Some(Action::Ignition(selected, command))
}
Expand Down Expand Up @@ -1403,10 +1378,7 @@ impl UpdatePane {
// Draw the title/tab bar
let title_bar = Paragraph::new(Line::from(vec![
Span::styled("UPDATE STATUS / ", border_style),
Span::styled(
state.rack_state.selected.to_string_uppercase(),
header_style,
),
Span::styled(state.rack_state.selected.to_string(), header_style),
]))
.block(block.clone());
frame.render_widget(title_bar, self.title_rect);
Expand Down
2 changes: 1 addition & 1 deletion wicket/src/ui/widgets/ignition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl IgnitionPopup {
) -> PopupBuilder<'static> {
PopupBuilder {
header: Line::from(vec![Span::styled(
format!("IGNITION: {}", component.to_string_uppercase()),
format!("IGNITION: {}", component),
style::header(true),
)]),
body: Text {
Expand Down

0 comments on commit 4f28d8f

Please sign in to comment.