all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 2/4] ui: dashboard: introduce DashboardConfig
Date: Fri,  6 Jun 2025 09:27:18 +0200	[thread overview]
Message-ID: <20250606072720.664054-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250606072720.664054-1-d.csapak@proxmox.com>

to hold the configuration of the dashboard. We'll later use this to
hold the user configuration.

Having it as a property does not make sense here since we don't set it
from outside the dashboard, and since it's not a generic component,
it's not likely to be reused elsewhere.

Saving it as a PersistentState also makes it possible to have it persist
across sessions when we're able to change it.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/dashboard/mod.rs | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/ui/src/dashboard/mod.rs b/ui/src/dashboard/mod.rs
index 0832ced..960766e 100644
--- a/ui/src/dashboard/mod.rs
+++ b/ui/src/dashboard/mod.rs
@@ -1,6 +1,7 @@
 use std::rc::Rc;
 
 use anyhow::Error;
+use serde::{Deserialize, Serialize};
 use serde_json::json;
 use yew::{
     virtual_dom::{VComp, VNode},
@@ -11,6 +12,8 @@ use proxmox_yew_comp::{http_get, Status};
 use pwt::{
     css::{AlignItems, FlexDirection, FlexFit, FlexWrap, JustifyContent},
     prelude::*,
+    props::StorageLocation,
+    state::PersistentState,
     widget::{error_message, Button, Column, Container, Fa, Panel, Row},
     AsyncPool,
 };
@@ -32,12 +35,11 @@ use remote_panel::RemotePanel;
 mod guest_panel;
 use guest_panel::GuestPanel;
 
+/// The default 'max-age' parameter in seconds.
+pub const DEFAULT_MAX_AGE_S: u64 = 60;
+
 #[derive(Properties, PartialEq)]
-pub struct Dashboard {
-    #[prop_or(60)]
-    /// The time (in seconds) to not refresh cached data. (Default: 60)
-    max_age_seconds: u64,
-}
+pub struct Dashboard {}
 
 impl Dashboard {
     pub fn new() -> Self {
@@ -51,6 +53,13 @@ impl Default for Dashboard {
     }
 }
 
+#[derive(Serialize, Deserialize, Default, Debug)]
+#[serde(rename_all = "kebab-case")]
+pub struct DashboardConfig {
+    #[serde(skip_serializing_if = "Option::is_none")]
+    max_age: Option<u64>,
+}
+
 pub enum Msg {
     LoadingFinished(Result<ResourcesStatus, Error>),
     TopEntitiesLoadResult(Result<pdm_client::types::TopEntities, proxmox_client::Error>),
@@ -68,6 +77,7 @@ pub struct PdmDashboard {
     show_wizard: bool,
     _context_listener: ContextHandle<RemoteList>,
     _async_pool: AsyncPool,
+    _config: PersistentState<DashboardConfig>,
 }
 
 impl PdmDashboard {
@@ -169,7 +179,9 @@ impl Component for PdmDashboard {
 
     fn create(ctx: &yew::Context<Self>) -> Self {
         let link = ctx.link().clone();
-        let max_age = ctx.props().max_age_seconds;
+        let _config: PersistentState<DashboardConfig> =
+            PersistentState::new(StorageLocation::local("dashboard-config"));
+        let max_age = _config.max_age.unwrap_or(DEFAULT_MAX_AGE_S);
 
         let async_pool = AsyncPool::new();
 
@@ -199,6 +211,7 @@ impl Component for PdmDashboard {
             show_wizard: false,
             _context_listener,
             _async_pool: async_pool,
+            _config,
         }
     }
 
-- 
2.39.5



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  parent reply	other threads:[~2025-06-06  7:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06  7:27 [pdm-devel] [PATCH datacenter-manager/yew-widget-toolkit-assets 0/5] make dashboard refreshable Dominik Csapak
2025-06-06  7:27 ` [pdm-devel] [PATCH yew-widget-toolkit-assets 1/1] content-spacer: add helper class for color Dominik Csapak
2025-06-06  7:27 ` [pdm-devel] [PATCH datacenter-manager 1/4] ui: dashboard: use builtin types and methods for styles Dominik Csapak
2025-06-06  7:27 ` Dominik Csapak [this message]
2025-06-06  7:27 ` [pdm-devel] [PATCH datacenter-manager 3/4] ui: dashboard: refactor loading logic Dominik Csapak
2025-06-06  7:27 ` [pdm-devel] [PATCH datacenter-manager 4/4] ui: dashboard: add status row and configuration window Dominik Csapak

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=20250606072720.664054-4-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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal