diff --git a/src/figures.py b/src/figures.py index c2a04a7..482d56e 100644 --- a/src/figures.py +++ b/src/figures.py @@ -1098,7 +1098,12 @@ AG_GRID_LOCALE_FR = { } -def ag_grid(grid_id: str, column_defs: list[dict]) -> "dag.AgGrid": +def ag_grid( + grid_id: "str | dict", + column_defs: list[dict], + persisted_props=("filterModel", "columnState"), + persistence: bool = True, +) -> "dag.AgGrid": """Grille AG Grid server-side (infinite) pour la page Tableau. Thème aligné sur les dash_table.DataTable du reste du site (en-tête @@ -1156,7 +1161,7 @@ def ag_grid(grid_id: str, column_defs: list[dict]) -> "dag.AgGrid": # apparaître le défilement horizontal natif d'AG Grid plutôt que de # les compresser/étirer toutes à la même largeur. style={"height": "70vh", "width": "100%"}, - persistence=True, + persistence=persistence, persistence_type="local", - persisted_props=["filterModel", "columnState"], + persisted_props=list(persisted_props), ) diff --git a/tests/test_figures.py b/tests/test_figures.py index 20f5834..9b91e11 100644 --- a/tests/test_figures.py +++ b/tests/test_figures.py @@ -381,3 +381,27 @@ def test_ag_grid_always_shows_horizontal_scroll(): grid = ag_grid("tableau_grid", []) assert grid.dashGridOptions["alwaysShowHorizontalScroll"] is True + + +def test_ag_grid_accepts_dict_id_and_custom_persisted_props(): + """Grille entité : id pattern-matching + persistance limitée au filterModel + (columnState géré via un store partagé, pas la persistance native).""" + from src.figures import ag_grid + + gid = {"type": "acheteur-grid", "entity_id": "123", "year": "Toutes les années"} + grid = ag_grid(gid, [], persisted_props=["filterModel"]) + + assert grid.id == gid + assert list(grid.persisted_props) == ["filterModel"] + assert grid.persistence is True + + +def test_ag_grid_defaults_unchanged_for_tableau(): + """Sans args de persistance, comportement identique au Lot 1 (tableau.py).""" + from src.figures import ag_grid + + grid = ag_grid("tableau_grid", []) + + assert grid.id == "tableau_grid" + assert list(grid.persisted_props) == ["filterModel", "columnState"] + assert grid.persistence is True