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 131611FF173 for ; Mon, 13 Jan 2025 16:46:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 582E75020; Mon, 13 Jan 2025 16:46:28 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Mon, 13 Jan 2025 16:45:49 +0100 Message-Id: <20250113154550.3462139-11-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250113154550.3462139-1-d.csapak@proxmox.com> References: <20250113154550.3462139-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 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 8/9] ui: widget: add remote endpoint selector 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" this is a widget to select a specific endpoint, showing the hostname as the value. This can be useful in situations where we wan to explicitely select an endpoint, e.g. remote migration. Signed-off-by: Dominik Csapak --- ui/src/widget/mod.rs | 2 + ui/src/widget/remote_endpoint_selector.rs | 103 ++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 ui/src/widget/remote_endpoint_selector.rs diff --git a/ui/src/widget/mod.rs b/ui/src/widget/mod.rs index b885d1b..ee9e799 100644 --- a/ui/src/widget/mod.rs +++ b/ui/src/widget/mod.rs @@ -21,3 +21,5 @@ pub use search_box::SearchBox; mod remote_selector; pub use remote_selector::RemoteSelector; + +mod remote_endpoint_selector; diff --git a/ui/src/widget/remote_endpoint_selector.rs b/ui/src/widget/remote_endpoint_selector.rs new file mode 100644 index 0000000..779d98c --- /dev/null +++ b/ui/src/widget/remote_endpoint_selector.rs @@ -0,0 +1,103 @@ +use std::rc::Rc; + +use wasm_bindgen::UnwrapThrowExt; +use yew::{ + html::{IntoEventCallback, IntoPropValue}, + AttrValue, Callback, Component, Properties, +}; + +use pwt::{ + props::{FieldBuilder, WidgetBuilder}, + widget::form::Combobox, +}; +use pwt_macros::{builder, widget}; + +use crate::RemoteList; + +#[widget(comp=PdmEndpointSelector, @input)] +#[derive(Clone, Properties, PartialEq)] +#[builder] +pub struct EndpointSelector { + /// The default value + #[builder(IntoPropValue, into_prop_value)] + #[prop_or_default] + pub default: Option, + + /// Change callback + #[builder_cb(IntoEventCallback, into_event_callback, String)] + #[prop_or_default] + pub on_change: Option>, + + /// The remote to list Endpoints from + #[builder(IntoPropValue, into_prop_value)] + #[prop_or_default] + pub remote: AttrValue, +} + +impl EndpointSelector { + pub fn new(remote: AttrValue) -> Self { + yew::props!(Self { remote }) + } +} + +pub struct PdmEndpointSelector { + endpoints: Rc>, +} + +impl PdmEndpointSelector { + fn update_endpoint_list(&mut self, ctx: &yew::Context) { + let (remotes, _): (RemoteList, _) = ctx + .link() + .context(ctx.link().callback(|_| ())) + .unwrap_throw(); + + let remote_id = ctx.props().remote.as_str(); + + for remote in remotes.iter() { + if remote.id != remote_id { + continue; + } + + let endpoints = remote + .nodes + .iter() + .map(|endpoint| AttrValue::from(endpoint.hostname.clone())) + .collect(); + self.endpoints = Rc::new(endpoints); + break; + } + } +} + +impl Component for PdmEndpointSelector { + type Message = (); + type Properties = EndpointSelector; + + fn create(ctx: &yew::Context) -> Self { + let mut this = Self { + endpoints: Rc::new(Vec::new()), + }; + + this.update_endpoint_list(ctx); + this + } + + fn changed(&mut self, ctx: &yew::Context, old_props: &Self::Properties) -> bool { + if ctx.props().remote != old_props.remote { + log::info!("{} {}", ctx.props().remote, old_props.remote); + self.update_endpoint_list(ctx); + } + true + } + + fn view(&self, ctx: &yew::Context) -> yew::Html { + let props = ctx.props(); + Combobox::new() + .with_std_props(&props.std_props) + .with_input_props(&props.input_props) + .on_change(props.on_change.clone()) + .default(props.default.clone()) + .items(self.endpoints.clone()) + .into() + } +} -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel