[pdm-devel] [PATCH yew-comp v2 1/1] notes view: allow hiding the toolbar if editing isn't supported

Shannon Sterz s.sterz at proxmox.com
Wed Oct 22 15:11:25 CEST 2025


Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
alternatively we could also pass down the path and permissions for the
the check and hook this component into the context itself. since we are
talking about a single boolean check here, i though this approach
provides less overhead and tried to keep it simple.

 src/notes_view.rs | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/notes_view.rs b/src/notes_view.rs
index 315163e..9806d63 100644
--- a/src/notes_view.rs
+++ b/src/notes_view.rs
@@ -6,6 +6,7 @@ use anyhow::Error;
 use serde::{Deserialize, Serialize};
 use serde_json::{json, Value};

+use yew::html::IntoPropValue;
 use yew::virtual_dom::{VComp, VNode};

 use pwt::prelude::*;
@@ -64,6 +65,10 @@ pub struct NotesView {
     #[builder_cb(IntoSubmitCallback, into_submit_callback, NotesWithDigest)]
     #[prop_or_default]
     pub on_submit: Option<SubmitCallback<NotesWithDigest>>,
+
+    #[builder(IntoPropValue, into_prop_value)]
+    #[prop_or(true)]
+    pub allow_editing: bool,
 }

 impl NotesView {
@@ -163,20 +168,25 @@ impl LoadableComponent for ProxmoxNotesView {
     }
     fn toolbar(&self, ctx: &LoadableComponentContext<Self>) -> Option<Html> {
         let props = ctx.props();
-        let toolbar = Toolbar::new()
-            .class("pwt-w-100")
-            .class("pwt-overflow-hidden")
-            .class("pwt-border-bottom")
-            .with_child(
-                Button::new(tr!("Edit"))
-                    .disabled(props.on_submit.is_none())
-                    .onclick(
-                        ctx.link()
-                            .change_view_callback(|_| Some(ViewState::EditNotes)),
-                    ),
-            );

-        Some(toolbar.into())
+        if props.allow_editing {
+            let toolbar = Toolbar::new()
+                .class("pwt-w-100")
+                .class("pwt-overflow-hidden")
+                .class("pwt-border-bottom")
+                .with_child(
+                    Button::new(tr!("Edit"))
+                        .disabled(props.on_submit.is_none())
+                        .onclick(
+                            ctx.link()
+                                .change_view_callback(|_| Some(ViewState::EditNotes)),
+                        ),
+                );
+
+            return Some(toolbar.into());
+        }
+
+        None
     }

     fn main_view(&self, _ctx: &LoadableComponentContext<Self>) -> Html {
--
2.47.3





More information about the pdm-devel mailing list