feat: implement merge_missing_catalog_widgets function to enhance dashboard layout
- Added the `merge_missing_catalog_widgets` function to append missing widget IDs from the catalog to the dashboard layout while preserving the existing order. - Updated the admin and app dashboard routes to utilize the new function, ensuring that new catalog entries are visible without requiring users to reset their layouts. - Enhanced tests to validate the functionality of the new merging logic, ensuring proper integration with existing layouts. - Bumped application version to reflect these changes.
This commit is contained in:
1 parent
2453da0da1
commit
01c0d1745f
6 files changed
+53
-6
No files matched your search
@@ -5,6 +5,7 @@ from dashboard_layout_schema import (
|
||||
DashboardLayoutPayload,
|
||||
coalesce_effective_layout,
|
||||
default_layout_dict,
|
||||
merge_missing_catalog_widgets,
|
||||
)
|
||||
from widget_catalog import DEFAULT_PRODUCT_DASHBOARD_WIDGET_IDS
|
||||
|
||||
@@ -56,3 +57,19 @@ def test_coalesce_valid_raw():
|
||||
custom, eff = coalesce_effective_layout(raw)
|
||||
assert custom is True
|
||||
assert eff == raw
|
||||
|
||||
|
||||
def test_merge_missing_catalog_widgets_keeps_order_and_fills_ids():
|
||||
raw = {
|
||||
"version": 1,
|
||||
"widgets": [
|
||||
{"id": "kpi_board", "enabled": True, "config": {}},
|
||||
{"id": "welcome", "enabled": False, "config": {}},
|
||||
],
|
||||
}
|
||||
merged = merge_missing_catalog_widgets(raw)
|
||||
assert [w["id"] for w in merged["widgets"][:2]] == ["kpi_board", "welcome"]
|
||||
assert {w["id"] for w in merged["widgets"]} == ALLOWED_WIDGET_IDS
|
||||
extra = [w for w in merged["widgets"] if w["id"] not in ("kpi_board", "welcome")]
|
||||
assert all(w["enabled"] is False for w in extra)
|
||||
DashboardLayoutPayload.model_validate(merged)
|
||||
Reference in new issue
Block a user