[pdm-devel] [PATCH yew-comp 5/7] running tasks: make buttons configurable

Dominik Csapak d.csapak at proxmox.com
Mon Jan 20 10:29:55 CET 2025


we sometimes want different buttons here (e.g. on PDM we want two)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/running_tasks.rs        | 37 +++++++++++++++++++++++++------------
 src/running_tasks_button.rs |  8 +++++++-
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/running_tasks.rs b/src/running_tasks.rs
index b0b63af..c5cea4c 100644
--- a/src/running_tasks.rs
+++ b/src/running_tasks.rs
@@ -1,6 +1,6 @@
 use std::rc::Rc;
 
-use yew::html::IntoEventCallback;
+use yew::html::{IntoEventCallback, IntoPropValue};
 use yew::virtual_dom::{VComp, VNode};
 
 use pwt::prelude::*;
@@ -35,6 +35,11 @@ pub struct RunningTasks {
     #[builder]
     #[prop_or_default]
     pub as_dropdown: bool,
+
+    #[builder(IntoPropValue, into_prop_value)]
+    #[prop_or_default]
+    /// Custom Buttons instead of the default 'Show all' one.
+    pub buttons: Option<Vec<Button>>,
 }
 
 impl RunningTasks {
@@ -167,17 +172,25 @@ impl Component for ProxmoxRunningTasks {
         });
 
         let toolbar = props.as_dropdown.then(|| {
-            Toolbar::new().with_flex_spacer().with_child({
-                let on_close = props.on_close.clone();
-                Button::new(tr!("Show All Tasks"))
-                    .class("pwt-scheme-primary")
-                    .onclick(move |_| {
-                        crate::utils::set_location_href("#/administration/tasks");
-                        if let Some(on_close) = &on_close {
-                            on_close.emit(());
-                        }
-                    })
-            })
+            if let Some(buttons) = props.buttons.clone() {
+                let mut tb = Toolbar::new().with_flex_spacer();
+                for button in buttons {
+                    tb.add_child(button);
+                }
+                tb
+            } else {
+                Toolbar::new().with_flex_spacer().with_child({
+                    let on_close = props.on_close.clone();
+                    Button::new(tr!("Show All Tasks"))
+                        .class("pwt-scheme-primary")
+                        .onclick(move |_| {
+                            crate::utils::set_location_href("#/administration/tasks");
+                            if let Some(on_close) = &on_close {
+                                on_close.emit(());
+                            }
+                        })
+                })
+            }
         });
 
         Panel::new()
diff --git a/src/running_tasks_button.rs b/src/running_tasks_button.rs
index e0e1062..331c006 100644
--- a/src/running_tasks_button.rs
+++ b/src/running_tasks_button.rs
@@ -3,7 +3,7 @@ use std::rc::Rc;
 use gloo_timers::callback::Timeout;
 use pwt::css::ColorScheme;
 use wasm_bindgen::JsCast;
-use yew::html::IntoEventCallback;
+use yew::html::{IntoEventCallback, IntoPropValue};
 use yew::virtual_dom::{VComp, VNode};
 
 use pwt::dom::align::{align_to, AlignOptions, GrowDirection, Point};
@@ -30,6 +30,11 @@ pub struct RunningTasksButton {
     #[prop_or_default]
     /// Render function for the [`TaskListItem`]
     pub render: Option<RenderFn<TaskListItem>>,
+
+    #[builder(IntoPropValue, into_prop_value)]
+    #[prop_or_default]
+    /// Custom Buttons instead of the default 'Show all' one.
+    pub buttons: Option<Vec<Button>>,
 }
 
 impl RunningTasksButton {
@@ -156,6 +161,7 @@ impl Component for ProxmoxRunningTasksButton {
                 .node_ref(self.submenu_ref.clone())
                 .with_child(
                     RunningTasks::new(props.running_tasks.clone())
+                        .buttons(props.buttons.clone())
                         .as_dropdown(true)
                         .on_show_task(props.on_show_task.clone())
                         .render(props.render.clone())
-- 
2.39.5





More information about the pdm-devel mailing list