From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager v2 17/18] lib/ui: move views types to pdm-api-types
Date: Fri, 14 Nov 2025 13:11:31 +0100 [thread overview]
Message-ID: <20251114121218.2479318-18-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251114121218.2479318-1-d.csapak@proxmox.com>
so that we can reuse these in the backend too. For the `GuestType`, we
have to redefine it in the pdm-api-types crate, since the ui depends on
some impls there that we cannot move (e.g. From<GuestType> for Fa), but
a From impl is provided so we can easily convert between the 'backend'
type and the 'ui' type where necessary (it's just two enum variants that
are copy and should not make much issues)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
lib/pdm-api-types/src/resource.rs | 7 +++
lib/pdm-api-types/src/views.rs | 78 ++++++++++++++++++++++++++-
ui/src/dashboard/mod.rs | 2 -
ui/src/dashboard/top_entities.rs | 3 +-
ui/src/dashboard/types.rs | 79 ----------------------------
ui/src/dashboard/view.rs | 10 ++--
ui/src/dashboard/view/row_element.rs | 2 +-
ui/src/dashboard/view/row_view.rs | 21 ++++----
ui/src/pve/mod.rs | 9 ++++
9 files changed, 113 insertions(+), 98 deletions(-)
delete mode 100644 ui/src/dashboard/types.rs
diff --git a/lib/pdm-api-types/src/resource.rs b/lib/pdm-api-types/src/resource.rs
index d89b45d7..4106a7ea 100644
--- a/lib/pdm-api-types/src/resource.rs
+++ b/lib/pdm-api-types/src/resource.rs
@@ -775,3 +775,10 @@ pub struct TopEntities {
/// The top entries for Node Memory
pub node_memory: Vec<TopEntity>,
}
+
+#[derive(PartialEq, Clone, Copy, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub enum GuestType {
+ Qemu,
+ Lxc,
+}
diff --git a/lib/pdm-api-types/src/views.rs b/lib/pdm-api-types/src/views.rs
index 4b837384..3464833d 100644
--- a/lib/pdm-api-types/src/views.rs
+++ b/lib/pdm-api-types/src/views.rs
@@ -11,7 +11,9 @@ use proxmox_schema::{
use proxmox_section_config::{typed::ApiSectionDataEntry, SectionConfig, SectionConfigPlugin};
use crate::{
- remotes::REMOTE_ID_SCHEMA, resource::ResourceType, PROXMOX_SAFE_ID_REGEX, VIEW_ID_SCHEMA,
+ remotes::{RemoteType, REMOTE_ID_SCHEMA},
+ resource::{GuestType, ResourceType},
+ PROXMOX_SAFE_ID_REGEX, VIEW_ID_SCHEMA,
};
const_regex! {
@@ -182,6 +184,80 @@ fn verify_filter_rule(input: &str) -> Result<(), anyhow::Error> {
FilterRule::from_str(input).map(|_| ())
}
+#[derive(Serialize, Deserialize, PartialEq, Clone)]
+#[serde(rename_all = "kebab-case")]
+pub struct ViewTemplate {
+ #[serde(skip_serializing_if = "String::is_empty")]
+ pub description: String,
+ pub layout: ViewLayout,
+}
+
+#[derive(Serialize, Deserialize, PartialEq, Clone)]
+#[serde(rename_all = "kebab-case")]
+#[serde(tag = "layout-type")]
+pub enum ViewLayout {
+ Rows {
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ rows: Vec<Vec<RowWidget>>,
+ },
+}
+
+#[derive(Serialize, Deserialize, PartialEq, Clone)]
+#[serde(rename_all = "kebab-case")]
+pub struct RowWidget {
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub flex: Option<f32>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub title: Option<String>,
+ #[serde(flatten)]
+ pub r#type: WidgetType,
+}
+
+#[derive(Serialize, Deserialize, PartialEq, Clone)]
+#[serde(rename_all = "kebab-case")]
+#[serde(tag = "widget-type")]
+pub enum WidgetType {
+ #[serde(rename_all = "kebab-case")]
+ Nodes {
+ #[serde(skip_serializing_if = "Option::is_none")]
+ remote_type: Option<RemoteType>,
+ },
+ #[serde(rename_all = "kebab-case")]
+ Guests {
+ #[serde(skip_serializing_if = "Option::is_none")]
+ guest_type: Option<GuestType>,
+ },
+ PbsDatastores,
+ #[serde(rename_all = "kebab-case")]
+ Remotes {
+ show_wizard: bool,
+ },
+ Subscription,
+ Sdn,
+ #[serde(rename_all = "kebab-case")]
+ Leaderboard {
+ leaderboard_type: LeaderboardType,
+ },
+ TaskSummary {
+ grouping: TaskSummaryGrouping,
+ },
+}
+
+#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
+#[serde(rename_all = "kebab-case")]
+pub enum LeaderboardType {
+ GuestCpu,
+ NodeCpu,
+ NodeMemory,
+}
+
+#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
+#[serde(rename_all = "kebab-case")]
+pub enum TaskSummaryGrouping {
+ Category,
+ Remote,
+}
+
#[cfg(test)]
mod test {
use anyhow::Error;
diff --git a/ui/src/dashboard/mod.rs b/ui/src/dashboard/mod.rs
index 31581c12..8800102f 100644
--- a/ui/src/dashboard/mod.rs
+++ b/ui/src/dashboard/mod.rs
@@ -34,8 +34,6 @@ pub use pbs_datastores_panel::create_pbs_datastores_panel;
mod tasks;
pub use tasks::create_task_summary_panel;
-pub mod types;
-
pub mod view;
mod refresh_config_edit;
diff --git a/ui/src/dashboard/top_entities.rs b/ui/src/dashboard/top_entities.rs
index e94c1b8c..ab8c703d 100644
--- a/ui/src/dashboard/top_entities.rs
+++ b/ui/src/dashboard/top_entities.rs
@@ -17,11 +17,12 @@ use pwt::{
widget::{error_message, ActionIcon, Column, Container, Panel, Row},
};
+use pdm_api_types::views::LeaderboardType;
use pdm_client::types::{Resource, TopEntity};
use crate::LoadResult;
use crate::{
- dashboard::{create_title_with_icon, loading_column, types::LeaderboardType},
+ dashboard::{create_title_with_icon, loading_column},
get_deep_url, get_resource_node, navigate_to,
renderer::{render_resource_icon, render_resource_name},
};
diff --git a/ui/src/dashboard/types.rs b/ui/src/dashboard/types.rs
deleted file mode 100644
index 3b018b6e..00000000
--- a/ui/src/dashboard/types.rs
+++ /dev/null
@@ -1,79 +0,0 @@
-use serde::{Deserialize, Serialize};
-
-use pdm_api_types::remotes::RemoteType;
-
-use crate::pve::GuestType;
-
-#[derive(Serialize, Deserialize, PartialEq, Clone)]
-#[serde(rename_all = "kebab-case")]
-pub struct ViewTemplate {
- #[serde(skip_serializing_if = "String::is_empty")]
- pub description: String,
- pub layout: ViewLayout,
-}
-
-#[derive(Serialize, Deserialize, PartialEq, Clone)]
-#[serde(rename_all = "kebab-case")]
-#[serde(tag = "layout-type")]
-pub enum ViewLayout {
- Rows {
- #[serde(default, skip_serializing_if = "Vec::is_empty")]
- rows: Vec<Vec<RowWidget>>,
- },
-}
-
-#[derive(Serialize, Deserialize, PartialEq, Clone)]
-#[serde(rename_all = "kebab-case")]
-pub struct RowWidget {
- #[serde(skip_serializing_if = "Option::is_none")]
- pub flex: Option<f32>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub title: Option<String>,
- #[serde(flatten)]
- pub r#type: WidgetType,
-}
-
-#[derive(Serialize, Deserialize, PartialEq, Clone)]
-#[serde(rename_all = "kebab-case")]
-#[serde(tag = "widget-type")]
-pub enum WidgetType {
- #[serde(rename_all = "kebab-case")]
- Nodes {
- #[serde(skip_serializing_if = "Option::is_none")]
- remote_type: Option<RemoteType>,
- },
- #[serde(rename_all = "kebab-case")]
- Guests {
- #[serde(skip_serializing_if = "Option::is_none")]
- guest_type: Option<GuestType>,
- },
- PbsDatastores,
- #[serde(rename_all = "kebab-case")]
- Remotes {
- show_wizard: bool,
- },
- Subscription,
- Sdn,
- #[serde(rename_all = "kebab-case")]
- Leaderboard {
- leaderboard_type: LeaderboardType,
- },
- TaskSummary {
- grouping: TaskSummaryGrouping,
- },
-}
-
-#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
-#[serde(rename_all = "kebab-case")]
-pub enum LeaderboardType {
- GuestCpu,
- NodeCpu,
- NodeMemory,
-}
-
-#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
-#[serde(rename_all = "kebab-case")]
-pub enum TaskSummaryGrouping {
- Category,
- Remote,
-}
diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index 8ee59073..7edf5106 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -19,8 +19,6 @@ use crate::dashboard::refresh_config_edit::{
FORCE_RELOAD_MAX_AGE_S, INITIAL_MAX_AGE_S,
};
use crate::dashboard::tasks::get_task_options;
-use crate::dashboard::types::RowWidget;
-use crate::dashboard::types::{TaskSummaryGrouping, ViewLayout, ViewTemplate, WidgetType};
use crate::dashboard::{
create_guest_panel, create_node_panel, create_pbs_datastores_panel,
create_refresh_config_edit_window, create_remote_panel, create_sdn_panel,
@@ -33,7 +31,9 @@ use crate::{pdm_client, LoadResult};
use pdm_api_types::remotes::RemoteType;
use pdm_api_types::resource::ResourcesStatus;
use pdm_api_types::subscription::RemoteSubscriptions;
-use pdm_api_types::views::ViewConfig;
+use pdm_api_types::views::{
+ RowWidget, TaskSummaryGrouping, ViewConfig, ViewLayout, ViewTemplate, WidgetType,
+};
use pdm_api_types::TaskStatistics;
use pdm_client::types::TopEntities;
@@ -118,7 +118,9 @@ fn render_widget(
) -> Html {
let mut widget = match &item.r#type {
WidgetType::Nodes { remote_type } => create_node_panel(*remote_type, status),
- WidgetType::Guests { guest_type } => create_guest_panel(*guest_type, status),
+ WidgetType::Guests { guest_type } => {
+ create_guest_panel(guest_type.map(|g| g.into()), status)
+ }
WidgetType::Remotes { show_wizard } => create_remote_panel(
status,
show_wizard.then_some(link.callback(|_| Msg::CreateWizard(Some(RemoteType::Pve)))),
diff --git a/ui/src/dashboard/view/row_element.rs b/ui/src/dashboard/view/row_element.rs
index d242195c..01d868e6 100644
--- a/ui/src/dashboard/view/row_element.rs
+++ b/ui/src/dashboard/view/row_element.rs
@@ -6,7 +6,7 @@ use pwt::props::RenderFn;
use pwt::widget::{ActionIcon, Card, Fa, Panel, Row};
use pwt_macros::{builder, widget};
-use crate::dashboard::types::RowWidget;
+use pdm_api_types::views::RowWidget;
#[widget(comp=RowElementComp, @element)]
#[derive(PartialEq, Properties, Clone)]
diff --git a/ui/src/dashboard/view/row_view.rs b/ui/src/dashboard/view/row_view.rs
index 512e63e7..7ecac200 100644
--- a/ui/src/dashboard/view/row_view.rs
+++ b/ui/src/dashboard/view/row_view.rs
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::rc::Rc;
use gloo_timers::callback::Timeout;
+use pdm_api_types::resource::GuestType;
use wasm_bindgen::JsCast;
use web_sys::Element;
use yew::html::{IntoEventCallback, IntoPropValue};
@@ -15,11 +16,13 @@ use pwt::widget::menu::{Menu, MenuButton, MenuItem};
use pwt::widget::{ActionIcon, Button, Column, Container, Row, Tooltip};
use pwt_macros::builder;
-use crate::dashboard::types::{RowWidget, ViewLayout, WidgetType};
use crate::dashboard::view::row_element::RowElement;
use crate::dashboard::view::EditingMessage;
use pdm_api_types::remotes::RemoteType;
+use pdm_api_types::views::{
+ LeaderboardType, RowWidget, TaskSummaryGrouping, ViewLayout, WidgetType,
+};
#[derive(Properties, PartialEq)]
#[builder]
@@ -557,14 +560,14 @@ fn create_menu(ctx: &yew::Context<RowViewComp>, new_coords: Position) -> Menu {
.with_item(
MenuItem::new(tr!("Virtual Machines")).on_select(create_callback(
WidgetType::Guests {
- guest_type: Some(crate::pve::GuestType::Qemu),
+ guest_type: Some(GuestType::Qemu),
},
)),
)
.with_item(
MenuItem::new(tr!("Linux Container")).on_select(create_callback(
WidgetType::Guests {
- guest_type: Some(crate::pve::GuestType::Lxc),
+ guest_type: Some(GuestType::Lxc),
},
)),
),
@@ -584,23 +587,21 @@ fn create_menu(ctx: &yew::Context<RowViewComp>, new_coords: Position) -> Menu {
.with_item(
MenuItem::new(tr!("Guests with Highest CPU Usage")).on_select(
create_callback(WidgetType::Leaderboard {
- leaderboard_type:
- crate::dashboard::types::LeaderboardType::GuestCpu,
+ leaderboard_type: LeaderboardType::GuestCpu,
}),
),
)
.with_item(
MenuItem::new(tr!("Nodes With the Hightest CPU Usagge)")).on_select(
create_callback(WidgetType::Leaderboard {
- leaderboard_type: crate::dashboard::types::LeaderboardType::NodeCpu,
+ leaderboard_type: LeaderboardType::NodeCpu,
}),
),
)
.with_item(
MenuItem::new(tr!("Nodes With the Highest Memory Usage")).on_select(
create_callback(WidgetType::Leaderboard {
- leaderboard_type:
- crate::dashboard::types::LeaderboardType::NodeMemory,
+ leaderboard_type: LeaderboardType::NodeMemory,
}),
),
),
@@ -611,13 +612,13 @@ fn create_menu(ctx: &yew::Context<RowViewComp>, new_coords: Position) -> Menu {
Menu::new()
.with_item(MenuItem::new(tr!("Task Summary by Category")).on_select(
create_callback(WidgetType::TaskSummary {
- grouping: crate::dashboard::types::TaskSummaryGrouping::Category,
+ grouping: TaskSummaryGrouping::Category,
}),
))
.with_item(
MenuItem::new(tr!("Task Summary Sorted by Failed Tasks")).on_select(
create_callback(WidgetType::TaskSummary {
- grouping: crate::dashboard::types::TaskSummaryGrouping::Remote,
+ grouping: TaskSummaryGrouping::Remote,
}),
),
),
diff --git a/ui/src/pve/mod.rs b/ui/src/pve/mod.rs
index c0759f18..c1c62230 100644
--- a/ui/src/pve/mod.rs
+++ b/ui/src/pve/mod.rs
@@ -75,6 +75,15 @@ pub enum GuestType {
Lxc,
}
+impl From<pdm_api_types::resource::GuestType> for GuestType {
+ fn from(value: pdm_api_types::resource::GuestType) -> Self {
+ match value {
+ pdm_api_types::resource::GuestType::Qemu => GuestType::Qemu,
+ pdm_api_types::resource::GuestType::Lxc => GuestType::Lxc,
+ }
+ }
+}
+
impl Display for GuestType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-11-14 12:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 12:11 [pdm-devel] [PATCH datacenter-manager v2 00/18] enable custom views on the UI Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 01/18] lib: pdm-config: views: add locking/saving methods Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 02/18] lib: api-types: add 'layout' property to ViewConfig Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 03/18] server: api: implement CRUD api for views Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 04/18] server: api: resources: add 'view' category to search syntax Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 05/18] ui: remote selector: allow forcing of value Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 06/18] ui: dashboard types: add missing 'default' to de-serialization Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 07/18] ui: dashboard: status row: add optional 'editing state' Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 08/18] ui: dashboard: prepare view for editing custom views Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 09/18] ui: views: implement view loading from api Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 10/18] ui: views: make 'view' name property optional Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 11/18] ui: views: add 'view' parameter to api calls Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 12/18] ui: views: save updated layout to backend Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 13/18] ui: add view list context Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 14/18] ui: configuration: add view CRUD panels Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 15/18] ui: main menu: add optional view_list property Dominik Csapak
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 16/18] ui: load view list on page init Dominik Csapak
2025-11-14 12:11 ` Dominik Csapak [this message]
2025-11-14 12:11 ` [pdm-devel] [PATCH datacenter-manager v2 18/18] server: api: views: check layout string for validity Dominik Csapak
2025-11-14 12:22 ` [pdm-devel] [PATCH datacenter-manager v2 00/18] enable custom views on the UI 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=20251114121218.2479318-18-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox