From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 03/10] ui: views: add options panel for editing widgets
Date: Thu, 26 Nov 2026 15:49:16 +0100 [thread overview]
Message-ID: <20261126145410.3011676-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261126145410.3011676-1-d.csapak@proxmox.com>
so users can change the options of an existing widget, instead of
having to remove it and add another variant from the menu. This also
makes it possible to set a custom title, which was only possible by
editing the layout manually.
In edit mode, each widget now has a pencil button that opens a panel
on the right side with the widget's options. Changes are applied to
the layout immediately, so the widget acts as a live preview, and are
saved or reverted together with the rest of the layout changes.
I opted for a dedicated button instead of opening the options when
clicking the widget, since in edit mode a pointer down on the widget
already starts dragging it.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/view.rs | 2 +
ui/src/dashboard/view/row_element.rs | 29 ++-
ui/src/dashboard/view/row_view.rs | 87 +++++++-
ui/src/dashboard/view/widget_options.rs | 281 ++++++++++++++++++++++++
4 files changed, 394 insertions(+), 5 deletions(-)
create mode 100644 ui/src/dashboard/view/widget_options.rs
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index 8d8f83a9..c46a85b0 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -51,6 +51,8 @@ pub use row_view::RowView;
mod row_element;
+mod widget_options;
+
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum EditingMessage {
Start,
diff --git a/ui/src/dashboard/view/row_element.rs b/ui/src/dashboard/view/row_element.rs
index 01d868e6..40686160 100644
--- a/ui/src/dashboard/view/row_element.rs
+++ b/ui/src/dashboard/view/row_element.rs
@@ -3,7 +3,7 @@ use yew::html::IntoEventCallback;
use pwt::css;
use pwt::prelude::*;
use pwt::props::RenderFn;
-use pwt::widget::{ActionIcon, Card, Fa, Panel, Row};
+use pwt::widget::{ActionIcon, Card, Fa, Panel, Row, Tooltip};
use pwt_macros::{builder, widget};
use pdm_api_types::views::RowWidget;
@@ -23,6 +23,11 @@ pub struct RowElement {
#[prop_or_default]
is_dragging: bool,
+ #[builder]
+ #[prop_or_default]
+ /// Highlights the element, e.g. while its options are edited
+ selected: bool,
+
#[builder_cb(IntoEventCallback, into_event_callback, ())]
#[prop_or_default]
on_remove: Option<Callback<()>>,
@@ -30,6 +35,10 @@ pub struct RowElement {
#[builder_cb(IntoEventCallback, into_event_callback, u32)]
#[prop_or_default]
on_flex_change: Option<Callback<u32>>,
+
+ #[builder_cb(IntoEventCallback, into_event_callback, ())]
+ #[prop_or_default]
+ on_edit: Option<Callback<()>>,
}
impl RowElement {
@@ -84,6 +93,7 @@ impl Component for RowElementComp {
.padding(2)
.style("z-index", "10")
.class(css::AlignItems::Center)
+ .class(css::Display::Flex)
.with_child(Fa::new("bars").style("cursor", "grab").padding_end(1))
.with_child(tr!("Flex"))
.with_child(
@@ -95,6 +105,17 @@ impl Component for RowElementComp {
ActionIcon::new("fa fa-plus")
.on_activate(ctx.link().callback(|_| Msg::FlexIncrease)),
)
+ .with_child(
+ Tooltip::new(ActionIcon::new("fa fa-pencil").on_activate({
+ let on_edit = props.on_edit.clone();
+ move |_| {
+ if let Some(on_edit) = &on_edit {
+ on_edit.emit(());
+ }
+ }
+ }))
+ .tip(tr!("Edit Options")),
+ )
.with_child(ActionIcon::new("fa fa-times").on_activate({
let on_remove = props.on_remove.clone();
move |_| {
@@ -109,6 +130,12 @@ impl Component for RowElementComp {
.listeners(&props.listeners)
.border(true)
.class(props.is_dragging.then_some("dragging-item"))
+ .style(
+ "outline",
+ props
+ .selected
+ .then_some("2px solid var(--pwt-color-primary)"),
+ )
.attribute("draggable", if props.edit_mode { "true" } else { "false" })
.style("position", "relative")
.with_child(widget)
diff --git a/ui/src/dashboard/view/row_view.rs b/ui/src/dashboard/view/row_view.rs
index 535230c9..2f94b4d3 100644
--- a/ui/src/dashboard/view/row_view.rs
+++ b/ui/src/dashboard/view/row_view.rs
@@ -18,6 +18,7 @@ use pwt_macros::builder;
use crate::dashboard::view::EditingMessage;
use crate::dashboard::view::row_element::RowElement;
+use crate::dashboard::view::widget_options::WidgetOptions;
use pdm_api_types::remotes::RemoteType;
use pdm_api_types::views::{
@@ -81,6 +82,9 @@ pub enum Msg {
AddWidget(Position, WidgetType),
RemoveWidget(Position),
MoveRow(usize, MoveDirection), // idx
+ EditWidget(Position), // key
+ CloseWidgetOptions,
+ UpdateWidget(Position, RowWidget), // key
HandleEditMessages,
}
@@ -99,6 +103,7 @@ pub struct RowViewComp {
drag_timeout: Option<Timeout>,
next_row_indices: HashMap<usize, usize>, // for saving the max index for new widgets
+ edited_widget: Option<Position>, // key of the widget whose options are shown
node_ref: NodeRef,
edit_mode: bool,
@@ -150,6 +155,7 @@ impl Component for RowViewComp {
dragging_target: None,
drag_timeout: None,
next_row_indices,
+ edited_widget: None,
node_ref: NodeRef::default(),
edit_mode: false,
_editing_observer,
@@ -159,7 +165,10 @@ impl Component for RowViewComp {
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::RemoveRow(idx) => {
- self.current_layout.remove(idx);
+ let row = self.current_layout.remove(idx);
+ if row.iter().any(|(key, _)| self.edited_widget == Some(*key)) {
+ self.edited_widget = None;
+ }
}
Msg::AddRow => {
self.current_layout.push(Vec::new());
@@ -246,7 +255,10 @@ impl Component for RowViewComp {
);
}
Msg::RemoveWidget(coords) => {
- self.current_layout[coords.row].remove(coords.item);
+ let (key, _) = self.current_layout[coords.row].remove(coords.item);
+ if self.edited_widget == Some(key) {
+ self.edited_widget = None;
+ }
}
Msg::MoveRow(old, direction) => {
let mut new_layout = self.current_layout.clone();
@@ -258,6 +270,25 @@ impl Component for RowViewComp {
new_layout.insert(new_idx, row);
self.current_layout = new_layout;
}
+ Msg::EditWidget(key) => {
+ self.edited_widget = match self.edited_widget {
+ Some(current) if current == key => None,
+ _ => Some(key),
+ };
+ }
+ Msg::CloseWidgetOptions => {
+ self.edited_widget = None;
+ }
+ Msg::UpdateWidget(key, widget) => {
+ if let Some((_, item)) = self
+ .current_layout
+ .iter_mut()
+ .flatten()
+ .find(|(position, _)| *position == key)
+ {
+ *item = widget;
+ }
+ }
Msg::HandleEditMessages => {
let props = ctx.props();
let state = match props.editing_state.clone() {
@@ -306,6 +337,7 @@ impl Component for RowViewComp {
self.dragging = None;
self.dragging_target = None;
self.drag_timeout = None;
+ self.edited_widget = None;
}
}
}
@@ -318,6 +350,7 @@ impl Component for RowViewComp {
let new_layout = extract_row_layout(&props.rows);
if new_layout != self.current_layout {
self.current_layout = new_layout;
+ self.edited_widget = None;
}
}
@@ -333,7 +366,6 @@ impl Component for RowViewComp {
let layout = self.new_layout.as_ref().unwrap_or(&self.current_layout);
let mut row = Row::new()
.padding_x(2)
- .class("pwt-content-spacer-colors")
.class(css::FlexDirection::Row)
.class(css::FlexWrap::Wrap);
@@ -377,6 +409,7 @@ impl Component for RowViewComp {
.margin_bottom(4)
.edit_mode(self.edit_mode)
.is_dragging(self.dragging_target == Some(current_coords))
+ .selected(self.edit_mode && self.edited_widget == Some(*coords))
.key(format!("item-{}-{}", coords.row, coords.item))
.style("flex", flex_style)
.style("touch-action", self.edit_mode.then_some("none"))
@@ -388,6 +421,10 @@ impl Component for RowViewComp {
ctx.link()
.callback(move |flex| Msg::EditFlex(current_coords, flex)),
)
+ .on_edit({
+ let key = *coords;
+ ctx.link().callback(move |_| Msg::EditWidget(key))
+ })
.ondragstart(ctx.link().callback(move |event: DragEvent| {
let data = event.data_transfer().unwrap();
let _ = data.clear_data();
@@ -532,7 +569,49 @@ impl Component for RowViewComp {
),
);
}
- view.add_child(row);
+
+ let widget_options = self
+ .edited_widget
+ .filter(|_| self.edit_mode)
+ .and_then(|key| {
+ layout
+ .iter()
+ .flatten()
+ .find(|(position, _)| *position == key)
+ })
+ .map(|(key, widget)| {
+ let key = *key;
+ Container::new()
+ .key(format!("options-{}-{}", key.row, key.item))
+ .margin_end(4)
+ .margin_bottom(4)
+ .style("flex", "0 0 auto")
+ .style("width", "400px")
+ .style("max-width", "40%")
+ // keep the options visible while scrolling through long layouts
+ .style("position", "sticky")
+ .style("top", "0")
+ .with_child(
+ WidgetOptions::new(widget.clone())
+ .on_change(
+ ctx.link()
+ .callback(move |widget| Msg::UpdateWidget(key, widget)),
+ )
+ .on_close(ctx.link().callback(|_| Msg::CloseWidgetOptions)),
+ )
+ });
+
+ view.add_child(
+ Row::new()
+ .class(css::AlignItems::Start)
+ .class("pwt-content-spacer-colors")
+ .with_child(
+ row.key("rows")
+ .class(css::Flex::Fill)
+ .style("min-width", "0"),
+ )
+ .with_optional_child(widget_options),
+ );
view.into_html_with_ref(self.node_ref.clone())
}
}
diff --git a/ui/src/dashboard/view/widget_options.rs b/ui/src/dashboard/view/widget_options.rs
new file mode 100644
index 00000000..9418d67f
--- /dev/null
+++ b/ui/src/dashboard/view/widget_options.rs
@@ -0,0 +1,281 @@
+use yew::html::IntoEventCallback;
+use yew::virtual_dom::{VComp, VNode};
+
+use pwt::prelude::*;
+use pwt::widget::form::{Checkbox, Combobox, DisplayField, Field};
+use pwt::widget::{ActionIcon, InputPanel, Panel, Tooltip};
+use pwt_macros::builder;
+
+use pdm_api_types::remotes::RemoteType;
+use pdm_api_types::resource::GuestType;
+use pdm_api_types::views::{
+ LeaderboardType, NodeResourceType, RowWidget, TaskSummaryGrouping, WidgetType,
+};
+
+/// Returns the name of the kind of widget, independent of its options.
+pub fn widget_type_name(widget_type: &WidgetType) -> String {
+ match widget_type {
+ WidgetType::Nodes { .. } => tr!("Node Panel"),
+ WidgetType::Guests { .. } => tr!("Guest Panel"),
+ WidgetType::PbsDatastores => tr!("PBS Datastores"),
+ WidgetType::Remotes { .. } => tr!("Remote Panel"),
+ WidgetType::Subscription => tr!("Subscription Panel"),
+ WidgetType::Sdn => tr!("SDN Panel"),
+ WidgetType::Leaderboard { .. } => tr!("Leaderboard"),
+ WidgetType::TaskSummary { .. } => tr!("Task Summary"),
+ WidgetType::ResourceTree => tr!("Resource Tree"),
+ WidgetType::NodeResourceGauge { .. } => tr!("Resource Usage"),
+ WidgetType::Map => tr!("Map"),
+ WidgetType::UnknownWidget { widget_type, .. } => {
+ tr!("Unknown Widget of type '{0}'", widget_type)
+ }
+ }
+}
+
+#[derive(Properties, PartialEq)]
+#[builder]
+/// Shows and edits the options of a single dashboard widget.
+///
+/// Every change is emitted immediately via `on_change`, so that the dashboard can show a live
+/// preview of the widget.
+pub struct WidgetOptions {
+ widget: RowWidget,
+
+ #[builder_cb(IntoEventCallback, into_event_callback, RowWidget)]
+ #[prop_or_default]
+ on_change: Option<Callback<RowWidget>>,
+
+ #[builder_cb(IntoEventCallback, into_event_callback, ())]
+ #[prop_or_default]
+ on_close: Option<Callback<()>>,
+}
+
+impl WidgetOptions {
+ pub fn new(widget: RowWidget) -> Self {
+ yew::props!(Self { widget })
+ }
+}
+
+impl From<WidgetOptions> for VNode {
+ fn from(val: WidgetOptions) -> Self {
+ let comp = VComp::new::<WidgetOptionsComp>(std::rc::Rc::new(val), None);
+ VNode::from(comp)
+ }
+}
+
+pub struct WidgetOptionsComp;
+
+impl Component for WidgetOptionsComp {
+ type Message = ();
+ type Properties = WidgetOptions;
+
+ fn create(_ctx: &Context<Self>) -> Self {
+ Self
+ }
+
+ fn view(&self, ctx: &Context<Self>) -> Html {
+ let props = ctx.props();
+ let widget = &props.widget;
+ let on_change = props.on_change.clone().unwrap_or_default();
+
+ let set_title = on_change.reform({
+ let widget = widget.clone();
+ move |title: String| RowWidget {
+ title: (!title.is_empty()).then_some(title),
+ ..widget.clone()
+ }
+ });
+ let set_type = on_change.reform({
+ let widget = widget.clone();
+ move |r#type| RowWidget {
+ r#type,
+ ..widget.clone()
+ }
+ });
+
+ let mut panel = InputPanel::new()
+ .padding(4)
+ .with_field(
+ tr!("Type"),
+ DisplayField::new().value(widget_type_name(&widget.r#type)),
+ )
+ .with_field(
+ tr!("Title"),
+ Field::new()
+ .placeholder(tr!("Default"))
+ .value(widget.title.clone().unwrap_or_default())
+ .on_change(set_title),
+ );
+
+ match &widget.r#type {
+ WidgetType::Nodes { remote_type } => {
+ panel.add_field(
+ tr!("Remote Type"),
+ remote_type_selector(
+ *remote_type,
+ set_type.reform(|remote_type| WidgetType::Nodes { remote_type }),
+ ),
+ );
+ }
+ WidgetType::Guests { guest_type } => {
+ panel.add_field(
+ tr!("Guest Type"),
+ option_selector(
+ *guest_type,
+ vec![
+ (None, tr!("All Guests")),
+ (Some(GuestType::Qemu), tr!("Virtual Machines")),
+ (Some(GuestType::Lxc), tr!("Linux Containers")),
+ ],
+ set_type.reform(|guest_type| WidgetType::Guests { guest_type }),
+ ),
+ );
+ }
+ WidgetType::Remotes { show_wizard } => {
+ panel.add_field(
+ tr!("Show Add Buttons"),
+ Checkbox::new().checked(*show_wizard).on_change(
+ set_type.reform(|show_wizard| WidgetType::Remotes { show_wizard }),
+ ),
+ );
+ }
+ WidgetType::Leaderboard { leaderboard_type } => {
+ panel.add_field(
+ tr!("Ranking"),
+ option_selector(
+ *leaderboard_type,
+ vec![
+ (
+ LeaderboardType::GuestCpu,
+ tr!("Guests with Highest CPU Usage"),
+ ),
+ (
+ LeaderboardType::NodeCpu,
+ tr!("Nodes with Highest CPU Usage"),
+ ),
+ (
+ LeaderboardType::NodeMemory,
+ tr!("Nodes with Highest Memory Usage"),
+ ),
+ ],
+ set_type.reform(|leaderboard_type| WidgetType::Leaderboard {
+ leaderboard_type,
+ }),
+ ),
+ );
+ }
+ WidgetType::TaskSummary { grouping } => {
+ panel.add_field(
+ tr!("Grouping"),
+ option_selector(
+ *grouping,
+ vec![
+ (TaskSummaryGrouping::Category, tr!("By Category")),
+ (
+ TaskSummaryGrouping::Remote,
+ tr!("By Remote, Sorted by Failed Tasks"),
+ ),
+ ],
+ set_type.reform(|grouping| WidgetType::TaskSummary { grouping }),
+ ),
+ );
+ }
+ &WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ } => {
+ panel.add_field(
+ tr!("Resource"),
+ option_selector(
+ resource,
+ vec![
+ (None, tr!("All Resources")),
+ (Some(NodeResourceType::Cpu), tr!("CPU")),
+ (Some(NodeResourceType::Memory), tr!("Memory")),
+ (Some(NodeResourceType::Storage), tr!("Storage")),
+ ],
+ set_type.reform(move |resource| WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ }),
+ ),
+ );
+ panel.add_field(
+ tr!("Remote Type"),
+ remote_type_selector(
+ remote_type,
+ set_type.reform(move |remote_type| WidgetType::NodeResourceGauge {
+ resource,
+ remote_type,
+ }),
+ ),
+ );
+ }
+ WidgetType::PbsDatastores
+ | WidgetType::Subscription
+ | WidgetType::Sdn
+ | WidgetType::ResourceTree
+ | WidgetType::Map
+ | WidgetType::UnknownWidget { .. } => {}
+ }
+
+ Panel::new()
+ .border(true)
+ .title(tr!("Widget Options"))
+ .with_tool(
+ Tooltip::new(ActionIcon::new("fa fa-times").on_activate({
+ let on_close = props.on_close.clone();
+ move |_| {
+ if let Some(on_close) = &on_close {
+ on_close.emit(());
+ }
+ }
+ }))
+ .tip(tr!("Close")),
+ )
+ .with_child(panel)
+ .into()
+ }
+}
+
+fn remote_type_selector(
+ current: Option<RemoteType>,
+ on_select: Callback<Option<RemoteType>>,
+) -> Combobox {
+ option_selector(
+ current,
+ vec![
+ (None, tr!("All")),
+ (Some(RemoteType::Pve), tr!("Virtual Environment")),
+ (Some(RemoteType::Pbs), tr!("Backup Server")),
+ ],
+ on_select,
+ )
+}
+
+/// Creates a combobox to select one of the given values, labeled by the accompanying text.
+fn option_selector<T: Copy + PartialEq + 'static>(
+ current: T,
+ options: Vec<(T, String)>,
+ on_select: Callback<T>,
+) -> Combobox {
+ let current = options
+ .iter()
+ .position(|(value, _)| *value == current)
+ .map(|idx| idx.to_string());
+ let values: Vec<T> = options.iter().map(|(value, _)| *value).collect();
+
+ Combobox::from_key_value_pairs(
+ options
+ .into_iter()
+ .enumerate()
+ .map(|(idx, (_, label))| (idx.to_string(), label)),
+ )
+ .required(true)
+ .value(current)
+ .on_change(move |key: String| {
+ if let Some(value) = key.parse::<usize>().ok().and_then(|idx| values.get(idx)) {
+ on_select.emit(*value);
+ }
+ })
+}
--
2.47.3
next prev parent reply other threads:[~2026-11-26 14:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:49 [PATCH datacenter-manager 00/10] dashborad: add widget settings and leaderboard graph types Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 01/10] ui: dashboard: use plural for the container panel Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 02/10] ui: views: keep the icon for custom widget titles Dominik Csapak
2026-11-26 14:49 ` Dominik Csapak [this message]
2026-11-26 14:49 ` [PATCH datacenter-manager 04/10] ui: views: add only one menu entry per widget type Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 05/10] ui: dashboard: top entities: only build graph gradients on change Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 06/10] ui: dashboard: top entities: center data points in their interval Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 07/10] ui: dashboard: top entities: limit color stops by graph width Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 08/10] ui: dashboard: top entities: add line, area and bar graph types Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 09/10] ui: dashboard: top entities: show indicator line for tooltip point Dominik Csapak
2026-11-26 14:49 ` [PATCH datacenter-manager 10/10] docs: custom views: mention the graph types of the leaderboard widget Dominik Csapak
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=20261126145410.3011676-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox