From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 2/2] ui: dashboard: render last refresh date/time instead of a seconds counter
Date: Tue, 9 Sep 2025 09:37:56 +0200 [thread overview]
Message-ID: <20250909073801.661423-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250909073801.661423-1-d.csapak@proxmox.com>
this is less jarring, since it does not change the content of the page
as often. Since we now only have to do things when we actually reload,
we can use the actual configured interval for the internal one, and
don't have to check every second if that elapsed.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/src/dashboard/mod.rs | 4 +--
ui/src/dashboard/status_row.rs | 47 +++++++++++++---------------------
2 files changed, 20 insertions(+), 31 deletions(-)
diff --git a/ui/src/dashboard/mod.rs b/ui/src/dashboard/mod.rs
index 8d68dc2..11b4e2d 100644
--- a/ui/src/dashboard/mod.rs
+++ b/ui/src/dashboard/mod.rs
@@ -71,7 +71,7 @@ pub const DEFAULT_MAX_AGE_S: u64 = 30;
/// The default refresh interval, we poll more frequently than the default max-age to quicker show
/// any new data that was gathered either by the backend polling tasks or by a manual update
/// triggered by another user.
-pub const DEFAULT_REFRESH_INTERVAL_S: u64 = 10;
+pub const DEFAULT_REFRESH_INTERVAL_S: u32 = 10;
/// The default hours to show for task summaries. Use 2 days to ensure that all tasks from yesterday
/// are included independent from the time a user checks the dashboard on the current day.
@@ -96,7 +96,7 @@ impl Default for Dashboard {
#[serde(rename_all = "kebab-case")]
pub struct DashboardConfig {
#[serde(skip_serializing_if = "Option::is_none")]
- refresh_interval: Option<u64>,
+ refresh_interval: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
max_age: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
diff --git a/ui/src/dashboard/status_row.rs b/ui/src/dashboard/status_row.rs
index 85048fe..5e37741 100644
--- a/ui/src/dashboard/status_row.rs
+++ b/ui/src/dashboard/status_row.rs
@@ -1,5 +1,4 @@
use gloo_timers::callback::Interval;
-use js_sys::Date;
use yew::{Component, Properties};
use pwt::prelude::*;
@@ -9,13 +8,13 @@ use pwt::{
};
use pwt_macros::widget;
-use proxmox_yew_comp::utils::format_duration_human;
+use proxmox_yew_comp::utils::render_epoch;
#[widget(comp=PdmDashboardStatusRow)]
#[derive(Properties, PartialEq, Clone)]
pub struct DashboardStatusRow {
last_refresh: Option<f64>,
- reload_interval_s: u64,
+ reload_interval_s: u32,
on_reload: Callback<bool>,
@@ -25,7 +24,7 @@ pub struct DashboardStatusRow {
impl DashboardStatusRow {
pub fn new(
last_refresh: Option<f64>,
- reload_interval_s: u64,
+ reload_interval_s: u32,
on_reload: impl Into<Callback<bool>>,
on_settings_click: impl Into<Callback<()>>,
) -> Self {
@@ -41,24 +40,24 @@ impl DashboardStatusRow {
pub enum Msg {
/// The bool denotes if the reload comes from the click or the timer.
Reload(bool),
- CheckReload,
}
#[doc(hidden)]
pub struct PdmDashboardStatusRow {
- _interval: Option<Interval>,
+ _interval: Interval,
}
impl PdmDashboardStatusRow {
- fn update_interval(&mut self, ctx: &yew::Context<Self>) {
+ fn create_interval(ctx: &yew::Context<Self>) -> Interval {
let link = ctx.link().clone();
- let _interval = ctx.props().last_refresh.map(|_| {
- Interval::new(1000, move || {
- link.send_message(Msg::CheckReload);
- })
- });
+ let _interval = Interval::new(
+ ctx.props().reload_interval_s.saturating_mul(1000),
+ move || {
+ link.send_message(Msg::Reload(false));
+ },
+ );
- self._interval = _interval;
+ _interval
}
}
@@ -67,9 +66,9 @@ impl Component for PdmDashboardStatusRow {
type Properties = DashboardStatusRow;
fn create(ctx: &yew::Context<Self>) -> Self {
- let mut this = Self { _interval: None };
- this.update_interval(ctx);
- this
+ Self {
+ _interval: Self::create_interval(ctx),
+ }
}
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
@@ -79,21 +78,11 @@ impl Component for PdmDashboardStatusRow {
props.on_reload.emit(clicked);
true
}
- Msg::CheckReload => match ctx.props().last_refresh {
- Some(last_refresh) => {
- let duration = Date::now() / 1000.0 - last_refresh;
- if duration >= props.reload_interval_s as f64 {
- ctx.link().send_message(Msg::Reload(false));
- }
- true
- }
- None => false,
- },
}
}
fn changed(&mut self, ctx: &Context<Self>, _old_props: &Self::Properties) -> bool {
- self.update_interval(ctx);
+ self._interval = Self::create_interval(ctx);
true
}
@@ -119,8 +108,8 @@ impl Component for PdmDashboardStatusRow {
)
.with_child(Container::new().with_child(match ctx.props().last_refresh {
Some(last_refresh) => {
- let duration = Date::now() / 1000.0 - last_refresh;
- tr!("Last refreshed: {0} ago", format_duration_human(duration))
+ let date = render_epoch(last_refresh as i64);
+ tr!("Last refresh: {0}", date)
}
None => tr!("Now refreshing"),
}))
--
2.47.2
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
prev parent reply other threads:[~2025-09-09 7:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 7:37 [pdm-devel] [PATCH datacenter-manager 1/2] ui: dashboard: show finished loading data immediately Dominik Csapak
2025-09-09 7:37 ` Dominik Csapak [this message]
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=20250909073801.661423-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.