all lists on 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 v3 01/21] ui: dashboard: refactor guest panel creation to its own module
Date: Fri, 31 Oct 2025 13:43:44 +0100	[thread overview]
Message-ID: <20251031124822.2739685-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251031124822.2739685-1-d.csapak@proxmox.com>

so we can more easily reuse it. For this, also make the 'create_title_with_icon'
a freestanding function that is public so we can reuse it outside the
dashboard struct.

Also add the functionality of not passing a guest_type, so that we can
create a panel that includes info for all guests, regardless of type.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/dashboard/guest_panel.rs | 79 +++++++++++++++++++++++++--------
 ui/src/dashboard/mod.rs         | 69 +++++++++++++---------------
 2 files changed, 91 insertions(+), 57 deletions(-)

diff --git a/ui/src/dashboard/guest_panel.rs b/ui/src/dashboard/guest_panel.rs
index 814ecfa5..be7a7a2e 100644
--- a/ui/src/dashboard/guest_panel.rs
+++ b/ui/src/dashboard/guest_panel.rs
@@ -1,30 +1,34 @@
 use std::rc::Rc;
 
-use pdm_api_types::resource::{GuestStatusCount, ResourceType};
+use pdm_api_types::resource::{GuestStatusCount, ResourceType, ResourcesStatus};
 use pdm_search::{Search, SearchTerm};
 use proxmox_yew_comp::GuestState;
 use pwt::{
     css::{self, TextAlign},
     prelude::*,
-    widget::{Container, Fa, List, ListTile},
+    widget::{Container, Fa, List, ListTile, Panel},
 };
 use yew::{
     virtual_dom::{VComp, VNode},
     Properties,
 };
 
-use crate::{pve::GuestType, search_provider::get_search_provider};
+use crate::{
+    dashboard::create_title_with_icon, pve::GuestType, search_provider::get_search_provider,
+};
 
 use super::loading_column;
 
 #[derive(PartialEq, Clone, Properties)]
 pub struct GuestPanel {
-    guest_type: GuestType,
-    status: Option<GuestStatusCount>,
+    guest_type: Option<GuestType>,
+    status: Option<ResourcesStatus>,
 }
 
 impl GuestPanel {
-    pub fn new(guest_type: GuestType, status: Option<GuestStatusCount>) -> Self {
+    /// Creates a new guest panel. Setting `guest_type` to `None` means we
+    /// create one for all guests, regardless of type.
+    pub fn new(guest_type: Option<GuestType>, status: Option<ResourcesStatus>) -> Self {
         yew::props!(Self { guest_type, status })
     }
 }
@@ -63,7 +67,16 @@ impl yew::Component for PdmGuestPanel {
         let props = ctx.props();
         let guest_type = props.guest_type;
         let status = match &props.status {
-            Some(status) => status,
+            Some(status) => match guest_type {
+                Some(GuestType::Qemu) => status.qemu.clone(),
+                Some(GuestType::Lxc) => status.lxc.clone(),
+                None => GuestStatusCount {
+                    running: status.qemu.running + status.lxc.running,
+                    stopped: status.qemu.stopped + status.lxc.stopped,
+                    template: status.qemu.template + status.lxc.template,
+                    unknown: status.qemu.unknown + status.lxc.unknown,
+                },
+            },
             None => return loading_column().into(),
         };
 
@@ -93,7 +106,7 @@ impl yew::Component for PdmGuestPanel {
 
 fn create_list_tile(
     link: &html::Scope<PdmGuestPanel>,
-    guest_type: GuestType,
+    guest_type: Option<GuestType>,
     status_row: StatusRow,
 ) -> Option<ListTile> {
     let (icon, text, count, status, template) = match status_row {
@@ -129,7 +142,13 @@ fn create_list_tile(
                 None,
             ),
         },
-        StatusRow::All(count) => (Fa::from(guest_type), tr!("All"), count, None, None),
+        StatusRow::All(count) => (
+            Fa::from(guest_type.unwrap_or(GuestType::Qemu)),
+            tr!("All"),
+            count,
+            None,
+            None,
+        ),
     };
 
     Some(
@@ -158,19 +177,29 @@ fn create_list_tile(
 }
 
 fn create_guest_search_term(
-    guest_type: GuestType,
+    guest_type: Option<GuestType>,
     status: Option<&'static str>,
     template: Option<bool>,
 ) -> Search {
-    let resource_type: ResourceType = guest_type.into();
-    if status.is_none() && template.is_none() {
-        return Search::with_terms(vec![
-            SearchTerm::new(resource_type.as_str()).category(Some("type"))
-        ]);
+    let mut terms = Vec::new();
+    match guest_type {
+        Some(guest_type) => {
+            let resource_type: ResourceType = guest_type.into();
+            terms.push(SearchTerm::new(resource_type.as_str()).category(Some("type")));
+        }
+        None => {
+            terms.push(
+                SearchTerm::new(ResourceType::PveQemu.as_str())
+                    .category(Some("type"))
+                    .optional(true),
+            );
+            terms.push(
+                SearchTerm::new(ResourceType::PveLxc.as_str())
+                    .category(Some("type"))
+                    .optional(true),
+            );
+        }
     }
-
-    let mut terms = vec![SearchTerm::new(resource_type.as_str()).category(Some("type"))];
-
     if let Some(template) = template {
         terms.push(SearchTerm::new(template.to_string()).category(Some("template")));
     }
@@ -179,3 +208,17 @@ fn create_guest_search_term(
     }
     Search::with_terms(terms)
 }
+
+/// Creates a new guest panel. Setting `guest_type` to `None` means we
+/// create one for all guests, regardless of type.
+pub fn create_guest_panel(guest_type: Option<GuestType>, status: Option<ResourcesStatus>) -> Panel {
+    let (icon, title) = match guest_type {
+        Some(GuestType::Qemu) => ("desktop", tr!("Virtual Machines")),
+        Some(GuestType::Lxc) => ("cubes", tr!("Linux Container")),
+        None => ("desktop", tr!("Guests")),
+    };
+    Panel::new()
+        .title(create_title_with_icon(icon, title))
+        .border(true)
+        .with_child(GuestPanel::new(guest_type, status))
+}
diff --git a/ui/src/dashboard/mod.rs b/ui/src/dashboard/mod.rs
index 07d5cd99..1fe149c3 100644
--- a/ui/src/dashboard/mod.rs
+++ b/ui/src/dashboard/mod.rs
@@ -41,7 +41,7 @@ mod remote_panel;
 use remote_panel::RemotePanel;
 
 mod guest_panel;
-use guest_panel::GuestPanel;
+pub use guest_panel::create_guest_panel;
 
 mod node_status_panel;
 use node_status_panel::NodeStatusPanel;
@@ -149,15 +149,6 @@ pub struct PdmDashboard {
 }
 
 impl PdmDashboard {
-    fn create_title_with_icon(&self, icon: &str, title: String) -> Html {
-        Row::new()
-            .class(AlignItems::Center)
-            .gap(2)
-            .with_child(Fa::new(icon))
-            .with_child(title)
-            .into()
-    }
-
     fn create_node_panel(&self, icon: &str, title: String, remote_type: RemoteType) -> Panel {
         let (nodes_status, failed_remotes) = match &self.status {
             Some(status) => {
@@ -178,7 +169,7 @@ impl PdmDashboard {
         Panel::new()
             .flex(1.0)
             .width(300)
-            .title(self.create_title_with_icon(icon, title))
+            .title(create_title_with_icon(icon, title))
             .border(true)
             .with_child(NodeStatusPanel::new(
                 remote_type,
@@ -187,34 +178,13 @@ impl PdmDashboard {
             ))
     }
 
-    fn create_guest_panel(&self, guest_type: GuestType) -> Panel {
-        let (icon, title, status) = match guest_type {
-            GuestType::Qemu => (
-                "desktop",
-                tr!("Virtual Machines"),
-                self.status.as_ref().map(|s| s.qemu.clone()),
-            ),
-            GuestType::Lxc => (
-                "cubes",
-                tr!("Linux Container"),
-                self.status.as_ref().map(|s| s.lxc.clone()),
-            ),
-        };
-        Panel::new()
-            .flex(1.0)
-            .width(300)
-            .title(self.create_title_with_icon(icon, title))
-            .border(true)
-            .with_child(GuestPanel::new(guest_type, status))
-    }
-
     fn create_sdn_panel(&self) -> Panel {
         let sdn_zones_status = self.status.as_ref().map(|status| status.sdn_zones.clone());
 
         Panel::new()
             .flex(1.0)
             .width(200)
-            .title(self.create_title_with_icon("sdn", tr!("SDN Zones")))
+            .title(create_title_with_icon("sdn", tr!("SDN Zones")))
             .border(true)
             .with_child(SdnZonePanel::new(
                 (!self.loading).then_some(sdn_zones_status).flatten(),
@@ -235,7 +205,7 @@ impl PdmDashboard {
             .flex(1.0)
             .width(500)
             .border(true)
-            .title(self.create_title_with_icon("list", title))
+            .title(create_title_with_icon("list", title))
             .with_child(
                 Container::new()
                     .class(FlexFit)
@@ -272,7 +242,7 @@ impl PdmDashboard {
             .width(500)
             .min_width(400)
             .border(true)
-            .title(self.create_title_with_icon(icon, title))
+            .title(create_title_with_icon(icon, title))
             .with_optional_child(
                 entities
                     .map(|entities| TopEntities::new(entities.clone(), metrics_title, threshold)),
@@ -294,7 +264,10 @@ impl PdmDashboard {
         Panel::new()
             .flex(1.0)
             .width(300)
-            .title(self.create_title_with_icon("database", tr!("Backup Server Datastores")))
+            .title(create_title_with_icon(
+                "database",
+                tr!("Backup Server Datastores"),
+            ))
             .border(true)
             .with_child(PbsDatastoresPanel::new(pbs_datastores))
     }
@@ -499,7 +472,7 @@ impl Component for PdmDashboard {
                     .padding_top(0)
                     .with_child(
                         Panel::new()
-                            .title(self.create_title_with_icon("server", tr!("Remotes")))
+                            .title(create_title_with_icon("server", tr!("Remotes")))
                             .flex(1.0)
                             //.border(true)
                             .width(300)
@@ -530,8 +503,16 @@ impl Component for PdmDashboard {
                         tr!("Virtual Environment Nodes"),
                         RemoteType::Pve,
                     ))
-                    .with_child(self.create_guest_panel(GuestType::Qemu))
-                    .with_child(self.create_guest_panel(GuestType::Lxc))
+                    .with_child(
+                        create_guest_panel(Some(GuestType::Qemu), self.status.clone())
+                            .flex(1.0)
+                            .width(300),
+                    )
+                    .with_child(
+                        create_guest_panel(Some(GuestType::Lxc), self.status.clone())
+                            .flex(1.0)
+                            .width(300),
+                    )
                     .with_child(self.create_node_panel(
                         "building-o",
                         tr!("Backup Server Nodes"),
@@ -682,3 +663,13 @@ fn loading_column() -> Column {
         .class(AlignItems::Center)
         .with_child(html! {<i class={"pwt-loading-icon"} />})
 }
+
+/// Create a consistent title component for the given title and icon
+pub fn create_title_with_icon(icon: &str, title: String) -> Html {
+    Row::new()
+        .class(AlignItems::Center)
+        .gap(2)
+        .with_child(Fa::new(icon))
+        .with_child(title)
+        .into()
+}
-- 
2.47.3



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


  reply	other threads:[~2025-10-31 12:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-31 12:43 [pdm-devel] [PATCH datacenter-manager v3 00/21] prepare ui for customizable views Dominik Csapak
2025-10-31 12:43 ` Dominik Csapak [this message]
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 02/21] ui: dashboard: refactor creating the node panel into its own module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 03/21] ui: dashboard: node panel: make remote type optional Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 04/21] ui: dashboard: refactor remote panel creation into its own module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 05/21] ui: dashboard: remote panel: make wizard menu optional Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 06/21] ui: dashboard: refactor sdn panel creation into its own module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 07/21] ui: dashboard: refactor task summary panel creation to " Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 08/21] ui: dashboard: task summary: disable virtual scrolling Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 09/21] ui: dashboard: refactor subscription panel creation to its own module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 10/21] ui: dashboard: refactor top entities " Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 11/21] ui: dashboard: refactor DashboardConfig editing/constants to their module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 12/21] ui: dashboard: factor out task parameter calculation Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 13/21] ui: dashboard: pbs datastores panel: refactor creation into own module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 14/21] ui: dashboard: remove unused remote list Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 15/21] ui: dashboard: status row: make loading less jarring Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 16/21] ui: introduce `LoadResult` helper type Dominik Csapak
2025-10-31 12:44 ` [pdm-devel] [PATCH datacenter-manager v3 17/21] ui: dashboard: implement 'View' Dominik Csapak
2025-10-31 12:44 ` [pdm-devel] [PATCH datacenter-manager v3 18/21] ui: dashboard: use 'View' instead of the Dashboard Dominik Csapak
2025-10-31 12:44 ` [pdm-devel] [PATCH datacenter-manager v3 19/21] ui: dashboard: subscription info: move subscription loading to view Dominik Csapak
2025-10-31 12:44 ` [pdm-devel] [PATCH datacenter-manager v3 20/21] ui: dashboard: use SharedState for create_*_panel Dominik Csapak
2025-10-31 12:44 ` [pdm-devel] [PATCH datacenter-manager v3 21/21] ui: dashboard: enable editing view Dominik Csapak

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=20251031124822.2739685-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal