From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager] ui: snapshots: use constructor instead of custom `From` implementation
Date: Tue, 26 May 2026 11:31:17 +0200 [thread overview]
Message-ID: <20260526093123.1383837-1-d.csapak@proxmox.com> (raw)
having it return a dialog when a specific property is set instead of an
embedded list is better done via a custom constructor. This way we don't
have to passthrough the properties of the dialog we need, we save the
extra property to differentiate, and the logic is not hidden inside the
`From` implementation.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/guests.rs | 2 +-
ui/src/pve/lxc/mod.rs | 1 -
ui/src/pve/qemu/mod.rs | 1 -
ui/src/widget/snapshot_window.rs | 42 +++++++++-----------------------
4 files changed, 13 insertions(+), 33 deletions(-)
diff --git a/ui/src/guests.rs b/ui/src/guests.rs
index decfffa9..c49eaff5 100644
--- a/ui/src/guests.rs
+++ b/ui/src/guests.rs
@@ -575,7 +575,7 @@ impl LoadableComponent for GuestPanelComp {
.into(),
),
ViewState::Snapshots(remote, guest_info) => Some(
- SnapshotWindow::new(remote.clone(), *guest_info)
+ SnapshotWindow::dialog(remote.clone(), *guest_info)
.on_close(ctx.link().change_view_callback(|_| None))
.into(),
),
diff --git a/ui/src/pve/lxc/mod.rs b/ui/src/pve/lxc/mod.rs
index a0ce86aa..4569a5ee 100644
--- a/ui/src/pve/lxc/mod.rs
+++ b/ui/src/pve/lxc/mod.rs
@@ -182,7 +182,6 @@ impl yew::Component for LxcPanelComp {
vmid,
},
)
- .embedded(true)
.into()
}
},
diff --git a/ui/src/pve/qemu/mod.rs b/ui/src/pve/qemu/mod.rs
index 1d2ffa7c..b1a5c15d 100644
--- a/ui/src/pve/qemu/mod.rs
+++ b/ui/src/pve/qemu/mod.rs
@@ -162,7 +162,6 @@ impl yew::Component for QemuPanelComp {
vmid,
},
)
- .embedded(true)
.into()
}
},
diff --git a/ui/src/widget/snapshot_window.rs b/ui/src/widget/snapshot_window.rs
index 4630759b..7e22ed79 100644
--- a/ui/src/widget/snapshot_window.rs
+++ b/ui/src/widget/snapshot_window.rs
@@ -11,9 +11,8 @@ use std::rc::Rc;
use anyhow::{bail, Error};
use serde_json::json;
-use yew::html::IntoEventCallback;
use yew::virtual_dom::{Key, VComp, VNode};
-use yew::{Callback, Properties};
+use yew::Properties;
use proxmox_client::ApiResponseData;
use proxmox_yew_comp::{
@@ -139,16 +138,6 @@ pub struct SnapshotWindow {
/// Which guest to manage snapshots for.
pub guest_info: GuestInfo,
-
- /// Render the list inline (for embedding as a tab) instead of as a modal dialog.
- #[prop_or_default]
- #[builder]
- pub embedded: bool,
-
- /// Close callback (only used in modal mode).
- #[prop_or_default]
- #[builder_cb(IntoEventCallback, into_event_callback, ())]
- pub on_close: Option<Callback<()>>,
}
impl SnapshotWindow {
@@ -158,31 +147,24 @@ impl SnapshotWindow {
guest_info,
})
}
-}
-impl From<SnapshotWindow> for VNode {
- fn from(val: SnapshotWindow) -> Self {
- let embedded = val.embedded;
- let on_close = val.on_close.clone();
- let title = tr!("Snapshots - {0}", val.guest_info.vmid);
-
- // The master renders a Column/page (toolbar + table + dialogs), not a dialog. Embedded as
- // a detail-panel tab it is dropped in inline; as a standalone window it is wrapped in a
- // Dialog that carries the title and the close callback.
- let master: VNode =
- VComp::new::<LoadableComponentMaster<PdmSnapshotWindow>>(Rc::new(val), None).into();
- if embedded {
- return master;
- }
+ /// Returns the snapshot component within a dialog
+ pub fn dialog(remote: impl Into<AttrValue>, guest_info: GuestInfo) -> Dialog {
+ let title = tr!("Snapshots - {0}", guest_info.vmid);
+ let snapshot_comp = Self::new(remote, guest_info);
Dialog::new(title)
.min_width(720)
.min_height(440)
.max_height("90vh")
.resizable(true)
- .on_close(on_close)
- .with_child(master)
- .into()
+ .with_child(snapshot_comp)
+ }
+}
+
+impl From<SnapshotWindow> for VNode {
+ fn from(val: SnapshotWindow) -> Self {
+ VComp::new::<LoadableComponentMaster<PdmSnapshotWindow>>(Rc::new(val), None).into()
}
}
--
2.47.3
next reply other threads:[~2026-05-26 9:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 9:31 Dominik Csapak [this message]
2026-05-26 9:50 ` applied: [PATCH datacenter-manager] ui: snapshots: use constructor instead of custom `From` implementation Lukas Wagner
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=20260526093123.1383837-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox