feat: Enhance dashboard layout and widget configuration
- Updated dashboard layout schema to introduce separate default layouts for product and lab dashboards. - Added new functions for managing product and lab default layouts, improving user customization options. - Updated app_dashboard version to 1.9.0 to reflect the introduction of product vs lab layout defaults and new API fields for dashboard configuration. - Enhanced tests to validate new layout functionalities and ensure proper widget visibility based on user settings.
This commit is contained in:
1 parent
9bc0cf70da
commit
e4e2f23d7f
12 files changed
+592
-417
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Dashboard-Layout v1 (Nutzer-Lab): Validierung und Standard-Layout.
|
||||
Dashboard-Layout v1: Validierung, Produkt-Standard (Übersicht) und Lab-Standard.
|
||||
|
||||
Erlaubte Widget-IDs und Standard-Reihenfolge: widget_catalog.WIDGET_CATALOG
|
||||
Erlaubte Widget-IDs und Reihenfolge: widget_catalog.WIDGET_CATALOG.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -10,7 +10,12 @@ from typing import Any, Literal
|
||||
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, DEFAULT_LAB_WIDGET_IDS, WIDGET_CATALOG
|
||||
from widget_catalog import (
|
||||
ALLOWED_WIDGET_IDS,
|
||||
DEFAULT_LAB_WIDGET_IDS,
|
||||
DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS,
|
||||
WIDGET_CATALOG,
|
||||
)
|
||||
|
||||
# Abwärtskompatibel (Tests importieren weiterhin aus diesem Modul)
|
||||
__all__ = [
|
||||
@@ -19,10 +24,13 @@ __all__ = [
|
||||
"DashboardWidgetEntry",
|
||||
"coalesce_effective_layout",
|
||||
"default_layout_dict",
|
||||
"lab_default_layout_dict",
|
||||
"product_default_layout_dict",
|
||||
]
|
||||
|
||||
|
||||
def default_layout_dict() -> dict[str, Any]:
|
||||
def lab_default_layout_dict() -> dict[str, Any]:
|
||||
"""Standard für Dashboard-Lab (Experimentier-Widgets)."""
|
||||
on = DEFAULT_LAB_WIDGET_IDS
|
||||
return {
|
||||
"version": 1,
|
||||
@@ -30,6 +38,20 @@ def default_layout_dict() -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def product_default_layout_dict() -> dict[str, Any]:
|
||||
"""System-Standard für die Produkt-Übersicht (kein DB-Override)."""
|
||||
on = DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
|
||||
return {
|
||||
"version": 1,
|
||||
"widgets": [{"id": e["id"], "enabled": e["id"] in on} for e in WIDGET_CATALOG],
|
||||
}
|
||||
|
||||
|
||||
def default_layout_dict() -> dict[str, Any]:
|
||||
"""Alias: Produkt-Standard (coalesce, Reset). Lab nutzt lab_default_layout_dict()."""
|
||||
return product_default_layout_dict()
|
||||
|
||||
|
||||
class DashboardWidgetEntry(BaseModel):
|
||||
id: str = Field(min_length=1, max_length=64)
|
||||
enabled: bool = True
|
||||
|
||||
@@ -9,7 +9,12 @@ from fastapi import APIRouter, Depends, Header, HTTPException
|
||||
from psycopg2.extras import Json
|
||||
|
||||
from auth import require_auth
|
||||
from dashboard_layout_schema import DashboardLayoutPayload, coalesce_effective_layout, default_layout_dict
|
||||
from dashboard_layout_schema import (
|
||||
DashboardLayoutPayload,
|
||||
coalesce_effective_layout,
|
||||
lab_default_layout_dict,
|
||||
product_default_layout_dict,
|
||||
)
|
||||
from dashboard_widget_entitlements import apply_entitlements_to_layout_dict, widgets_catalog_payload
|
||||
from db import get_cursor, get_db
|
||||
from routers.profiles import get_pid
|
||||
@@ -47,11 +52,13 @@ def get_dashboard_layout(
|
||||
custom, effective = coalesce_effective_layout(raw)
|
||||
with get_db() as conn:
|
||||
effective = apply_entitlements_to_layout_dict(effective, pid, conn)
|
||||
default_adj = apply_entitlements_to_layout_dict(default_layout_dict(), pid, conn)
|
||||
product_adj = apply_entitlements_to_layout_dict(product_default_layout_dict(), pid, conn)
|
||||
lab_adj = apply_entitlements_to_layout_dict(lab_default_layout_dict(), pid, conn)
|
||||
return {
|
||||
"custom": custom,
|
||||
"layout": effective,
|
||||
"default_layout": default_adj,
|
||||
"product_default_layout": product_adj,
|
||||
"lab_default_layout": lab_adj,
|
||||
}
|
||||
|
||||
|
||||
@@ -100,4 +107,5 @@ def reset_dashboard_layout(
|
||||
)
|
||||
if cur.rowcount == 0:
|
||||
raise HTTPException(404, "Profil nicht gefunden")
|
||||
return {"ok": True, "layout": default_layout_dict()}
|
||||
cleared = apply_entitlements_to_layout_dict(product_default_layout_dict(), pid, conn)
|
||||
return {"ok": True, "layout": cleared}
|
||||
@@ -6,12 +6,14 @@ from dashboard_layout_schema import (
|
||||
coalesce_effective_layout,
|
||||
default_layout_dict,
|
||||
)
|
||||
from widget_catalog import DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
|
||||
|
||||
|
||||
def test_default_has_all_allowed_ids():
|
||||
d = default_layout_dict()
|
||||
got = {w["id"] for w in d["widgets"]}
|
||||
assert got == ALLOWED_WIDGET_IDS
|
||||
assert {w["id"] for w in d["widgets"] if w["enabled"]} == DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
|
||||
|
||||
|
||||
def test_payload_rejects_duplicate_ids():
|
||||
@@ -32,7 +34,7 @@ def test_payload_requires_one_enabled():
|
||||
DashboardLayoutPayload.model_validate(
|
||||
{
|
||||
"version": 1,
|
||||
"widgets": [{"id": "welcome", "enabled": False}],
|
||||
"widgets": [{"id": "dashboard_greeting", "enabled": False}],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
from dashboard_layout_schema import default_layout_dict
|
||||
from dashboard_widget_entitlements import widgets_catalog_payload
|
||||
from widget_catalog import ALLOWED_WIDGET_IDS, DEFAULT_LAB_WIDGET_IDS, WIDGET_CATALOG
|
||||
from widget_catalog import (
|
||||
ALLOWED_WIDGET_IDS,
|
||||
DEFAULT_LAB_WIDGET_IDS,
|
||||
DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS,
|
||||
WIDGET_CATALOG,
|
||||
)
|
||||
|
||||
|
||||
def test_catalog_ids_unique_and_match_allowed():
|
||||
@@ -17,10 +22,17 @@ def test_default_layout_follows_catalog_order():
|
||||
got = [w["id"] for w in d["widgets"]]
|
||||
assert got == [e["id"] for e in WIDGET_CATALOG]
|
||||
enabled_ids = {w["id"] for w in d["widgets"] if w["enabled"]}
|
||||
assert enabled_ids == DEFAULT_LAB_WIDGET_IDS
|
||||
assert enabled_ids == DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
|
||||
assert any(w["enabled"] for w in d["widgets"])
|
||||
|
||||
|
||||
def test_lab_default_matches_lab_widget_ids():
|
||||
from dashboard_layout_schema import lab_default_layout_dict
|
||||
|
||||
d = lab_default_layout_dict()
|
||||
assert {w["id"] for w in d["widgets"] if w["enabled"]} == DEFAULT_LAB_WIDGET_IDS
|
||||
|
||||
|
||||
def test_catalog_payload_shape(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"dashboard_widget_entitlements._check_feature_access",
|
||||
|
||||
+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.8.0", # widget catalog allowed via features; layout entitlements on GET/PUT
|
||||
"app_dashboard": "1.9.0", # product vs lab layout defaults; user dashboard configure page API fields
|
||||
}
|
||||
|
||||
CHANGELOG = [
|
||||
|
||||
@@ -133,4 +133,21 @@ DEFAULT_LAB_WIDGET_IDS: frozenset[str] = frozenset(
|
||||
}
|
||||
)
|
||||
|
||||
# Produkt-Übersicht (/): Default wenn Nutzer kein dashboard_layout in der DB hat (Physisch: nur Profil-JSON).
|
||||
DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS: frozenset[str] = frozenset(
|
||||
{
|
||||
"dashboard_greeting",
|
||||
"quick_weight_today",
|
||||
"body_stat_strip",
|
||||
"status_pills",
|
||||
"trend_kcal_weight",
|
||||
"nutrition_activity_summary",
|
||||
"activity_overview",
|
||||
"recovery_sleep_rest",
|
||||
"goals_focus_teaser",
|
||||
"profile_goals_progress",
|
||||
"ai_pipeline_insight",
|
||||
}
|
||||
)
|
||||
|
||||
ALLOWED_WIDGET_IDS: frozenset[str] = frozenset(e["id"] for e in WIDGET_CATALOG)
|
||||
Reference in new issue
Block a user