public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Shan Shaji <s.shaji@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager v4 5/6] fix #6914: ui: add remove remote dialog with optional token deletion
Date: Wed, 18 Feb 2026 17:41:33 +0100	[thread overview]
Message-ID: <20260218164135.413762-6-s.shaji@proxmox.com> (raw)
In-Reply-To: <20260218164135.413762-1-s.shaji@proxmox.com>

previously, removing a remote did not remove its token, which
prevented users from re-adding the same remote later with the same token
name. To fix this, add a new checkbox that lets users choose whether to
delete the token from remote.

Signed-off-by: Shan Shaji <s.shaji@proxmox.com>
---
 changes since v3:
 - use the `ConfirmDialog` widget to create the dialog.
 - made the token deletion as an opt-out feature. If the user wants to
   keep the token, then the checkbox needs to checked.
 - fixed clippy warnings.
 - changed the checkbox label. 
 - remove the use of `pub` keyword.
  
 ui/src/remotes/config.rs        |  38 ++++++++----
 ui/src/remotes/mod.rs           |   2 +
 ui/src/remotes/remove_remote.rs | 103 ++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+), 10 deletions(-)
 create mode 100644 ui/src/remotes/remove_remote.rs

diff --git a/ui/src/remotes/config.rs b/ui/src/remotes/config.rs
index 0737f1b..0481c78 100644
--- a/ui/src/remotes/config.rs
+++ b/ui/src/remotes/config.rs
@@ -7,6 +7,7 @@ use anyhow::Error;
 use proxmox_schema::property_string::PropertyString;
 
 use crate::remotes::edit_remote::EditRemote;
+use crate::remotes::remove_remote::RemoveRemote;
 //use pwt::widget::form::{Field, FormContext, InputType};
 
 use pdm_api_types::remotes::Remote;
@@ -17,7 +18,7 @@ use proxmox_yew_comp::percent_encoding::percent_encode_component;
 
 //use proxmox_schema::api_types::{CERT_FINGERPRINT_SHA256_SCHEMA, DNS_NAME_OR_IP_SCHEMA};
 
-use serde_json::Value;
+use serde_json::{json, Value};
 use yew::virtual_dom::{Key, VComp, VNode};
 
 use pwt::prelude::*;
@@ -32,7 +33,7 @@ use pwt::widget::{
 
 //use proxmox_yew_comp::EditWindow;
 use proxmox_yew_comp::{
-    ConfirmButton, LoadableComponent, LoadableComponentContext, LoadableComponentMaster,
+    LoadableComponent, LoadableComponentContext, LoadableComponentMaster,
     LoadableComponentScopeExt, LoadableComponentState,
 };
 
@@ -42,10 +43,13 @@ async fn load_remotes() -> Result<Vec<Remote>, Error> {
     proxmox_yew_comp::http_get("/remotes/remote", None).await
 }
 
-async fn delete_item(key: Key) -> Result<(), Error> {
+async fn delete_item(key: Key, delete_token: bool) -> Result<(), Error> {
     let id = key.to_string();
+    let param = Some(json!({
+        "delete-token": delete_token,
+    }));
     let url = format!("/remotes/remote/{}", percent_encode_component(&id));
-    proxmox_yew_comp::http_delete(&url, None).await?;
+    proxmox_yew_comp::http_delete(&url, param).await?;
     Ok(())
 }
 
@@ -100,10 +104,11 @@ impl RemoteConfigPanel {
 pub enum ViewState {
     Add(RemoteType),
     Edit,
+    Remove,
 }
 
 pub enum Msg {
-    RemoveItem,
+    RemoveItem(bool),
 }
 
 pub struct PbsRemoteConfigPanel {
@@ -156,11 +161,11 @@ impl LoadableComponent for PbsRemoteConfigPanel {
 
     fn update(&mut self, ctx: &LoadableComponentContext<Self>, msg: Self::Message) -> bool {
         match msg {
-            Msg::RemoveItem => {
+            Msg::RemoveItem(v) => {
                 if let Some(key) = self.selection.selected_key() {
                     let link = ctx.link().clone();
                     self.spawn(async move {
-                        if let Err(err) = delete_item(key).await {
+                        if let Err(err) = delete_item(key, v).await {
                             link.show_error(tr!("Unable to delete item"), err, true);
                         }
                         link.send_reload();
@@ -205,10 +210,9 @@ impl LoadableComponent for PbsRemoteConfigPanel {
                     .onclick(link.change_view_callback(|_| Some(ViewState::Edit))),
             )
             .with_child(
-                ConfirmButton::new(tr!("Remove"))
-                    .confirm_message(tr!("Are you sure you want to remove this remote?"))
+                Button::new(tr!("Remove"))
                     .disabled(disabled)
-                    .on_activate(link.callback(|_| Msg::RemoveItem)),
+                    .on_activate(link.change_view_callback(|_| Some(ViewState::Remove))),
             )
             .with_flex_spacer()
             .with_child({
@@ -243,6 +247,7 @@ impl LoadableComponent for PbsRemoteConfigPanel {
                 .selection
                 .selected_key()
                 .map(|key| self.create_edit_dialog(ctx, key)),
+            ViewState::Remove => Some(self.create_remove_remote_dialog(ctx)),
         }
     }
 }
@@ -303,6 +308,19 @@ impl PbsRemoteConfigPanel {
             .on_done(ctx.link().change_view_callback(|_| None))
             .into()
     }
+
+    fn create_remove_remote_dialog(&self, ctx: &LoadableComponentContext<Self>) -> Html {
+        let link = ctx.link().clone();
+        let close = link.change_view_callback(|_| None);
+
+        RemoveRemote::new()
+            .on_dismiss(close.clone())
+            .on_confirm(Callback::from(move |v| {
+                link.send_message(Msg::RemoveItem(v));
+                link.change_view(None);
+            }))
+            .into()
+    }
 }
 
 impl From<RemoteConfigPanel> for VNode {
diff --git a/ui/src/remotes/mod.rs b/ui/src/remotes/mod.rs
index 603077c..bfe9dc0 100644
--- a/ui/src/remotes/mod.rs
+++ b/ui/src/remotes/mod.rs
@@ -27,6 +27,8 @@ pub use tasks::RemoteTaskList;
 mod updates;
 pub use updates::UpdateTree;
 
+mod remove_remote;
+
 mod firewall;
 pub use firewall::FirewallTree;
 
diff --git a/ui/src/remotes/remove_remote.rs b/ui/src/remotes/remove_remote.rs
new file mode 100644
index 0000000..45cbd18
--- /dev/null
+++ b/ui/src/remotes/remove_remote.rs
@@ -0,0 +1,103 @@
+use std::rc::Rc;
+
+use yew::html::IntoEventCallback;
+use yew::prelude::*;
+use yew::virtual_dom::{VComp, VNode};
+
+use pwt::prelude::*;
+use pwt::widget::form::Checkbox;
+use pwt::widget::{Column, ConfirmDialog};
+
+use pwt_macros::builder;
+
+#[derive(PartialEq, Properties)]
+#[builder]
+pub struct RemoveRemote {
+    /// A callback for an action that needs to be confirmed by the user.
+    #[prop_or_default]
+    #[builder_cb(IntoEventCallback, into_event_callback, bool)]
+    pub on_confirm: Option<Callback<bool>>,
+
+    /// A callback that will trigger if the user dismisses the dialog.
+    #[prop_or_default]
+    #[builder_cb(IntoEventCallback, into_event_callback, ())]
+    pub on_dismiss: Option<Callback<()>>,
+}
+
+impl Default for RemoveRemote {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl RemoveRemote {
+    pub fn new() -> Self {
+        yew::props!(Self {})
+    }
+}
+
+enum Msg {
+    SelectCheckBox(bool),
+}
+
+struct PdmRemoveRemote {
+    keep_api_token: bool,
+}
+
+impl Component for PdmRemoveRemote {
+    type Message = Msg;
+    type Properties = RemoveRemote;
+
+    fn create(_ctx: &Context<Self>) -> Self {
+        Self {
+            keep_api_token: false,
+        }
+    }
+
+    fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
+        match msg {
+            Msg::SelectCheckBox(v) => {
+                self.keep_api_token = v;
+                true
+            }
+        }
+    }
+
+    fn view(&self, ctx: &Context<Self>) -> Html {
+        let props = ctx.props();
+        let keep_api_token = self.keep_api_token;
+
+        let on_confirm = props.on_confirm.clone();
+        let on_dismiss = props.on_dismiss.clone();
+
+        let content = Column::new()
+            .gap(2)
+            .with_child(tr!("Are you sure you want to remove this remote?"))
+            .with_child(
+                Checkbox::new()
+                    .box_label(tr!("Keep the API token on the remote"))
+                    .checked(keep_api_token)
+                    .on_change(ctx.link().callback(Msg::SelectCheckBox)),
+            );
+
+        let mut dialog = ConfirmDialog::default()
+            .on_confirm(Callback::from(move |_| {
+                if let Some(on_confirm) = &on_confirm {
+                    on_confirm.emit(!keep_api_token);
+                }
+            }))
+            .on_close(on_dismiss.clone())
+            .on_dismiss(on_dismiss);
+
+        dialog.set_confirm_message(content);
+
+        dialog.into()
+    }
+}
+
+impl From<RemoveRemote> for VNode {
+    fn from(val: RemoveRemote) -> Self {
+        let comp = VComp::new::<PdmRemoveRemote>(Rc::new(val), None);
+        VNode::from(comp)
+    }
+}
-- 
2.47.3





  parent reply	other threads:[~2026-02-18 16:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 16:41 [PATCH datacenter-manager/proxmox v4 0/7] fix #6914: add option to remove already existing token Shan Shaji
2026-02-18 16:41 ` [PATCH datacenter-manager v4 1/6] server: pbs-client: add method to delete token from remote Shan Shaji
2026-02-18 16:41 ` [PATCH datacenter-manager v4 2/6] fix #6914: api: add support " Shan Shaji
2026-02-18 16:41 ` [PATCH datacenter-manager v4 3/6] pdm-client: accept `delete-token` argument for deleting api token Shan Shaji
2026-02-18 16:41 ` [PATCH datacenter-manager v4 4/6] fix #6914: cli-client: add option to delete token from remote Shan Shaji
2026-02-18 16:41 ` Shan Shaji [this message]
2026-02-18 16:41 ` [PATCH datacenter-manager v4 6/6] fix #6914: cli-admin: " Shan Shaji
2026-02-18 16:41 ` [PATCH proxmox v4 1/1] pve-api-types: generate missing `delete_token` method Shan Shaji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260218164135.413762-6-s.shaji@proxmox.com \
    --to=s.shaji@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal