[pdm-devel] [PATCH yew-comp v2 1/1] notes view: allow hiding the toolbar if editing isn't supported
Dominik Csapak
d.csapak at proxmox.com
Thu Oct 23 11:36:50 CEST 2025
alternatively we could determine this from the 'on_submit' existence?
IMHO it does not make much sense if someone
sets the 'on_submit' call but disables editing, or vice versa
if there is some use case I can't see right now, consider this
Reviewed-by: Dominik Csapak <d.csapak at proxmox.com>
On 10/22/25 3:11 PM, Shannon Sterz wrote:
> 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
>
>
>
> _______________________________________________
> pdm-devel mailing list
> pdm-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
>
>
More information about the pdm-devel
mailing list