Skip to content

Commit

Permalink
Fix example content wrapper plugin callback (#607)
Browse files Browse the repository at this point in the history
Remove prefix `_` in `set_callbacks` and remove usage of `_plugin_wrapper_id`
  • Loading branch information
jorgenherje authored Aug 10, 2022
1 parent c19dab9 commit dafdf68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion webviz_config/_localhost_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _check_for_ott_or_cookie(): # type: ignore[no-untyped-def]
else:
flask.abort(401)

@self._app.after_request # type: ignore[arg-type]
@self._app.after_request
def _set_cookie_token_in_response(
response: flask.wrappers.Response,
) -> flask.wrappers.Response:
Expand Down
18 changes: 7 additions & 11 deletions webviz_config/_plugin_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,34 +312,30 @@ def get_all_settings(self) -> List[html.Div]:
shared_settings = self.shared_settings_groups()
if shared_settings is not None:
settings = [
setting._wrapped_layout("", self._plugin_wrapper_id)
setting._wrapped_layout("", self._plugin_unique_id.to_string())
for setting in shared_settings
]

for view in self._views:
settings.extend(
[
setting._wrapped_layout(
view[1].unique_id(), self._plugin_wrapper_id
view[1].unique_id(), self._plugin_unique_id.to_string()
)
for setting in view[1].settings_groups()
]
)

return settings

@property
def _plugin_wrapper_id(self) -> str:
return f"plugin-wrapper-{self._plugin_unique_id}"

@property
def plugin_data_output(self) -> Output:
self._add_download_button = True
return Output(self._plugin_wrapper_id, "download")
return Output(self._plugin_unique_id.to_string(), "download")

@property
def plugin_data_requested(self) -> Input:
return Input(self._plugin_wrapper_id, "data_requested")
return Input(self._plugin_unique_id.to_string(), "data_requested")

@staticmethod
def _reformat_tour_steps(steps: List[dict]) -> List[dict]:
Expand Down Expand Up @@ -495,7 +491,7 @@ def plugin_layout(
for store in self._stores
] + [
wcc.WebvizPluginWrapper(
id=self._plugin_wrapper_id,
id=self._plugin_unique_id.to_string(),
name=type(self).__name__,
views=[
{
Expand Down Expand Up @@ -535,7 +531,7 @@ def plugin_layout(

def _set_wrapper_callbacks(self) -> None:
@callback(
Output(self._plugin_wrapper_id, "children"),
Output(self._plugin_unique_id.to_string(), "children"),
Input("webviz-content-manager", "activeViewId"),
Input("webviz-content-manager", "activePluginId"),
)
Expand All @@ -552,7 +548,7 @@ def change_view(view_id: str, plugin_id: str) -> Component:
if initial_call:
view_id = self.active_view_id

if plugin_id == self._plugin_wrapper_id or initial_call:
if plugin_id == self._plugin_unique_id.to_string() or initial_call:
view = next(
(
view[1]
Expand Down
13 changes: 7 additions & 6 deletions webviz_config/generic_plugins/_example_wlf_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def download_data_df(graph_figure: Dict[str, Any]) -> pd.DataFrame:
df["y"] = y_values
return df

def _set_callbacks(self) -> None:
def set_callbacks(self) -> None:
@callback(
self.view_element_data_output(),
self.view_element_data_requested(),
Expand Down Expand Up @@ -182,7 +182,7 @@ def download_data_df(table_data: List[Dict[str, int]]) -> pd.DataFrame:
df["y"] = y_values
return df

def _set_callbacks(self) -> None:
def set_callbacks(self) -> None:
@callback(
self.view_element_data_output(),
self.view_element_data_requested(),
Expand Down Expand Up @@ -339,7 +339,7 @@ def __init__(self, data: List[Tuple[int, int]]) -> None:

self.add_settings_group(PlotViewSettingsGroup(), PlotView.Ids.PLOT_SETTINGS)

def _set_callbacks(self) -> None:
def set_callbacks(self) -> None:
@callback(
self.view_data_output(),
self.view_data_requested(),
Expand Down Expand Up @@ -395,7 +395,7 @@ def __init__(
TableViewSettingsGroup(), settings_group_id=TableView.Ids.TABLE_SETTINGS
)

def _set_callbacks(self) -> None:
def set_callbacks(self) -> None:
@callback(
Output(
self.table_view.component_unique_id(
Expand All @@ -405,7 +405,8 @@ def _set_callbacks(self) -> None:
),
Input(
self.settings_group_unique_id(
"Settings", TableViewSettingsGroup.Ids.ORDER_SELECTOR
TableView.Ids.TABLE_SETTINGS,
TableViewSettingsGroup.Ids.ORDER_SELECTOR,
),
"value",
),
Expand Down Expand Up @@ -514,7 +515,7 @@ def tour_steps(self) -> List[dict]:
},
]

def _set_callbacks(self) -> None:
def set_callbacks(self) -> None:
@callback(
Output(
self.view(ExampleWlfPlugin.Ids.PLOT_VIEW)
Expand Down

0 comments on commit dafdf68

Please sign in to comment.