[pdm-devel] [PATCH yew-comp 1/2] subscription: refactor api subscription check for showing the alert

Dominik Csapak d.csapak at proxmox.com
Mon Dec 1 11:39:01 CET 2025


so we can reuse that

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/apt_repositories.rs   |  8 ++------
 src/subscription_alert.rs | 13 +++++++++++++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/apt_repositories.rs b/src/apt_repositories.rs
index ae582a6..83463c9 100644
--- a/src/apt_repositories.rs
+++ b/src/apt_repositories.rs
@@ -19,6 +19,7 @@ use pwt::widget::data_table::{
 };
 use pwt::widget::{Button, Column, Container, Fa, Row, Toolbar, Tooltip};
 
+use crate::subscription_alert::subscription_is_active;
 use crate::{
     EditWindow, ExistingProduct, LoadableComponent, LoadableComponentContext,
     LoadableComponentMaster, ProjectInfo, SubscriptionAlert,
@@ -694,12 +695,7 @@ fn standard_repo_info(
 
 impl ProxmoxAptRepositories {
     fn active_subscription(&self) -> bool {
-        match &self.subscription_status {
-            Some(Ok(data)) => {
-                data["status"].as_str().map(|s| s.to_lowercase()).as_deref() == Some("active")
-            }
-            _ => false,
-        }
+        subscription_is_active(&self.subscription_status)
     }
 
     fn create_show_subscription_dialog(
diff --git a/src/subscription_alert.rs b/src/subscription_alert.rs
index 2dca3c4..7734123 100644
--- a/src/subscription_alert.rs
+++ b/src/subscription_alert.rs
@@ -1,5 +1,8 @@
 use std::rc::Rc;
 
+use anyhow::Error;
+use serde_json::Value;
+
 use yew::html::{IntoEventCallback, IntoPropValue};
 use yew::virtual_dom::{VComp, VNode};
 
@@ -63,3 +66,13 @@ impl From<SubscriptionAlert> for VNode {
         VNode::from(comp)
     }
 }
+
+/// Check if the result of the subscription check returned an active subscription
+pub fn subscription_is_active(result: &Option<Result<Value, Error>>) -> bool {
+    match result {
+        Some(Ok(data)) => {
+            data["status"].as_str().map(|s| s.to_lowercase()).as_deref() == Some("active")
+        }
+        _ => false,
+    }
+}
-- 
2.47.3





More information about the pdm-devel mailing list