Skip to content

Commit 70139c8

Browse files
committed
Implement _BaseAction and separate Action and AbstractAction
1 parent eab49cd commit 70139c8

File tree

4 files changed

+185
-150
lines changed

4 files changed

+185
-150
lines changed

vizro-core/examples/scratch_dev/app.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
color="continent",
2222
custom_data=["continent"],
2323
),
24-
# \actions=[filter_interaction(targets=["scatter_relation_2007"])],
25-
actions=[vm.Action(function=filter_interaction(targets=["scatter_relation_2007"]))], # TODO NOW CHECK
24+
actions=[filter_interaction(targets=["scatter_relation_2007"])],
25+
# actions=[vm.Action(function=filter_interaction(targets=["scatter_relation_2007"]))], # TODO NOW CHECK
2626
),
2727
vm.Graph(
2828
id="scatter_relation_2007",
@@ -64,13 +64,13 @@
6464
@capture("action")
6565
# To test legacy=True
6666
# def my_custom_action(points_data, controls=None):
67-
def my_custom_action(t, points_data, controls=None):
67+
def my_custom_action(points_data, controls):
6868
"""Custom action."""
6969
clicked_point = points_data["points"][0]
7070
x, y = clicked_point["x"], clicked_point["y"]
7171
species = clicked_point["customdata"][0]
72-
card_1_text = f"Clicked point has sepal length {x}, petal width {y}. {t=}"
73-
card_2_text = f"Controls are `{controls}`. {t=}"
72+
card_1_text = f"Clicked point has sepal length {x}, petal width {y}."
73+
card_2_text = f"Controls are `{controls}`"
7474
return card_1_text, card_2_text
7575

7676

@@ -101,12 +101,13 @@ def my_custom_action(t, points_data, controls=None):
101101
actions=[
102102
vm.Action(
103103
# function=my_custom_action,
104-
# inputs=["scatter_chart.clickData"],
104+
# ("scatter_chart.clickData"),
105105
# TODO NOW CHECK: make sure user-specified argument continues to take precedence
106106
# function=my_custom_action("scatter_chart.clickData", controls="my_card_1.children"),
107107
# TODO NOW CHECK: test to make sure this old way continues to work
108-
function=my_custom_action(t=4),
109-
inputs=["scatter_chart.clickData"],
108+
# function=my_custom_action(),
109+
# function=my_custom_action(t=4),
110+
# inputs=["scatter_chart.clickData"],
110111
outputs=["my_card_1.children", "my_card_2.children"],
111112
),
112113
],

vizro-core/src/vizro/actions/export_data_action.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from vizro.managers import model_manager
99
from vizro.managers._model_manager import ModelID
1010

11-
"""Pre-defined action function "export_data" to be reused in `action` parameter of VizroBaseModels."""
12-
1311
from collections.abc import Iterable
1412
from typing import Literal, cast
1513

@@ -27,7 +25,7 @@ class export_data(AbstractAction):
2725
] = [] # TODO NOW: think about whether should in future rename this so it doesn't inconsistently use targets? May be ok now that targets doesn't yet have special role.
2826
file_format: Literal["csv", "xlsx"] = "csv"
2927

30-
# TODO NOW: continue testing this and eventually remove.
28+
# TODO NOW CHECK: continue testing this and eventually remove.
3129
runtime_arg: str
3230

3331
def function(
@@ -56,8 +54,6 @@ def function(
5654
# will change in future once the structure of controls has been worked out and we know how to pass ids through.
5755
# See https://github.com/mckinsey/vizro/pull/880
5856
# TODO NOW: move the setting of targets to validator. Reused in outputs and components
59-
# TODO NOW: test this runtime argument
60-
# print(f"{runtime_arg=}")
6157
targets = self.targets or [
6258
output["id"]["target_id"]
6359
for output in ctx.outputs_list
@@ -84,12 +80,12 @@ def function(
8480

8581
return outputs
8682

87-
@property
8883
# TODO NOW: think about if this is best way.
8984
# overrides _outputs_ not outputs
9085
# could convert to string ids and use outputs
9186
# leave like this because hopefully will have single download component in future anyway with a reserved id
92-
def _outputs_(self) -> dict[str, Output]:
87+
@property
88+
def _transformed_outputs(self) -> dict[str, Output]:
9389
# TODO NOW: comment
9490
targets = self.targets or [
9591
model.id
@@ -107,7 +103,11 @@ def _outputs_(self) -> dict[str, Output]:
107103
for target in targets
108104
}
109105

106+
# TODO NOW: just needed due to abstractmethod
110107
@property
108+
def outputs(self):
109+
pass
110+
111111
# TODO NOW: put these thoughts somewhere
112112
# For multiple files could use single dcc.Download but zip file.
113113
# Will need some way to add new components on the fly for other actions though.
@@ -116,7 +116,8 @@ def _outputs_(self) -> dict[str, Output]:
116116
# Petar qn: what other actions would require new components on page?
117117
# Note name clash with "components" and current model_manager __get_model_children that looks for "components"
118118
# for Page.components. Hence call dash_components, which is probably better name anyway.
119-
def dash_components(self) -> list[dcc.Download]:
119+
@property
120+
def _dash_components(self) -> list[dcc.Download]:
120121
"""Creates dcc.Downloads for target components of the `export_data` action."""
121122
targets = self.targets or [
122123
model.id

0 commit comments

Comments
 (0)