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 843061FF164
	for <inbox@lore.proxmox.com>; Fri, 28 Feb 2025 16:25:52 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id E71191263E;
	Fri, 28 Feb 2025 16:25:50 +0100 (CET)
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Fri, 28 Feb 2025 16:17:58 +0100
Message-Id: <20250228151803.158984-22-s.hanreich@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250228151803.158984-1-s.hanreich@proxmox.com>
References: <20250228151803.158984-1-s.hanreich@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.225 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
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 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
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [mod.rs]
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 08/13] ui: sdn: add
 RouterTable component
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>

This table shows an overview of EVPN controllers on all connected
remotes. Those routers can then be used for creating new EVPN zones.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 ui/src/sdn/evpn/mod.rs          |   3 +
 ui/src/sdn/evpn/router_table.rs | 125 ++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+)
 create mode 100644 ui/src/sdn/evpn/router_table.rs

diff --git a/ui/src/sdn/evpn/mod.rs b/ui/src/sdn/evpn/mod.rs
index 0745f52..996ab25 100644
--- a/ui/src/sdn/evpn/mod.rs
+++ b/ui/src/sdn/evpn/mod.rs
@@ -1,2 +1,5 @@
+mod router_table;
+pub use router_table::RouterTable;
+
 mod vrf_tree;
 pub use vrf_tree::VrfTree;
diff --git a/ui/src/sdn/evpn/router_table.rs b/ui/src/sdn/evpn/router_table.rs
new file mode 100644
index 0000000..8f2892c
--- /dev/null
+++ b/ui/src/sdn/evpn/router_table.rs
@@ -0,0 +1,125 @@
+use std::cmp::Ordering;
+use std::rc::Rc;
+
+use pdm_client::types::{ListController, SdnObjectState};
+use pwt::props::{ContainerBuilder, ExtractPrimaryKey, WidgetBuilder};
+use pwt::state::{Selection, Store};
+use pwt::widget::data_table::{DataTable, DataTableColumn, DataTableHeader};
+use pwt::widget::{Column, Container};
+use pwt::{css, tr};
+use serde::{Deserialize, Serialize};
+use yew::virtual_dom::{Key, VComp, VNode};
+use yew::{Component, Context, Html, Properties};
+
+#[derive(PartialEq, Properties)]
+pub struct RouterTable {
+    controllers: Rc<Vec<ListController>>,
+}
+
+impl RouterTable {
+    pub fn new(controllers: Rc<Vec<ListController>>) -> Self {
+        yew::props!(Self { controllers })
+    }
+}
+
+impl From<RouterTable> for VNode {
+    fn from(val: RouterTable) -> Self {
+        let comp = VComp::new::<RouterTableComponent>(Rc::new(val), None);
+        VNode::from(comp)
+    }
+}
+
+pub enum RouterTableMsg {
+    SelectionChange,
+}
+
+#[derive(Clone, PartialEq, Serialize, Deserialize)]
+pub struct RouterEntry {
+    pub remote: String,
+    pub controller: String,
+    pub asn: u32,
+    pub state: Option<SdnObjectState>,
+}
+
+impl ExtractPrimaryKey for RouterEntry {
+    fn extract_key(&self) -> Key {
+        Key::from(format!("{}/{}", self.remote, self.controller))
+    }
+}
+
+pub struct RouterTableComponent {
+    store: Store<RouterEntry>,
+    selection: Selection,
+}
+
+fn remote_sorter(a: &RouterEntry, b: &RouterEntry) -> Ordering {
+    a.remote.cmp(&b.remote)
+}
+
+impl RouterTableComponent {
+    fn columns() -> Rc<Vec<DataTableHeader<RouterEntry>>> {
+        Rc::new(vec![
+            DataTableColumn::new(tr!("Remote"))
+                .render(|item: &RouterEntry| item.remote.as_str().into())
+                .sorter(remote_sorter)
+                .into(),
+            DataTableColumn::new(tr!("Name"))
+                .render(|item: &RouterEntry| item.controller.as_str().into())
+                .sorter(|a: &RouterEntry, b: &RouterEntry| a.controller.cmp(&b.controller))
+                .into(),
+            DataTableColumn::new(tr!("ASN"))
+                .render(|item: &RouterEntry| item.asn.into())
+                .sorter(|a: &RouterEntry, b: &RouterEntry| a.asn.cmp(&b.asn))
+                .into(),
+        ])
+    }
+}
+
+impl Component for RouterTableComponent {
+    type Properties = RouterTable;
+    type Message = RouterTableMsg;
+
+    fn create(ctx: &Context<Self>) -> Self {
+        let store = Store::new();
+        store.set_sorter(remote_sorter);
+
+        let selection =
+            Selection::new().on_select(ctx.link().callback(|_| Self::Message::SelectionChange));
+
+        Self { store, selection }
+    }
+
+    fn changed(&mut self, ctx: &Context<Self>, old_props: &Self::Properties) -> bool {
+        if !Rc::ptr_eq(&ctx.props().controllers, &old_props.controllers) {
+            self.store.set_data(
+                ctx.props()
+                    .controllers
+                    .iter()
+                    .map(|elem| RouterEntry {
+                        remote: elem.remote.clone(),
+                        controller: elem.controller.controller.clone(),
+                        asn: elem
+                            .controller
+                            .asn_pending()
+                            .expect("EVPN controller has an ASN"),
+                        state: elem.controller.state,
+                    })
+                    .collect(),
+            );
+            self.store.set_sorter(remote_sorter);
+        }
+
+        true
+    }
+
+    fn view(&self, _ctx: &Context<Self>) -> Html {
+        let table = DataTable::new(Self::columns(), self.store.clone())
+            .selection(self.selection.clone())
+            .class("pwt-flex-fit");
+
+        Container::new()
+            .class(css::FlexFit)
+            .with_child(Column::new().class(css::FlexFit).gap(2).with_child(table))
+            .into()
+    }
+}
-- 
2.39.5


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