Skip to content

Commit

Permalink
fix: bug in custom metric value callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Feb 14, 2025
1 parent e370233 commit 3d831d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/aind_qc_portal/panel/custom_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,31 @@ def _callback_helper(self, event):
"""Helper function for custom metric value callbacks, called by Panel event callback
when the user changes the value of the metric
"""
# Update the value according to the t ype of custom metric
self.update_value(event.new)

# Push the new value into the upstream QCMetric.value field
self._value_callback(self._data)
self._value_callback(event.new)

# Handle state updates
if self._auto_state:
try:
if not self._data.value:
print(f"Value is empty for {self._data}, setting state to PENDING")
self._status_callback(Status.PENDING)
else:
if isinstance(self._data.value, list):
# Check if we're dealing with a checkbox metric
if isinstance(self._data, CheckboxMetric):
values = [self._data.status[self._data.options.index(value)] for value in self._data.value]
if any(values == Status.FAIL for value in values):
self._status_callback(Status.FAIL)
elif any(values == Status.PENDING for value in values):
self._status_callback(Status.PENDING)
else:
self._status_callback(Status.PASS)
else:
elif isinstance(self._data, DropdownMetric):
idx = self._data.options.index(self._data.value)
self._status_callback(self._data.status[idx])
else:
print(f"Unsupported metric type for auto state update: {self._data}")
self._status_callback(Status.PENDING)
except Exception as e:
print(e)
self._status_callback(Status.PENDING)
Expand Down
2 changes: 1 addition & 1 deletion src/aind_qc_portal/panel/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _set_status(self, status: Status | str):
status = Status(status)
print(f"Updating metric status to: {status.value}")

if self.state_selector:
if self.state_selector and self.state_selector.value != status.value:
self.state_selector.value = status.value

given_name = pn.state.user_info.get("given_name", "")
Expand Down

0 comments on commit 3d831d8

Please sign in to comment.