public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 08/13] ui: sdn: add RouterTable component
Date: Fri, 28 Feb 2025 16:17:58 +0100	[thread overview]
Message-ID: <20250228151803.158984-22-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250228151803.158984-1-s.hanreich@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


  parent reply	other threads:[~2025-02-28 15:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 15:17 [pdm-devel] [RFC proxmox{-api-types, -yew-comp, -datacenter-manager} 00/26] Add initial SDN / EVPN integration Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 01/12] sdn: add list/create zone endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 02/12] sdn: generate zones endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 03/12] sdn: add list/create vnet endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 04/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 05/12] sdn: add list/create controller endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 06/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 07/12] sdn: add acquire/release lock endpoints Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 08/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 09/12] sdn: add apply configuration endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 10/12] sdn: generate " Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 11/12] tasks: add helper for querying successfully finished tasks Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-api-types 12/12] sdn: add helpers for pending values Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-yew-comp 1/1] sdn: add descriptions for sdn tasks Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 01/13] server: add locked sdn client and helper methods Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 02/13] api: sdn: add list_zones endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 03/13] api: sdn: add create_zone endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 04/13] api: sdn: add list_vnets endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 05/13] api: sdn: add create_vnet endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 06/13] api: sdn: add list_controllers endpoint Stefan Hanreich
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 07/13] ui: add VrfTree component Stefan Hanreich
2025-02-28 15:17 ` Stefan Hanreich [this message]
2025-02-28 15:17 ` [pdm-devel] [PATCH proxmox-datacenter-manager 09/13] ui: sdn: add AddVnetWindow component Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 10/13] ui: sdn: add AddZoneWindow component Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 11/13] ui: sdn: add EvpnPanel Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 12/13] ui: sdn: add EvpnPanel to main menu Stefan Hanreich
2025-02-28 15:18 ` [pdm-devel] [PATCH proxmox-datacenter-manager 13/13] pve: sdn: add descriptions for sdn tasks Stefan Hanreich

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=20250228151803.158984-22-s.hanreich@proxmox.com \
    --to=s.hanreich@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