[pdm-devel] [PATCH datacenter-manager 1/2] ui: view configuration: unify create and edit input panel
Dominik Csapak
d.csapak at proxmox.com
Thu Nov 27 12:22:51 CET 2025
even though the implementation is not big, the two variants did diverge
already (boxlabel on the include all checkbox). To avoid that, unify the
two methods into one so most changes to one node will be reflected in
the other.
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
ui/src/configuration/views.rs | 61 +++++++++++++++++------------------
1 file changed, 29 insertions(+), 32 deletions(-)
diff --git a/ui/src/configuration/views.rs b/ui/src/configuration/views.rs
index 71cadc68..41969fdd 100644
--- a/ui/src/configuration/views.rs
+++ b/ui/src/configuration/views.rs
@@ -162,7 +162,7 @@ impl ViewGridComp {
let props = ctx.props();
let store = self.store.clone();
EditWindow::new(tr!("Add") + ": " + &tr!("View"))
- .renderer(move |form_ctx: &FormContext| add_view_input_panel(form_ctx, store.clone()))
+ .renderer(move |form_ctx| input_panel(form_ctx, InputPanelMode::Create(store.clone())))
.on_submit({
let base_url = props.base_url.clone();
let store = self.store.clone();
@@ -176,7 +176,7 @@ impl ViewGridComp {
let props = ctx.props();
let id = selection.to_string();
EditWindow::new(tr!("Edit") + ": " + &tr!("View"))
- .renderer(move |form_ctx| edit_view_input_panel(form_ctx, id.clone()))
+ .renderer(move |form_ctx| input_panel(form_ctx, InputPanelMode::Edit(id.clone())))
.on_submit({
let base_url = props.base_url.clone();
move |form| update_view(base_url.clone(), form)
@@ -322,23 +322,39 @@ impl LoadableComponent for ViewGridComp {
}
}
-fn add_view_input_panel(form_ctx: &FormContext, store: Store<ViewConfig>) -> Html {
+enum InputPanelMode {
+ Create(Store<ViewConfig>),
+ Edit(String), // id
+}
+
+fn input_panel(form_ctx: &FormContext, mode: InputPanelMode) -> Html {
let include_all = form_ctx.read().get_field_checked("include-all");
- InputPanel::new()
- .padding(4)
- .with_field(tr!("Name"), Field::new().name("id").required(true))
- .with_right_field(
- tr!("Copy Layout from"),
- ViewSelector::new(store)
- .placeholder(tr!("None"))
- .name("copy-from"),
- )
+ let is_create = matches!(mode, InputPanelMode::Create(_));
+ let mut input_panel = InputPanel::new().padding(4);
+
+ match mode {
+ InputPanelMode::Create(store) => {
+ input_panel.add_field(tr!("Name"), Field::new().name("id").required(true));
+ input_panel.add_right_field(
+ tr!("Copy Layout from"),
+ ViewSelector::new(store)
+ .placeholder(tr!("None"))
+ .name("copy-from"),
+ );
+ }
+ InputPanelMode::Edit(id) => input_panel.add_field(
+ tr!("Name"),
+ DisplayField::new().name("id").value(id.clone()),
+ ),
+ }
+
+ input_panel
.with_field(
tr!("Include All"),
Checkbox::new()
.name("include-all")
.box_label(tr!("Include all remotes and their resources."))
- .default(true),
+ .default(is_create),
)
.with_field_and_options(
pwt::widget::FieldPosition::Large,
@@ -352,22 +368,3 @@ fn add_view_input_panel(form_ctx: &FormContext, store: Store<ViewConfig>) -> Htm
.with_large_field(tr!("Exclude"), ViewFilterSelector::new().name("exclude"))
.into()
}
-
-fn edit_view_input_panel(form_ctx: &FormContext, id: String) -> Html {
- let include_all = form_ctx.read().get_field_checked("include-all");
- InputPanel::new()
- .padding(4)
- .with_field(tr!("Name"), DisplayField::new().name("id").value(id))
- .with_field(tr!("Include All"), Checkbox::new().name("include-all"))
- .with_field_and_options(
- pwt::widget::FieldPosition::Large,
- false,
- include_all,
- tr!("Include"),
- ViewFilterSelector::new()
- .name("include")
- .disabled(include_all),
- )
- .with_large_field(tr!("Exclude"), ViewFilterSelector::new().name("exclude"))
- .into()
-}
--
2.47.3
More information about the pdm-devel
mailing list