fix: cap percentage in connectivity layout to 100%

it may happen that percentages larger than 100% are reported by the provider,
eg. for some time a storage usage of 120% may be accepted.

while we should report the values "as is" to the user,
for the bar, percentages larger 100% will destroy the layout.
This commit is contained in:
B. Petersen
2023-10-01 12:17:11 +02:00
committed by link2xt
parent f656cb29be
commit 2dd44d5f89

View File

@@ -1,4 +1,5 @@
use core::fmt;
use std::cmp::min;
use std::{iter::once, ops::Deref, sync::Arc};
use anyhow::{anyhow, Result};
@@ -457,7 +458,8 @@ impl Context {
} else {
"green"
};
ret += &format!("<div class=\"bar\"><div class=\"progress {color}\" style=\"width: {percent}%\">{percent}%</div></div>");
let div_width_percent = min(100, percent);
ret += &format!("<div class=\"bar\"><div class=\"progress {color}\" style=\"width: {div_width_percent}%\">{percent}%</div></div>");
ret += "</li>";
}