From: "Lukas Wagner" <l.wagner@proxmox.com>
To: "Dominik Csapak" <d.csapak@proxmox.com>, <pdm-devel@lists.proxmox.com>
Subject: Re: [PATCH datacenter-manager] views: catch unknown widget types
Date: Mon, 04 May 2026 10:00:18 +0200 [thread overview]
Message-ID: <DI9QFOCB8F85.35PBK040AXWCS@proxmox.com> (raw)
In-Reply-To: <20260427111402.2322116-1-d.csapak@proxmox.com>
On Mon Apr 27, 2026 at 1:13 PM CEST, Dominik Csapak wrote:
> If there is a mismatch between backend and frontend, (e.g. after an
> update or during development) deserialize unknown widget types in a way
> that we can still show the remaining widgets.
>
> Use serde's untagged + flatten feature so we can save all extra
> parameters and send it back to the backend.
>
> In the api, we reject all view updates that contain unknown widgets,
> since the frontend should never send any types the backend does not
> know.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> lib/pdm-api-types/Cargo.toml | 1 +
> lib/pdm-api-types/src/views.rs | 30 +++++++++++++++++++++++++++++-
> server/src/api/config/views.rs | 20 +++++++++++++++-----
> ui/src/dashboard/view.rs | 25 ++++++++++++++++++++++++-
> 4 files changed, 69 insertions(+), 7 deletions(-)
>
> diff --git a/lib/pdm-api-types/Cargo.toml b/lib/pdm-api-types/Cargo.toml
> index 7aa7b64e..0c84d301 100644
> --- a/lib/pdm-api-types/Cargo.toml
> +++ b/lib/pdm-api-types/Cargo.toml
> @@ -12,6 +12,7 @@ http.workspace = true
> regex.workspace = true
> serde.workspace = true
> serde_plain.workspace = true
> +serde_json.workspace = true
>
> proxmox-acme-api.workspace = true
> proxmox-access-control = { workspace = true, features = ["acl"] }
> diff --git a/lib/pdm-api-types/src/views.rs b/lib/pdm-api-types/src/views.rs
> index c1885828..89281bb3 100644
> --- a/lib/pdm-api-types/src/views.rs
> +++ b/lib/pdm-api-types/src/views.rs
> @@ -1,4 +1,7 @@
> -use std::{fmt::Debug, fmt::Display, str::FromStr, sync::OnceLock};
> +use std::collections::HashMap;
> +use std::fmt::{Debug, Display};
> +use std::str::FromStr;
> +use std::sync::OnceLock;
>
> use anyhow::{bail, Error};
> use const_format::concatcp;
> @@ -255,6 +258,24 @@ pub enum ViewLayout {
> },
> }
>
> +impl ViewLayout {
> + /// Tests if this layout has unknown widget types
> + pub fn has_unknown_widgets(&self) -> bool {
> + match self {
> + ViewLayout::Rows { rows } => {
> + for row in rows {
> + for widget in row {
> + if let WidgetType::UnknownWidget { .. } = widget.r#type {
> + return true;
> + }
> + }
> + }
> + }
> + }
> + false
> + }
> +}
> +
> #[derive(Serialize, Deserialize, PartialEq, Clone)]
> #[serde(rename_all = "kebab-case")]
> pub struct RowWidget {
> @@ -312,6 +333,13 @@ pub enum WidgetType {
> #[serde(skip_serializing_if = "Option::is_none")]
> remote_type: Option<RemoteType>,
> },
> + #[serde(untagged)]
> + #[serde(rename_all = "kebab-case")]
> + UnknownWidget {
> + widget_type: String,
> + #[serde(flatten)]
> + extra: HashMap<String, serde_json::Value>,
> + },
This is `pub` and should therefore have some doc comments. Seems
valuable to me to express the 'catch-all' behavior there.
> }
>
Looks good to me otherwise.
Tested it by applying this patch and then modifying views.cfg manually,
changing the widget-type of one widget to something unknown.
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Lukas Wagner <l.wagner@proxmox.com>
next prev parent reply other threads:[~2026-05-04 8:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 11:13 [PATCH datacenter-manager] views: catch unknown widget types Dominik Csapak
2026-05-04 8:00 ` Lukas Wagner [this message]
2026-05-04 10:18 ` superseded: " 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=DI9QFOCB8F85.35PBK040AXWCS@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox