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 [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 201FC1FF164 for <inbox@lore.proxmox.com>; Fri, 11 Apr 2025 16:05:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 103401C0B4; Fri, 11 Apr 2025 16:05:54 +0200 (CEST) From: Dominik Csapak <d.csapak@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 11 Apr 2025 16:05:19 +0200 Message-Id: <20250411140520.1475644-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250411140520.1475644-1-d.csapak@proxmox.com> References: <20250411140520.1475644-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 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 2/3] ui: dashboard: refactor remotes panel 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> put the remotes panel into it's own component to keep the dashboard code shorter when adding more functionality here. Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> --- ui/src/dashboard/mod.rs | 38 ++++---------- ui/src/dashboard/remote_panel.rs | 90 ++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 ui/src/dashboard/remote_panel.rs diff --git a/ui/src/dashboard/mod.rs b/ui/src/dashboard/mod.rs index ea0cf5e..016fccb 100644 --- a/ui/src/dashboard/mod.rs +++ b/ui/src/dashboard/mod.rs @@ -26,6 +26,9 @@ pub use top_entities::TopEntities; mod subscription_info; pub use subscription_info::SubscriptionInfo; +mod remote_panel; +use remote_panel::RemotePanel; + #[derive(Properties, PartialEq)] pub struct Dashboard { #[prop_or(60)] @@ -260,19 +263,7 @@ impl Component for PdmDashboard { } } - fn view(&self, _ctx: &yew::Context<Self>) -> yew::Html { - let (remote_icon, remote_text) = match (self.status.failed_remotes, self.status.remotes) { - (0, 0) => (Status::Warning.to_fa_icon(), tr!("No remotes configured.")), - (0, _) => ( - Status::Success.to_fa_icon(), - tr!("Could reach all remotes."), - ), - (failed, _) => ( - Status::Error.to_fa_icon(), - tr!("{0} remotes failed to reach.", failed), - ), - }; - + fn view(&self, ctx: &yew::Context<Self>) -> yew::Html { let content = Column::new() .class(FlexFit) .with_child( @@ -290,22 +281,11 @@ impl Component for PdmDashboard { .with_tool( Button::new(tr!("Add")) .icon_class("fa fa-plus-circle") - .onclick(_ctx.link().callback(|_| Msg::CreateWizard(true))), + .onclick(ctx.link().callback(|_| Msg::CreateWizard(true))), ) - .with_child( - Column::new() - .padding(4) - .class(FlexFit) - .class(AlignItems::Center) - .class(JustifyContent::Center) - .gap(2) - .with_child(if self.loading { - html! {<i class={"pwt-loading-icon"} />} - } else { - remote_icon.large_4x().into() - }) - .with_optional_child((!self.loading).then_some(remote_text)), - ), + .with_child(RemotePanel::new( + (!self.loading).then_some(self.status.clone()), + )), ) .with_child(self.create_node_panel( "building", @@ -423,7 +403,7 @@ impl Component for PdmDashboard { .with_optional_child( self.show_wizard.then_some( AddWizard::new(pdm_api_types::remotes::RemoteType::Pve) - .on_close(_ctx.link().callback(|_| Msg::CreateWizard(false))) + .on_close(ctx.link().callback(|_| Msg::CreateWizard(false))) .on_submit(move |ctx| { crate::remotes::create_remote( ctx, diff --git a/ui/src/dashboard/remote_panel.rs b/ui/src/dashboard/remote_panel.rs new file mode 100644 index 0000000..2c1dd75 --- /dev/null +++ b/ui/src/dashboard/remote_panel.rs @@ -0,0 +1,90 @@ +use std::rc::Rc; + +use proxmox_yew_comp::Status; +use pwt::{ + css, + prelude::*, + props::{ContainerBuilder, WidgetBuilder}, + widget::{Column, Container, Fa}, +}; +use yew::{ + virtual_dom::{VComp, VNode}, + Component, Properties, +}; + +use pdm_api_types::resource::ResourcesStatus; + +#[derive(Properties, PartialEq)] +/// A panel for showing the overall remotes status +pub struct RemotePanel { + /// The status loaded from the API + pub status: Option<ResourcesStatus>, +} + +impl RemotePanel { + /// Takes the status of the API, or None (which indicates loading) + pub fn new(status: Option<ResourcesStatus>) -> Self { + yew::props!(Self { status }) + } +} + +impl From<RemotePanel> for VNode { + fn from(val: RemotePanel) -> Self { + let comp = VComp::new::<PdmRemotePanel>(Rc::new(val), None); + VNode::from(comp) + } +} + +struct PdmRemotePanel {} + +impl Component for PdmRemotePanel { + type Message = &'static str; + type Properties = RemotePanel; + + fn create(_ctx: &yew::Context<Self>) -> Self { + Self {} + } + + fn view(&self, ctx: &yew::Context<Self>) -> yew::Html { + let props = ctx.props(); + if props.status.is_none() { + return Column::new() + .padding(4) + .class(css::FlexFit) + .class(css::AlignItems::Center) + .class(css::JustifyContent::Center) + .with_child(Fa::new("").class("pwt-loading-icon")) + .into(); + } + let status = props.status.clone().unwrap(); + + let (remote_icon, remote_text, failure) = match (status.failed_remotes, status.remotes) { + (0, 0) => ( + Status::Warning.to_fa_icon(), + tr!("No remotes configured."), + false, + ), + (0, _) => ( + Status::Success.to_fa_icon(), + tr!("Could reach all remotes."), + false, + ), + (failed, _) => ( + Status::Error.to_fa_icon(), + tr!("{0} remotes failed to reach.", failed), + true, + ), + }; + Column::new() + .tabindex(if failure { 0 } else { -1 }) + .padding(4) + .class(css::FlexFit) + .class(css::AlignItems::Center) + .class(css::JustifyContent::Center) + .style("cursor", failure.then_some("pointer")) + .gap(2) + .with_child(remote_icon.large_4x()) + .with_child(Container::new().with_child(remote_text)) + .into() + } +} -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel