feat: implement DashboardWidgetProvider pattern for modular dashboard widgets
Add protocol-based widget system following the MetricsProvider pattern: - Create DashboardWidgetProviderProtocol in contracts/widgets.py - Add WidgetAggregatorService in core to discover and aggregate widgets - Implement MarketplaceWidgetProvider for recent_imports widget - Implement TenancyWidgetProvider for recent_vendors widget - Update admin dashboard to use widget_aggregator - Add widget_provider field to ModuleDefinition Architecture documentation: - Add widget-provider-pattern.md with implementation guide - Add cross-module-import-rules.md enforcing core/optional separation - Update module-system.md with widget_provider and import rules This enables modules to provide rich dashboard widgets without core modules importing from optional modules, maintaining true module independence. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,17 @@ Metrics Provider Pattern:
|
||||
|
||||
def get_vendor_metrics(self, db, vendor_id, context=None) -> list[MetricValue]:
|
||||
return [MetricValue(key="orders.total", value=42, label="Total", category="orders")]
|
||||
|
||||
Widget Provider Pattern:
|
||||
from app.modules.contracts.widgets import DashboardWidgetProviderProtocol, DashboardWidget
|
||||
|
||||
class OrderWidgetProvider:
|
||||
@property
|
||||
def widgets_category(self) -> str:
|
||||
return "orders"
|
||||
|
||||
def get_vendor_widgets(self, db, vendor_id, context=None) -> list[DashboardWidget]:
|
||||
return [DashboardWidget(key="orders.recent", widget_type="list", ...)]
|
||||
"""
|
||||
|
||||
from app.modules.contracts.base import ServiceProtocol
|
||||
@@ -41,6 +52,15 @@ from app.modules.contracts.metrics import (
|
||||
MetricsContext,
|
||||
MetricsProviderProtocol,
|
||||
)
|
||||
from app.modules.contracts.widgets import (
|
||||
BreakdownWidget,
|
||||
DashboardWidget,
|
||||
DashboardWidgetProviderProtocol,
|
||||
ListWidget,
|
||||
WidgetBreakdownItem,
|
||||
WidgetContext,
|
||||
WidgetListItem,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# Base protocols
|
||||
@@ -51,4 +71,12 @@ __all__ = [
|
||||
"MetricValue",
|
||||
"MetricsContext",
|
||||
"MetricsProviderProtocol",
|
||||
# Widget protocols
|
||||
"WidgetContext",
|
||||
"WidgetListItem",
|
||||
"WidgetBreakdownItem",
|
||||
"ListWidget",
|
||||
"BreakdownWidget",
|
||||
"DashboardWidget",
|
||||
"DashboardWidgetProviderProtocol",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user