From 4c3924653c2db277d9200dbd010005d043a1a6f6 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 2 May 2024 09:27:59 +0200 Subject: [PATCH] TBR Removing DF breaks filter persistence on page change --- .../src/vizro/models/_components/ag_grid.py | 7 ++++--- .../vizro/models/_components/test_ag_grid.py | 18 ++++++++++++------ .../unit/vizro/tables/test_dash_ag_grid.py | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/vizro-core/src/vizro/models/_components/ag_grid.py b/vizro-core/src/vizro/models/_components/ag_grid.py index dde7f3b22..19235b8da 100644 --- a/vizro-core/src/vizro/models/_components/ag_grid.py +++ b/vizro-core/src/vizro/models/_components/ag_grid.py @@ -103,7 +103,8 @@ def build(self): Output(self._input_component_id, "className"), Input("theme_selector", "checked"), ) - + grid = self.__call__() + grid.rowData = [] return dcc.Loading( [ html.H3(self.title, className="table-title") if self.title else None, @@ -111,9 +112,9 @@ def build(self): # here) must have the same setting as the object that is built by the on-page-load mechanism using # with the user settings and rendered finally. Otherwise the grid is not rendered correctly. # Hence be careful when editing the line below. - html.Div(self.__call__(), id=self.id, className="table-container"), + html.Div(grid, id=self.id, className="table-container"), ], id=f"{self.id}_outer", color="grey", parent_className="loading-container", - ) + ) \ No newline at end of file diff --git a/vizro-core/tests/unit/vizro/models/_components/test_ag_grid.py b/vizro-core/tests/unit/vizro/models/_components/test_ag_grid.py index db132a0f3..5fc654a52 100644 --- a/vizro-core/tests/unit/vizro/models/_components/test_ag_grid.py +++ b/vizro-core/tests/unit/vizro/models/_components/test_ag_grid.py @@ -120,11 +120,13 @@ def test_ag_grid_build_mandatory_only(self, standard_ag_grid, gapminder): ag_grid = vm.AgGrid(id="text_ag_grid", figure=standard_ag_grid) ag_grid.pre_build() ag_grid = ag_grid.build() - expected_ag_grid = dcc.Loading( + expected_ag_grid = dash_ag_grid(data_frame=gapminder, id="__input_text_ag_grid")() + expected_ag_grid.rowData = [] + expected_build_result = dcc.Loading( [ None, html.Div( - dash_ag_grid(data_frame=gapminder, id="__input_text_ag_grid")(), + expected_ag_grid, id="text_ag_grid", className="table-container", ), @@ -134,20 +136,24 @@ def test_ag_grid_build_mandatory_only(self, standard_ag_grid, gapminder): parent_className="loading-container", ) - assert_component_equal(ag_grid, expected_ag_grid) + assert_component_equal(ag_grid, expected_build_result) def test_ag_grid_build_with_underlying_id(self, ag_grid_with_id_and_conf, filter_interaction_action, gapminder): ag_grid = vm.AgGrid(id="text_ag_grid", figure=ag_grid_with_id_and_conf, actions=[filter_interaction_action]) ag_grid.pre_build() ag_grid = ag_grid.build() + expected_ag_grid = dash_ag_grid( + data_frame=gapminder, id="underlying_ag_grid_id", + )() + expected_ag_grid.rowData = [] + + expected_ag_grid = dcc.Loading( [ None, html.Div( - dash_ag_grid( - data_frame=gapminder, id="underlying_ag_grid_id", dashGridOptions={"pagination": True} - )(), + expected_ag_grid, id="text_ag_grid", className="table-container", ), diff --git a/vizro-core/tests/unit/vizro/tables/test_dash_ag_grid.py b/vizro-core/tests/unit/vizro/tables/test_dash_ag_grid.py index a74eba7d3..2c6920509 100644 --- a/vizro-core/tests/unit/vizro/tables/test_dash_ag_grid.py +++ b/vizro-core/tests/unit/vizro/tables/test_dash_ag_grid.py @@ -76,7 +76,7 @@ def custom_ag_grid(data_frame): [ None, html.Div( - dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=row_data_date_raw), + dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=[]), id=id, className="table-container", ), @@ -114,7 +114,7 @@ def custom_ag_grid(data_frame): [ None, html.Div( - dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=row_data_date_raw), + dag.AgGrid(id="__input_custom_ag_grid", columnDefs=column_defs, rowData=[]), id=id, className="table-container", ),