feat: Extend widget configuration for activity overview and improve validation
- Added support for the "activity_overview" widget in the dashboard configuration, allowing for chart_days validation. - Refactored validation logic to streamline error handling for both "body_overview" and "activity_overview" widgets. - Updated the widget catalog description to reflect the new configuration options. - Enhanced the DashboardLabPage to manage chart_days input for both widgets, improving user experience. - Bumped app_dashboard version to 1.3.0 to reflect these enhancements.
This commit is contained in:
1 parent
4493b140bd
commit
b617212145
9 files changed
+164
-60
No files matched your search
@@ -11,7 +11,7 @@ from typing import Any
|
||||
|
||||
MAX_WIDGET_CONFIG_JSON_BYTES = 1024
|
||||
|
||||
WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({"body_overview"})
|
||||
WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({"body_overview", "activity_overview"})
|
||||
|
||||
|
||||
def _config_json_size_bytes(config: dict[str, Any]) -> int:
|
||||
@@ -32,33 +32,35 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
raise ValueError(f"Widget {widget_id}: keine Konfiguration unterstützt")
|
||||
|
||||
if widget_id == "body_overview":
|
||||
return _validate_body_overview_config(raw)
|
||||
return _validate_chart_days_only(raw, label="body_overview")
|
||||
if widget_id == "activity_overview":
|
||||
return _validate_chart_days_only(raw, label="activity_overview")
|
||||
|
||||
raise ValueError(f"Widget {widget_id}: keine Konfiguration unterstützt")
|
||||
|
||||
|
||||
def _validate_body_overview_config(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
def _parse_chart_days(v: Any, label: str) -> int:
|
||||
if isinstance(v, bool):
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
if isinstance(v, float):
|
||||
if not math.isfinite(v):
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
if abs(v - round(v)) > 1e-9:
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
return int(round(v))
|
||||
if isinstance(v, int):
|
||||
return v
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
|
||||
|
||||
def _validate_chart_days_only(raw: dict[str, Any], *, label: str) -> dict[str, Any]:
|
||||
allowed = frozenset({"chart_days"})
|
||||
unknown = set(raw) - allowed
|
||||
if unknown:
|
||||
raise ValueError(f"body_overview: unbekannte config-Felder: {sorted(unknown)}")
|
||||
out: dict[str, Any] = {}
|
||||
raise ValueError(f"{label}: unbekannte config-Felder: {sorted(unknown)}")
|
||||
if "chart_days" not in raw:
|
||||
return out
|
||||
v = raw["chart_days"]
|
||||
if isinstance(v, bool):
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
if isinstance(v, float):
|
||||
if not math.isfinite(v):
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
if abs(v - round(v)) > 1e-9:
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
v = int(round(v))
|
||||
elif isinstance(v, int):
|
||||
pass
|
||||
else:
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
return {}
|
||||
v = _parse_chart_days(raw["chart_days"], label)
|
||||
if v < 7 or v > 90:
|
||||
raise ValueError("body_overview: chart_days muss zwischen 7 und 90 liegen")
|
||||
out["chart_days"] = v
|
||||
return out
|
||||
raise ValueError(f"{label}: chart_days muss zwischen 7 und 90 liegen")
|
||||
return {"chart_days": v}
|
||||
@@ -24,6 +24,17 @@ def test_body_unknown_key():
|
||||
validate_widget_entry_config("body_overview", {"chart_days": 30, "extra": 1})
|
||||
|
||||
|
||||
def test_activity_chart_days():
|
||||
assert validate_widget_entry_config("activity_overview", {"chart_days": 14}) == {"chart_days": 14}
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("activity_overview", {"chart_days": 5})
|
||||
|
||||
|
||||
def test_kpi_config_rejected():
|
||||
with pytest.raises(ValueError):
|
||||
validate_widget_entry_config("kpi_board", {"chart_days": 30})
|
||||
|
||||
|
||||
def test_layout_payload_with_chart_days_roundtrip():
|
||||
p = DashboardLayoutPayload.model_validate(
|
||||
{
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ MODULE_VERSIONS = {
|
||||
"importdata": "1.0.0",
|
||||
"membership": "2.1.0",
|
||||
"workflow": "0.6.0", # Phase 4: End Node Template Engine
|
||||
"app_dashboard": "1.2.0", # Widget-Config (body_overview.chart_days) + Validierung
|
||||
"app_dashboard": "1.3.0", # activity_overview.chart_days + WidgetErrorBoundary
|
||||
}
|
||||
|
||||
CHANGELOG = [
|
||||
|
||||
@@ -40,7 +40,7 @@ WIDGET_CATALOG: list[WidgetCatalogEntry] = [
|
||||
{
|
||||
"id": "activity_overview",
|
||||
"title": "Aktivität",
|
||||
"description": "Training & Konsistenz",
|
||||
"description": "Training & Konsistenz (optional: config chart_days 7–90)",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Reference in new issue
Block a user