feat: Enhance Dashboard widget configuration and layout management
- Added validation for widget configuration in the DashboardWidgetEntry model to ensure proper data structure. - Updated the DashboardLayoutPayload to include widget configuration in the serialized output. - Improved the PilotBodySection and DashboardLabPage components to support dynamic chart days configuration for the body overview widget. - Refactored layout editor functions to normalize widget configurations for better handling. - Bumped app_dashboard version to 1.2.0 to reflect the new features and improvements.
This commit is contained in:
1 parent
f6c5f96768
commit
87c4cbc4b4
11 files changed
+298
-62
No files matched your search
@@ -7,8 +7,9 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator
|
||||
|
||||
from dashboard_widget_config import validate_widget_entry_config
|
||||
from widget_catalog import ALLOWED_WIDGET_IDS, WIDGET_CATALOG
|
||||
|
||||
# Abwärtskompatibel (Tests importieren weiterhin aus diesem Modul)
|
||||
@@ -31,6 +32,21 @@ def default_layout_dict() -> dict[str, Any]:
|
||||
class DashboardWidgetEntry(BaseModel):
|
||||
id: str = Field(min_length=1, max_length=64)
|
||||
enabled: bool = True
|
||||
config: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
@field_validator("config", mode="before")
|
||||
@classmethod
|
||||
def _config_coerce(cls, v: Any) -> dict[str, Any]:
|
||||
if v is None:
|
||||
return {}
|
||||
if not isinstance(v, dict):
|
||||
raise ValueError("config muss Objekt sein")
|
||||
return v
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _normalize_widget_config(self) -> DashboardWidgetEntry:
|
||||
normalized = validate_widget_entry_config(self.id, self.config)
|
||||
return self.model_copy(update={"config": normalized})
|
||||
|
||||
|
||||
class DashboardLayoutPayload(BaseModel):
|
||||
@@ -50,10 +66,13 @@ class DashboardLayoutPayload(BaseModel):
|
||||
return self
|
||||
|
||||
def to_stored_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
"version": self.version,
|
||||
"widgets": [{"id": w.id, "enabled": w.enabled} for w in self.widgets],
|
||||
}
|
||||
out_widgets: list[dict[str, Any]] = []
|
||||
for w in self.widgets:
|
||||
d: dict[str, Any] = {"id": w.id, "enabled": w.enabled}
|
||||
if w.config:
|
||||
d["config"] = dict(w.config)
|
||||
out_widgets.append(d)
|
||||
return {"version": self.version, "widgets": out_widgets}
|
||||
|
||||
|
||||
def coalesce_effective_layout(raw: Any) -> tuple[bool, dict[str, Any]]:
|
||||
|
||||
Reference in new issue
Block a user