Prefer .map for conditionals with else conditions (#15118)

This PR updates instances where we were using `.when_else` and
`.when_else_some` to use `.map` with a conditional inside.

This allows us to avoid reinventing Rust's syntax for conditionals and
(IMO) makes the code easier to read.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-24 17:09:07 -04:00 committed by GitHub
parent 596ee58be8
commit 298ca5ff1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 55 additions and 93 deletions

View file

@ -83,37 +83,34 @@ impl QuickActionBar {
let status = menu_state.status;
let editor = editor.clone();
menu.when_else(
status.is_connected(),
|running| {
menu.map(|menu| {
if status.is_connected() {
let status = status.clone();
running
.custom_row(move |_cx| {
h_flex()
.child(
Label::new(format!(
"kernel: {} ({})",
menu_state.kernel_name.clone(),
menu_state.kernel_language.clone()
))
menu.custom_row(move |_cx| {
h_flex()
.child(
Label::new(format!(
"kernel: {} ({})",
menu_state.kernel_name.clone(),
menu_state.kernel_language.clone()
))
.size(LabelSize::Small)
.color(Color::Muted),
)
.into_any_element()
})
.custom_row(move |_cx| {
h_flex()
.child(
Label::new(status.clone().to_string())
.size(LabelSize::Small)
.color(Color::Muted),
)
.into_any_element()
})
.custom_row(move |_cx| {
h_flex()
.child(
Label::new(status.clone().to_string())
.size(LabelSize::Small)
.color(Color::Muted),
)
.into_any_element()
})
},
|not_running| {
)
.into_any_element()
})
} else {
let status = status.clone();
not_running.custom_row(move |_cx| {
menu.custom_row(move |_cx| {
h_flex()
.child(
Label::new(format!("{}...", status.clone().to_string()))
@ -122,8 +119,8 @@ impl QuickActionBar {
)
.into_any_element()
})
},
)
}
})
.separator()
.custom_entry(
move |_cx| {