From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 85C401FF15C for ; Fri, 31 Oct 2025 13:48:07 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BD439117CC; Fri, 31 Oct 2025 13:48:41 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Fri, 31 Oct 2025 13:44:02 +0100 Message-ID: <20251031124822.2739685-20-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251031124822.2739685-1-d.csapak@proxmox.com> References: <20251031124822.2739685-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 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 Subject: [pdm-devel] [PATCH datacenter-manager v3 19/21] ui: dashboard: subscription info: move subscription loading to view X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" so in case we have multiple subscription panels, the info from the view can be reused. Signed-off-by: Dominik Csapak --- 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>, +} impl SubscriptionInfo { - pub fn new() -> Self { - Self {} + pub fn new(subs: Option>) -> Self { + Self { subs } } } -struct PdmSubscriptionInfo { - status: Vec, - 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, Error>; - + type Message = (); type Properties = SubscriptionInfo; - fn create(ctx: &yew::Context) -> 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, 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 {} } - fn view(&self, _ctx: &yew::Context) -> yew::Html { + fn view(&self, ctx: &yew::Context) -> 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 for VNode { } } -pub fn create_subscription_panel() -> Panel { +pub fn create_subscription_panel( + subs: SharedState, 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), TopEntities(Result), TaskStatistics(Result), + SubscriptionInfo(Result, Error>), All, } @@ -81,6 +83,7 @@ struct ViewComp { status: SharedState>, top_entities: SharedState>, statistics: SharedState>, + subscriptions: SharedState, Error>>, refresh_config: PersistentState, @@ -95,6 +98,7 @@ fn render_widget( link: yew::html::Scope, item: &RowWidget, status: SharedState>, + subscriptions: SharedState, Error>>, top_entities: SharedState>, statistics: SharedState>, 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