ssh: Use system prompt for the server removal action (#19332)

This PR replaces a toast for the system prompt to confirm the action of
removing a server from the remote list. The alert dialog component is
the right choice here as we want to have a modal action that forces
choice. This should make it easier to convert to a nativa alert dialog
in the future, as well as for other platforms.

<img width="800" alt="Screenshot 2024-10-17 at 3 01 41 AM"
src="https://github.com/user-attachments/assets/7bb1210a-54bf-40da-a85a-f269484825a1">

Release Notes:

- N/A
This commit is contained in:
Danilo Leal 2024-10-17 03:25:03 +02:00 committed by GitHub
parent c888101e4b
commit 9a3d8733ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,7 +20,7 @@ use gpui::Task;
use gpui::WeakView; use gpui::WeakView;
use gpui::{ use gpui::{
Animation, AnimationExt, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, Animation, AnimationExt, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
FocusableView, FontWeight, Model, ScrollHandle, View, ViewContext, FocusableView, FontWeight, Model, PromptLevel, ScrollHandle, View, ViewContext,
}; };
use picker::Picker; use picker::Picker;
use project::terminals::wrap_for_ssh; use project::terminals::wrap_for_ssh;
@ -986,46 +986,38 @@ impl DevServerProjects {
.child({ .child({
fn remove_ssh_server( fn remove_ssh_server(
dev_servers: View<DevServerProjects>, dev_servers: View<DevServerProjects>,
workspace: WeakView<Workspace>,
index: usize, index: usize,
connection_string: SharedString, connection_string: SharedString,
cx: &mut WindowContext<'_>, cx: &mut WindowContext<'_>,
) { ) {
workspace let prompt_message = format!("Remove server `{}`?", connection_string);
.update(cx, |this, cx| {
struct SshServerRemoval; let confirmation = cx.prompt(
let notification = format!( PromptLevel::Warning,
"Do you really want to remove server `{}`?", &prompt_message,
connection_string None,
); &["Yes, remove it", "No, keep it"],
this.show_toast( );
Toast::new(
NotificationId::composite::<SshServerRemoval>( cx.spawn(|mut cx| async move {
connection_string.clone(), if confirmation.await.ok() == Some(0) {
), dev_servers
notification, .update(&mut cx, |this, cx| {
) this.delete_ssh_server(index, cx);
.on_click( this.mode = Mode::default_mode();
"Yes, delete it", cx.notify();
move |cx| { })
dev_servers.update(cx, |this, cx| { .ok();
this.delete_ssh_server(index, cx); }
this.mode = Mode::default_mode(); anyhow::Ok(())
cx.notify(); })
}) .detach_and_log_err(cx);
},
),
cx,
);
})
.ok();
} }
self.selectable_items.add_item(Box::new({ self.selectable_items.add_item(Box::new({
let connection_string = connection_string.clone(); let connection_string = connection_string.clone();
move |this, cx| { move |_, cx| {
remove_ssh_server( remove_ssh_server(
cx.view().clone(), cx.view().clone(),
this.workspace.clone(),
index, index,
connection_string.clone(), connection_string.clone(),
cx, cx,
@ -1033,16 +1025,15 @@ impl DevServerProjects {
} }
})); }));
let is_selected = self.selectable_items.is_selected(); let is_selected = self.selectable_items.is_selected();
ListItem::new("delete-server") ListItem::new("remove-server")
.selected(is_selected) .selected(is_selected)
.inset(true) .inset(true)
.spacing(ui::ListItemSpacing::Sparse) .spacing(ui::ListItemSpacing::Sparse)
.start_slot(Icon::new(IconName::Trash).color(Color::Error)) .start_slot(Icon::new(IconName::Trash).color(Color::Error))
.child(Label::new("Delete Server").color(Color::Error)) .child(Label::new("Remove Server").color(Color::Error))
.on_click(cx.listener(move |this, _, cx| { .on_click(cx.listener(move |_, _, cx| {
remove_ssh_server( remove_ssh_server(
cx.view().clone(), cx.view().clone(),
this.workspace.clone(),
index, index,
connection_string.clone(), connection_string.clone(),
cx, cx,