diff --git a/vizro-core/src/vizro/actions/_action_loop/_build_action_loop_callbacks.py b/vizro-core/src/vizro/actions/_action_loop/_build_action_loop_callbacks.py index 94f2789d9..b462156db 100644 --- a/vizro-core/src/vizro/actions/_action_loop/_build_action_loop_callbacks.py +++ b/vizro-core/src/vizro/actions/_action_loop/_build_action_loop_callbacks.py @@ -30,7 +30,7 @@ def _build_action_loop_callbacks() -> None: actions_chain_trigger_component = model_manager[ModelID(str(actions_chain_trigger_component_id))] # Use underlying table object as a trigger component. if isinstance(actions_chain_trigger_component, Table): - actions_chain_trigger_component_id = actions_chain_trigger_component._underlying_table_id + actions_chain_trigger_component_id = actions_chain_trigger_component._callable_object_id # Not all action_chain_trigger_components are included in model_manager e.g. on_page_load_action_trigger except KeyError: pass diff --git a/vizro-core/src/vizro/actions/_actions_utils.py b/vizro-core/src/vizro/actions/_actions_utils.py index ed0e0c4dc..7356cbd2e 100644 --- a/vizro-core/src/vizro/actions/_actions_utils.py +++ b/vizro-core/src/vizro/actions/_actions_utils.py @@ -92,7 +92,7 @@ def _get_parent_vizro_table(_underlying_table_id: str) -> Table: from vizro.models import Table for _, table in model_manager._items_with_type(Table): - if table._underlying_table_id == _underlying_table_id: + if table._callable_object_id == _underlying_table_id: return table raise KeyError(f"No parent Vizro.Table component found for underlying table with id {_underlying_table_id}.") @@ -105,12 +105,7 @@ def _apply_table_filter_interaction( if not ctd_active_cell["value"] or not ctd_derived_viewport_data["value"]: return data_frame - source_table_id = ctd_active_cell["id"] - try: - source_table_actions = _get_component_actions(model_manager[source_table_id]) - except KeyError: - # source_table_id is underlying table id, so actions from parent Vizro.Table component should be considered. - source_table_actions = _get_component_actions(_get_parent_vizro_table(source_table_id)) + source_table_actions = _get_component_actions(_get_parent_vizro_table(ctd_active_cell["id"])) for action in source_table_actions: if target not in action.function["targets"]: diff --git a/vizro-core/src/vizro/actions/_callback_mapping/_callback_mapping_utils.py b/vizro-core/src/vizro/actions/_callback_mapping/_callback_mapping_utils.py index 79561cae8..e5c2368a3 100644 --- a/vizro-core/src/vizro/actions/_callback_mapping/_callback_mapping_utils.py +++ b/vizro-core/src/vizro/actions/_callback_mapping/_callback_mapping_utils.py @@ -111,10 +111,10 @@ def _get_inputs_of_figure_interactions( inputs.append( { "active_cell": State( - component_id=triggered_model._underlying_table_id, component_property="active_cell" + component_id=triggered_model._callable_object_id, component_property="active_cell" ), "derived_viewport_data": State( - component_id=triggered_model._underlying_table_id, + component_id=triggered_model._callable_object_id, component_property="derived_viewport_data", ), } diff --git a/vizro-core/src/vizro/models/_components/table.py b/vizro-core/src/vizro/models/_components/table.py index bb2f96bf4..960b7ddef 100644 --- a/vizro-core/src/vizro/models/_components/table.py +++ b/vizro-core/src/vizro/models/_components/table.py @@ -32,7 +32,7 @@ class Table(VizroBaseModel): title: Optional[str] = Field(None, description="Title of the table") actions: List[Action] = [] - _underlying_table_id: str = PrivateAttr() + _callable_object_id: str = PrivateAttr() # Component properties for actions and interactions _output_property: str = PrivateAttr("children") @@ -72,7 +72,7 @@ def pre_build(self): " Underlying table object has to be provided." ) - self._underlying_table_id = underlying_table_object.id + self._callable_object_id = underlying_table_object.id def build(self): return dcc.Loading( @@ -80,7 +80,7 @@ def build(self): [ html.H3(self.title, className="table-title") if self.title else None, html.Div( - dash_table.DataTable(**({"id": self._underlying_table_id} if self.actions else {})), id=self.id + dash_table.DataTable(**({"id": self._callable_object_id} if self.actions else {})), id=self.id ), ], className="table-container", diff --git a/vizro-core/tests/unit/vizro/actions/test_export_data_action.py b/vizro-core/tests/unit/vizro/actions/test_export_data_action.py index 9fae41336..4e787129e 100644 --- a/vizro-core/tests/unit/vizro/actions/test_export_data_action.py +++ b/vizro-core/tests/unit/vizro/actions/test_export_data_action.py @@ -71,14 +71,14 @@ def callback_context_export_data(request): args_grouping_filter_interaction.append( { "active_cell": CallbackTriggerDict( - id="vizro_table", + id="underlying_table_id", property="active_cell", value={"row": 0, "column": 0, "column_id": "country"}, - str_id="vizro_table", + str_id="underlying_table_id", triggered=False, ), "derived_viewport_data": CallbackTriggerDict( - id="vizro_table", + id="underlying_table_id", property="derived_viewport_data", value=[ { @@ -92,7 +92,7 @@ def callback_context_export_data(request): "year": 2007, }, ], - str_id="vizro_table", + str_id="underlying_table_id", triggered=False, ), } @@ -307,9 +307,8 @@ def test_multiple_targets_with_filter_and_filter_interaction_and_table( ] # Add table filter_interaction Action to scatter_chart component - model_manager["vizro_table"].actions = [ - vm.Action(id="table_filter_interaction", function=filter_interaction(targets=["scatter_chart"])) - ] + model_manager["vizro_table"].actions = [vm.Action(function=filter_interaction(targets=["scatter_chart"]))] + model_manager["vizro_table"].pre_build() # Add export_data action to relevant component model_manager["button"].actions = [ diff --git a/vizro-core/tests/unit/vizro/actions/test_filter_interaction_action.py b/vizro-core/tests/unit/vizro/actions/test_filter_interaction_action.py index 95757a991..4e7031801 100644 --- a/vizro-core/tests/unit/vizro/actions/test_filter_interaction_action.py +++ b/vizro-core/tests/unit/vizro/actions/test_filter_interaction_action.py @@ -42,7 +42,7 @@ def callback_context_filter_interaction(request): id="underlying_table_id", property="active_cell", value={"row": 0, "column": 0, "column_id": "country"}, - str_id="vizro_table", + str_id="underlying_table_id", triggered=False, ), "derived_viewport_data": CallbackTriggerDict( @@ -60,7 +60,7 @@ def callback_context_filter_interaction(request): "year": 2007, }, ], - str_id="vizro_table", + str_id="underlying_table_id", triggered=False, ), } diff --git a/vizro-core/tests/unit/vizro/models/_components/test_table.py b/vizro-core/tests/unit/vizro/models/_components/test_table.py index 63ecb230e..e4cd3b7ed 100644 --- a/vizro-core/tests/unit/vizro/models/_components/test_table.py +++ b/vizro-core/tests/unit/vizro/models/_components/test_table.py @@ -50,7 +50,9 @@ def expected_table_with_id(): ], className="table-container", id="text_table_outer", - ) + ), + color="grey", + parent_className="loading-container", ) @@ -141,7 +143,7 @@ def test_pre_build_no_actions_no_underlying_table_id(self, standard_dash_table): ) table.pre_build() - assert hasattr(table, "_underlying_table_id") is False + assert hasattr(table, "_callable_object_id") is False def test_pre_build_actions_no_underlying_table_id_exception(self, standard_dash_table, filter_interaction_action): table = vm.Table( @@ -160,8 +162,8 @@ def test_pre_build_actions_underlying_table_id(self, dash_data_table_with_id, fi ) table.pre_build() - assert hasattr(table, "_underlying_table_id") is True - assert table._underlying_table_id == "underlying_table_id" + assert hasattr(table, "_callable_object_id") is True + assert table._callable_object_id == "underlying_table_id" class TestBuildTable: