public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 4/4] ui: dashboard: subscriptions details: add a 'force refresh' button
Date: Thu, 27 Nov 2025 15:03:48 +0100	[thread overview]
Message-ID: <20251127140451.3131469-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251127140451.3131469-1-d.csapak@proxmox.com>

This simply calls the subscription api with 'max-age: 0', so we force
the backend to fetch all subscriptions.

This is useful when one adds a subscription to the remotes and does not
want to wait for the automatic refresh.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/dashboard/subscription_info.rs | 27 +++++++++++-----------
 ui/src/dashboard/view.rs              | 33 ++++++++++++++++++++-------
 ui/src/load_result.rs                 |  6 +++++
 3 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/ui/src/dashboard/subscription_info.rs b/ui/src/dashboard/subscription_info.rs
index fed2b2c7..d6d13d8c 100644
--- a/ui/src/dashboard/subscription_info.rs
+++ b/ui/src/dashboard/subscription_info.rs
@@ -136,19 +136,20 @@ impl From<SubscriptionInfo> for VNode {
 pub fn create_subscriptions_dialog(
     subs: SharedState<LoadResult<Vec<RemoteSubscriptions>, Error>>,
     on_dialog_close: Callback<()>,
-) -> Option<Dialog> {
-    if let Some(subs) = subs.read().data.clone() {
-        let dialog = Dialog::new(tr!("Your Subscriptions"))
-            .resizable(true)
-            .width(500)
-            .height(400)
-            .min_width(200)
-            .min_height(50)
-            .with_child(SubscriptionsList::new(subs.clone()))
-            .on_close(on_dialog_close);
-        return Some(dialog);
-    }
-    None
+    on_refresh: Callback<MouseEvent>,
+) -> Dialog {
+    let loading = !subs.read().has_data();
+    let subs = subs.read().data.clone();
+    let subs = subs.unwrap_or_default();
+    Dialog::new(tr!("Your Subscriptions"))
+        .with_tool(Button::refresh(loading).on_activate(on_refresh))
+        .resizable(true)
+        .width(500)
+        .height(400)
+        .min_width(200)
+        .min_height(50)
+        .with_child(SubscriptionsList::new(subs))
+        .on_close(on_dialog_close)
 }
 
 pub fn create_subscription_panel(
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index 2adcee53..2791277b 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -95,6 +95,7 @@ pub enum Msg {
     ShowSubscriptionsDialog(bool),
     LayoutUpdate(ViewLayout),
     UpdateResult(Result<(), Error>),
+    ForceSubscriptionUpdate,
 }
 
 struct ViewComp {
@@ -425,6 +426,22 @@ impl Component for ViewComp {
             Msg::UpdateResult(res) => {
                 self.update_result.update(res);
             }
+            Msg::ForceSubscriptionUpdate => {
+                let link = ctx.link().clone();
+                let view = ctx.props().view.clone();
+                self.render_args.subscriptions.write().clear();
+                self.async_pool.spawn(async move {
+                    let mut params = json!({
+                        "verbose": true,
+                        "max-age": 0,
+                    });
+                    if let Some(view) = view {
+                        params["view"] = view.to_string().into();
+                    }
+                    let res = http_get("/resources/subscription", Some(params)).await;
+                    link.send_message(Msg::LoadingResult(LoadingResult::SubscriptionInfo(res)));
+                });
+            }
         }
         true
     }
@@ -547,14 +564,14 @@ impl Component for ViewComp {
                 .on_submit(move |ctx| crate::remotes::create_remote(ctx, remote_type))
         }));
 
-        view.add_optional_child(if self.subscriptions_dialog {
-            create_subscriptions_dialog(
-                self.render_args.subscriptions.clone(),
-                ctx.link().callback(|_| Msg::ShowSubscriptionsDialog(false)),
-            )
-        } else {
-            None
-        });
+        view.add_optional_child(
+            self.subscriptions_dialog
+                .then_some(create_subscriptions_dialog(
+                    self.render_args.subscriptions.clone(),
+                    ctx.link().callback(|_| Msg::ShowSubscriptionsDialog(false)),
+                    ctx.link().callback(|_| Msg::ForceSubscriptionUpdate),
+                )),
+        );
 
         let view_context = ViewContext {
             name: props.view.clone(),
diff --git a/ui/src/load_result.rs b/ui/src/load_result.rs
index 4f3e6d5a..55436fd1 100644
--- a/ui/src/load_result.rs
+++ b/ui/src/load_result.rs
@@ -33,6 +33,12 @@ impl<T, E> LoadResult<T, E> {
     pub fn has_data(&self) -> bool {
         self.data.is_some() || self.error.is_some()
     }
+
+    /// Clears both data and the error from the result.
+    pub fn clear(&mut self) {
+        self.data = None;
+        self.error = None;
+    }
 }
 
 impl<T, E> Default for LoadResult<T, E> {
-- 
2.47.3



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  parent reply	other threads:[~2025-11-27 14:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27 14:03 [pdm-devel] [PATCH datacenter-manager 0/4] improve subscription display in Dominik Csapak
2025-11-27 14:03 ` [pdm-devel] [PATCH datacenter-manager 1/4] ui: dashboard: subscriptions: refactor subscriptions show logic Dominik Csapak
2025-11-27 14:03 ` [pdm-devel] [PATCH datacenter-manager 2/4] ui: dashboard: subscriptions list: update store when data changes Dominik Csapak
2025-11-27 14:03 ` [pdm-devel] [PATCH datacenter-manager 3/4] ui: dashboard: subscriptions list: improve display of subscription state Dominik Csapak
2025-11-27 14:03 ` Dominik Csapak [this message]
2025-11-27 16:13   ` [pdm-devel] [PATCH datacenter-manager 4/4] ui: dashboard: subscriptions details: add a 'force refresh' button Michael Köppl
2025-11-27 21:10     ` Thomas Lamprecht
2025-11-27 16:13 ` [pdm-devel] [PATCH datacenter-manager 0/4] improve subscription display in Michael Köppl
2025-11-27 21:12 ` [pdm-devel] applied: " Thomas Lamprecht

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=20251127140451.3131469-5-d.csapak@proxmox.com \
    --to=d.csapak@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