From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 67D911FF183 for ; Wed, 10 Sep 2025 15:11:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D6AD3217A9; Wed, 10 Sep 2025 15:11:55 +0200 (CEST) From: Stefan Hanreich To: pdm-devel@lists.proxmox.com Date: Wed, 10 Sep 2025 15:11:21 +0200 Message-ID: <20250910131123.235563-1-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.182 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 1/1] sdn: zone tree: add external links to zones 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" Add a new column to the zone tree that shows external links to SDN zones. In order to avoid issues similar to the resource tree, this component needs to re-create the columns on every draw, as well as re-draw itself whenever the RemoteList stored in the global context changes. Signed-off-by: Stefan Hanreich --- ui/src/sdn/zone_tree.rs | 57 ++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/ui/src/sdn/zone_tree.rs b/ui/src/sdn/zone_tree.rs index 0cda1a4..780c0bd 100644 --- a/ui/src/sdn/zone_tree.rs +++ b/ui/src/sdn/zone_tree.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use std::rc::Rc; use yew::virtual_dom::{Key, VComp, VNode}; -use yew::{Html, Properties}; +use yew::{html, ContextHandle, Html, Properties}; use pdm_api_types::resource::{ PveSdnResource, RemoteResources, ResourceType, SdnStatus, SdnZoneResource, @@ -12,7 +12,7 @@ use pdm_api_types::resource::{ use pdm_client::types::Resource; use proxmox_yew_comp::{LoadableComponent, LoadableComponentContext, LoadableComponentMaster}; use pwt::props::EventSubscriber; -use pwt::widget::{Button, Toolbar}; +use pwt::widget::{ActionIcon, Button, Toolbar}; use pwt::{ css, css::FontColor, @@ -25,7 +25,7 @@ use pwt::{ }, }; -use crate::pdm_client; +use crate::{get_deep_url, pdm_client, RemoteList}; #[derive(PartialEq, Properties)] pub struct ZoneTree {} @@ -92,6 +92,7 @@ impl ExtractPrimaryKey for ZoneTreeEntry { pub enum ZoneTreeMsg { LoadFinished(Vec), + RemoteListChanged(RemoteList), Reload, } @@ -99,7 +100,7 @@ pub struct ZoneTreeComponent { store: TreeStore, selection: Selection, remote_errors: Vec, - columns: Rc>>, + _context_listener: ContextHandle, } fn default_sorter(a: &ZoneTreeEntry, b: &ZoneTreeEntry) -> Ordering { @@ -107,7 +108,12 @@ fn default_sorter(a: &ZoneTreeEntry, b: &ZoneTreeEntry) -> Ordering { } impl ZoneTreeComponent { - fn columns(store: TreeStore) -> Rc>> { + fn columns( + ctx: &LoadableComponentContext, + store: TreeStore, + ) -> Rc>> { + let link = ctx.link().clone(); + Rc::new(vec![ DataTableColumn::new(tr!("Name")) .tree_column(store) @@ -151,6 +157,30 @@ impl ZoneTreeComponent { row.into() }) .into(), + DataTableColumn::new(tr!("Actions")) + .width("80px") + .justify("right") + .render(move |entry: &ZoneTreeEntry| { + let url = match entry { + ZoneTreeEntry::Root + | ZoneTreeEntry::Node(_, _) + | ZoneTreeEntry::Remote(_) => None, + ZoneTreeEntry::Zone(zone_data) => { + let id = format!("sdn/{}/{}", zone_data.node, zone_data.name); + get_deep_url(link.yew_link(), &zone_data.remote, None, &id) + } + }; + + match url { + Some(url) => ActionIcon::new("fa fa-external-link") + .on_activate(move |_| { + let _ = web_sys::window().unwrap().open_with_url(&url.href()); + }) + .into(), + None => html! {}, + } + }) + .into(), ]) } } @@ -219,17 +249,23 @@ impl LoadableComponent for ZoneTreeComponent { type Message = ZoneTreeMsg; type ViewState = (); - fn create(_ctx: &LoadableComponentContext) -> Self { + fn create(ctx: &LoadableComponentContext) -> Self { let store = TreeStore::new().view_root(false); store.set_sorter(default_sorter); let selection = Selection::new(); + let (_, _context_listener) = ctx + .link() + .yew_link() + .context(ctx.link().callback(Self::Message::RemoteListChanged)) + .expect("No Remote list context provided"); + Self { store: store.clone(), selection, remote_errors: Vec::new(), - columns: Self::columns(store), + _context_listener, } } @@ -261,6 +297,9 @@ impl LoadableComponent for ZoneTreeComponent { return true; } + Self::Message::RemoteListChanged(_list) => { + return true; + } Self::Message::Reload => { ctx.link().send_reload(); } @@ -283,8 +322,8 @@ impl LoadableComponent for ZoneTreeComponent { ) } - fn main_view(&self, _ctx: &LoadableComponentContext) -> yew::Html { - let table = DataTable::new(self.columns.clone(), self.store.clone()) + fn main_view(&self, ctx: &LoadableComponentContext) -> yew::Html { + let table = DataTable::new(Self::columns(ctx, self.store.clone()), self.store.clone()) .selection(self.selection.clone()) .striped(false) .class(css::FlexFit); -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel