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 v3 19/21] ui: dashboard: subscription info: move subscription loading to view
Date: Fri, 31 Oct 2025 13:44:02 +0100	[thread overview]
Message-ID: <20251031124822.2739685-20-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251031124822.2739685-1-d.csapak@proxmox.com>

so in case we have multiple subscription panels, the info from the view
can be reused.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/dashboard/subscription_info.rs | 72 ++++++++++-----------------
 ui/src/dashboard/view.rs              | 21 ++++++--
 2 files changed, 44 insertions(+), 49 deletions(-)

diff --git a/ui/src/dashboard/subscription_info.rs b/ui/src/dashboard/subscription_info.rs
index 2a4d94b7..cf8d7260 100644
--- a/ui/src/dashboard/subscription_info.rs
+++ b/ui/src/dashboard/subscription_info.rs
@@ -7,31 +7,30 @@ use yew::{
     Component, Html, Properties,
 };
 
-use proxmox_yew_comp::{http_get, Status};
+use proxmox_yew_comp::Status;
+use pwt::prelude::*;
+use pwt::widget::{Column, Container, Fa, Panel, Row};
 use pwt::{
     css::{AlignItems, FlexFit, JustifyContent, TextAlign},
-    prelude::tr,
-    props::{ContainerBuilder, CssBorderBuilder, CssPaddingBuilder, WidgetBuilder},
-    widget::{Column, Container, Fa, Panel, Row},
-    AsyncPool,
+    state::SharedState,
 };
 
 use pdm_api_types::subscription::{RemoteSubscriptionState, RemoteSubscriptions};
 
+use crate::LoadResult;
+
 #[derive(Properties, PartialEq)]
-pub struct SubscriptionInfo {}
+pub struct SubscriptionInfo {
+    subs: Option<Vec<RemoteSubscriptions>>,
+}
 
 impl SubscriptionInfo {
-    pub fn new() -> Self {
-        Self {}
+    pub fn new(subs: Option<Vec<RemoteSubscriptions>>) -> Self {
+        Self { subs }
     }
 }
 
-struct PdmSubscriptionInfo {
-    status: Vec<RemoteSubscriptions>,
-    loading: bool,
-    _async_pool: AsyncPool,
-}
+struct PdmSubscriptionInfo {}
 
 fn render_subscription_status(subs: &[RemoteSubscriptions]) -> Row {
     let mut none = 0;
@@ -98,52 +97,31 @@ fn render_subscription_status(subs: &[RemoteSubscriptions]) -> Row {
 }
 
 impl Component for PdmSubscriptionInfo {
-    type Message = Result<Vec<RemoteSubscriptions>, Error>;
-
+    type Message = ();
     type Properties = SubscriptionInfo;
 
-    fn create(ctx: &yew::Context<Self>) -> Self {
-        let link = ctx.link().clone();
-        let mut _async_pool = AsyncPool::new();
-        _async_pool.spawn(async move {
-            let result = http_get("/resources/subscription", None).await;
-            link.send_message(result);
-        });
-
-        Self {
-            status: Vec::new(),
-            loading: true,
-            _async_pool,
-        }
-    }
-
-    fn update(&mut self, _ctx: &yew::Context<Self>, msg: Self::Message) -> bool {
-        match msg {
-            Ok(result) => {
-                self.status = result;
-            }
-            Err(_) => self.status = Vec::new(),
-        }
-
-        self.loading = false;
-
-        true
+    fn create(_ctx: &yew::Context<Self>) -> Self {
+        Self {}
     }
 
-    fn view(&self, _ctx: &yew::Context<Self>) -> yew::Html {
+    fn view(&self, ctx: &yew::Context<Self>) -> yew::Html {
+        let props = ctx.props();
         Column::new()
             .class(FlexFit)
             .class(JustifyContent::Center)
             .class(AlignItems::Center)
             .with_optional_child(
-                self.loading.then_some(
+                props.subs.is_none().then_some(
                     Container::new()
                         .padding(4)
                         .with_child(Container::from_tag("i").class("pwt-loading-icon")),
                 ),
             )
             .with_optional_child(
-                (!self.loading).then_some(render_subscription_status(&self.status)),
+                props
+                    .subs
+                    .as_ref()
+                    .map(|subs| render_subscription_status(subs)),
             )
             .into()
     }
@@ -156,7 +134,9 @@ impl From<SubscriptionInfo> for VNode {
     }
 }
 
-pub fn create_subscription_panel() -> Panel {
+pub fn create_subscription_panel(
+    subs: SharedState<LoadResult<Vec<RemoteSubscriptions>, Error>>,
+) -> Panel {
     let title: Html = Row::new()
         .class(AlignItems::Center)
         .gap(2)
@@ -167,5 +147,5 @@ pub fn create_subscription_panel() -> Panel {
     Panel::new()
         .title(title)
         .border(true)
-        .with_child(SubscriptionInfo::new())
+        .with_child(SubscriptionInfo::new(subs.read().data.clone()))
 }
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index f3c8f0c8..bcb277ed 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -34,6 +34,7 @@ use crate::{pdm_client, LoadResult};
 
 use pdm_api_types::remotes::RemoteType;
 use pdm_api_types::resource::ResourcesStatus;
+use pdm_api_types::subscription::RemoteSubscriptions;
 use pdm_api_types::TaskStatistics;
 use pdm_client::types::TopEntities;
 
@@ -62,6 +63,7 @@ pub enum LoadingResult {
     Resources(Result<ResourcesStatus, Error>),
     TopEntities(Result<pdm_client::types::TopEntities, proxmox_client::Error>),
     TaskStatistics(Result<TaskStatistics, Error>),
+    SubscriptionInfo(Result<Vec<RemoteSubscriptions>, Error>),
     All,
 }
 
@@ -81,6 +83,7 @@ struct ViewComp {
     status: SharedState<LoadResult<ResourcesStatus, Error>>,
     top_entities: SharedState<LoadResult<TopEntities, proxmox_client::Error>>,
     statistics: SharedState<LoadResult<TaskStatistics, Error>>,
+    subscriptions: SharedState<LoadResult<Vec<RemoteSubscriptions>, Error>>,
 
     refresh_config: PersistentState<RefreshConfig>,
 
@@ -95,6 +98,7 @@ fn render_widget(
     link: yew::html::Scope<ViewComp>,
     item: &RowWidget,
     status: SharedState<LoadResult<ResourcesStatus, Error>>,
+    subscriptions: SharedState<LoadResult<Vec<RemoteSubscriptions>, Error>>,
     top_entities: SharedState<LoadResult<TopEntities, proxmox_client::Error>>,
     statistics: SharedState<LoadResult<TaskStatistics, Error>>,
     refresh_config: RefreshConfig,
@@ -112,7 +116,7 @@ fn render_widget(
             show_wizard.then_some(link.callback(|_| Msg::CreateWizard(Some(RemoteType::Pve)))),
         ),
         WidgetType::PbsDatastores => create_pbs_datastores_panel(status.data.clone()),
-        WidgetType::Subscription => create_subscription_panel(),
+        WidgetType::Subscription => create_subscription_panel(subscriptions),
         WidgetType::Sdn => create_sdn_panel(status.data.clone()),
         WidgetType::Leaderboard { leaderboard_type } => {
             let entities = match leaderboard_type {
@@ -200,7 +204,12 @@ impl ViewComp {
                     }
                 };
 
-                join!(status_future, entities_future, tasks_future);
+                let subs_future = async {
+                    let res = http_get("/resources/subscription", None).await;
+                    link.send_message(Msg::LoadingResult(LoadingResult::SubscriptionInfo(res)));
+                };
+
+                join!(status_future, entities_future, tasks_future, subs_future);
                 link.send_message(Msg::LoadingResult(LoadingResult::All));
             });
         } else {
@@ -279,6 +288,7 @@ impl Component for ViewComp {
             status: SharedState::new(LoadResult::new()),
             top_entities: SharedState::new(LoadResult::new()),
             statistics: SharedState::new(LoadResult::new()),
+            subscriptions: SharedState::new(LoadResult::new()),
 
             refresh_config,
             load_finished_time: None,
@@ -302,6 +312,9 @@ impl Component for ViewComp {
                 LoadingResult::TaskStatistics(task_statistics) => {
                     self.statistics.write().update(task_statistics)
                 }
+                LoadingResult::SubscriptionInfo(subscriptions) => {
+                    self.subscriptions.write().update(subscriptions);
+                }
                 LoadingResult::All => {
                     self.loading = false;
                     if self.load_finished_time.is_none() {
@@ -372,7 +385,7 @@ impl Component for ViewComp {
             view.add_child(
                 Row::new()
                     .class("pwt-content-spacer")
-                    .with_child(create_subscription_panel()),
+                    .with_child(create_subscription_panel(self.subscriptions.clone())),
             );
         }
         match self.template.data.as_ref().map(|template| &template.layout) {
@@ -380,6 +393,7 @@ impl Component for ViewComp {
                 view.add_child(RowView::new(rows.clone(), {
                     let link = ctx.link().clone();
                     let status = self.status.clone();
+                    let subscriptions = self.subscriptions.clone();
                     let top_entities = self.top_entities.clone();
                     let statistics = self.statistics.clone();
                     let refresh_config = self.refresh_config.clone();
@@ -388,6 +402,7 @@ impl Component for ViewComp {
                             link.clone(),
                             widget,
                             status.clone(),
+                            subscriptions.clone(),
                             top_entities.clone(),
                             statistics.clone(),
                             refresh_config.clone(),
-- 
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-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 ` [pdm-devel] [PATCH datacenter-manager v3 01/21] ui: dashboard: refactor guest panel creation to its own module Dominik Csapak
2025-10-31 12:43 ` [pdm-devel] [PATCH datacenter-manager v3 02/21] ui: dashboard: refactor creating the node panel into " 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 ` Dominik Csapak [this message]
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-20-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