From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager v2 3/4] ui: widget: add remote endpoint selector
Date: Tue, 14 Jan 2025 12:21:39 +0100 [thread overview]
Message-ID: <20250114112140.1898658-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250114112140.1898658-1-d.csapak@proxmox.com>
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 explicitly
select an endpoint, e.g. remote migration.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* fix typo in commit message
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<AttrValue>,
+
+ /// Change callback
+ #[builder_cb(IntoEventCallback, into_event_callback, String)]
+ #[prop_or_default]
+ pub on_change: Option<Callback<String>>,
+
+ /// 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<Vec<AttrValue>>,
+}
+
+impl PdmEndpointSelector {
+ fn update_endpoint_list(&mut self, ctx: &yew::Context<Self>) {
+ 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>) -> Self {
+ let mut this = Self {
+ endpoints: Rc::new(Vec::new()),
+ };
+
+ this.update_endpoint_list(ctx);
+ this
+ }
+
+ fn changed(&mut self, ctx: &yew::Context<Self>, 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<Self>) -> 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
next prev parent reply other threads:[~2025-01-14 11:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-14 11:21 [pdm-devel] [PATCH datacenter-manager v2 0/4] remote migration: make target endpoint selectable Dominik Csapak
2025-01-14 11:21 ` [pdm-devel] [PATCH datacenter-manager v2 1/4] pdm-client: add cluster status method Dominik Csapak
2025-01-14 11:21 ` [pdm-devel] [PATCH datacenter-manager v2 2/4] pdm-client: add target-endpoint parameter to remote migration methods Dominik Csapak
2025-01-14 11:21 ` Dominik Csapak [this message]
2025-01-14 11:21 ` [pdm-devel] [PATCH datacenter-manager v2 4/4] ui: migrate: make target endpoint selectable for remote migration Dominik Csapak
2025-01-14 13:25 ` [pdm-devel] applied: [PATCH datacenter-manager v2 0/4] remote migration: make target endpoint selectable Dietmar Maurer
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=20250114112140.1898658-4-d.csapak@proxmox.com \
--to=d.csapak@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.