From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pdm-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 4BA8F1FF15C
	for <inbox@lore.proxmox.com>; Wed, 19 Feb 2025 13:28:31 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 8504628614;
	Wed, 19 Feb 2025 13:28:27 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Wed, 19 Feb 2025 13:28:21 +0100
Message-Id: <20250219122824.2043990-5-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250219122824.2043990-1-d.csapak@proxmox.com>
References: <20250219122824.2043990-1-d.csapak@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -1.229 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [tasks.rs]
 URIBL_DBL_SPAM 2.5 Contains a spam URL listed in the Spamhaus DBL blocklist
 [tasks.rs]
Subject: [pdm-devel] [PATCH datacenter-manager v2 4/7] ui: refactor remote
 upid formatter
X-BeenThere: pdm-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Datacenter Manager development discussion
 <pdm-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/>
List-Post: <mailto:pdm-devel@lists.proxmox.com>
List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pdm-devel-bounces@lists.proxmox.com
Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com>

since that is often the same (aside from the option to render the
remote), and we'll want to reuse that even further.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/remotes/tasks.rs | 19 ++++---------------
 ui/src/tasks.rs         | 23 ++++++++++++++++++++++-
 ui/src/top_nav_bar.rs   | 18 +++---------------
 3 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/ui/src/remotes/tasks.rs b/ui/src/remotes/tasks.rs
index 99bb243..e74ebf2 100644
--- a/ui/src/remotes/tasks.rs
+++ b/ui/src/remotes/tasks.rs
@@ -7,12 +7,9 @@ use yew::{
 };
 
 use pdm_api_types::RemoteUpid;
-use pdm_client::types::PveUpid;
 
 use proxmox_yew_comp::{
-    common_api_types::TaskListItem,
-    utils::{format_task_description, format_upid, render_epoch_short},
-    TaskViewer, Tasks,
+    common_api_types::TaskListItem, utils::render_epoch_short, TaskViewer, Tasks,
 };
 use pwt::{
     css::FlexFit,
@@ -24,6 +21,8 @@ use pwt::{
     },
 };
 
+use crate::tasks::format_optional_remote_upid;
+
 #[derive(PartialEq, Properties)]
 pub struct RemoteTaskList;
 impl RemoteTaskList {
@@ -74,17 +73,7 @@ fn columns() -> Rc<Vec<DataTableHeader<TaskListItem>>> {
         DataTableColumn::new(tr!("Description"))
             .flex(4)
             .render(move |item: &TaskListItem| {
-                if let Ok(remote_upid) = item.upid.parse::<RemoteUpid>() {
-                    match remote_upid.upid.parse::<PveUpid>() {
-                        Ok(upid) => {
-                            format_task_description(&upid.worker_type, upid.worker_id.as_deref())
-                        }
-                        Err(_) => format_upid(&remote_upid.upid),
-                    }
-                } else {
-                    format_upid(&item.upid)
-                }
-                .into()
+                format_optional_remote_upid(&item.upid, false).into()
             })
             .into(),
         DataTableColumn::new(tr!("Status"))
diff --git a/ui/src/tasks.rs b/ui/src/tasks.rs
index 6aa202a..0e7899c 100644
--- a/ui/src/tasks.rs
+++ b/ui/src/tasks.rs
@@ -1,6 +1,9 @@
-use proxmox_yew_comp::utils::register_task_description;
+use proxmox_yew_comp::utils::{format_task_description, format_upid, register_task_description};
 use pwt::tr;
 
+use pdm_api_types::RemoteUpid;
+use pdm_client::types::PveUpid;
+
 pub fn register_pve_tasks() {
     register_task_description("qmstart", ("VM", tr!("Start")));
     register_task_description("acmedeactivate", ("ACME Account", tr!("Deactivate")));
@@ -99,3 +102,21 @@ pub fn register_pve_tasks() {
     register_task_description("zfscreate", (tr!("ZFS Storage"), tr!("Create")));
     register_task_description("zfsremove", ("ZFS Pool", tr!("Remove")));
 }
+
+/// Format a UPID that is either [`RemoteUpid`] or a [`UPID`]
+/// If it's a [`RemoteUpid`], prefixes it with the remote name
+pub fn format_optional_remote_upid(upid: &str, include_remote: bool) -> String {
+    if let Ok(remote_upid) = upid.parse::<RemoteUpid>() {
+        let description = match remote_upid.upid.parse::<PveUpid>() {
+            Ok(upid) => format_task_description(&upid.worker_type, upid.worker_id.as_deref()),
+            Err(_) => format_upid(&remote_upid.upid),
+        };
+        if include_remote {
+            format!("{} - {}", remote_upid.remote(), description)
+        } else {
+            description
+        }
+    } else {
+        format_upid(&upid)
+    }
+}
diff --git a/ui/src/top_nav_bar.rs b/ui/src/top_nav_bar.rs
index 07b3b23..88ff137 100644
--- a/ui/src/top_nav_bar.rs
+++ b/ui/src/top_nav_bar.rs
@@ -13,15 +13,15 @@ use pwt::state::{Loader, Theme, ThemeObserver};
 use pwt::widget::{Button, Container, Row, ThemeModeSelector, Tooltip};
 
 use proxmox_yew_comp::common_api_types::TaskListItem;
-use proxmox_yew_comp::utils::{format_task_description, format_upid, set_location_href};
+use proxmox_yew_comp::utils::set_location_href;
 use proxmox_yew_comp::RunningTasksButton;
 use proxmox_yew_comp::{http_get, HelpButton, LanguageDialog, TaskViewer, ThemeDialog};
 
 use pwt_macros::builder;
 
 use pdm_api_types::RemoteUpid;
-use pdm_client::types::PveUpid;
 
+use crate::tasks::format_optional_remote_upid;
 use crate::widget::SearchBox;
 
 #[derive(Deserialize)]
@@ -207,19 +207,7 @@ impl Component for PdmTopNavBar {
                             }),
                     ])
                     .render(|item: &TaskListItem| {
-                        if let Ok(remote_upid) = (&item.upid).parse::<RemoteUpid>() {
-                            let description = match remote_upid.upid.parse::<PveUpid>() {
-                                Ok(upid) => format_task_description(
-                                    &upid.worker_type,
-                                    upid.worker_id.as_deref(),
-                                ),
-                                Err(_) => format_upid(&remote_upid.upid),
-                            };
-                            format!("{} - {}", remote_upid.remote(), description)
-                        } else {
-                            format_upid(&item.upid)
-                        }
-                        .into()
+                        format_optional_remote_upid(&item.upid, true).into()
                     }),
             );
 
-- 
2.39.5



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