Coverage for src/lexigram/admin/ui/organisms/data_table/views.py: 42%
33 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 14:56 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 14:56 +0800
1"""View strategy handling for data table component."""
3from __future__ import annotations
5from typing import Any
7from lexigram.admin.config import TableConfiguration
8from lexigram.ui import TableState
11class ViewStrategy:
12 """Base class for view strategies."""
14 def __init__(
15 self,
16 data: list[dict],
17 config: TableConfiguration,
18 state: TableState,
19 total: int | None,
20 summary: dict[str, Any] | None = None,
21 user: Any = None,
22 resource_name: str | None = None,
23 ):
24 self.data = data
25 self.config = config
26 self.state = state
27 self.total = total
28 self.summary = summary
29 self.user = user
30 self.resource_name = resource_name
32 def render(self) -> Any:
33 """Render the view."""
34 raise NotImplementedError
37class ViewFactory:
38 """Factory for creating view strategies."""
40 @staticmethod
41 def create_view(
42 view_type: str,
43 data: list[dict],
44 config: TableConfiguration,
45 state: TableState,
46 total: int | None,
47 summary: dict[str, Any] | None = None,
48 user: Any = None,
49 resource_name: str | None = None,
50 ) -> ViewStrategy:
51 """Create a view strategy instance."""
52 total_count: int = total if total is not None else 0
53 if view_type == "tabular":
54 from lexigram.admin.ui.organisms.table.views.tabular import TabularView
56 return TabularView(
57 data, config, state, total_count, summary, user, resource_name
58 ) # type: ignore[return-value]
59 if view_type == "grid":
60 from lexigram.admin.ui.organisms.table.views.grid import GridView
62 return GridView(
63 data, config, state, total_count, summary, user, resource_name
64 ) # type: ignore[return-value]
65 if view_type == "calendar":
66 from lexigram.admin.ui.organisms.table.views.calendar import CalendarView
68 return CalendarView( # type: ignore[return-value]
69 data,
70 config,
71 state,
72 total_count,
73 summary,
74 user,
75 resource_name,
76 )
77 if view_type == "stacked":
78 from lexigram.admin.ui.organisms.table.views.stacked import StackedView
80 return StackedView(
81 data, config, state, total_count, summary, user, resource_name
82 ) # type: ignore[return-value]
83 # Default to tabular
84 from lexigram.admin.ui.organisms.table.views.tabular import TabularView
86 return TabularView(
87 data, config, state, total_count, summary, user, resource_name
88 ) # type: ignore[return-value]