Skip to content

Commit

Permalink
feat: bubble up errors on submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Nov 5, 2024
1 parent 0133078 commit b8f95cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/aind_qc_portal/docdb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
)


def qc_from_id(id: str):
def qc_from_id(id: str) -> QualityControl | None:
"""Get the QC object from the database for a given ID
Parameters
----------
id : str
Returns
-------
QualityControl
"""
response = client.retrieve_docdb_records(filter_query={"_id": id}, limit=1)
if len(response) == 0:
return None
Expand All @@ -33,9 +43,7 @@ def qc_update_to_id(id: str, qc: QualityControl):
response = client.upsert_one_docdb_record(
record={"_id": id, "quality_control": qc.model_dump()}
)
print(response)
if response.status_code != 200:
print(response.json())
return response


@pn.cache()
Expand Down
17 changes: 13 additions & 4 deletions src/aind_qc_portal/panel/quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ def __init__(self, id, **params):

self.id = id

# Set up the submission area
self.submit_button = pn.widgets.Button(
name="Submit changes", button_type="success",
)
self.submit_error = pn.widgets.StaticText("")
self.submit_col = pn.Column(self.submit_button, self.submit_error)
pn.bind(self.submit_changes, self.submit_button, watch=True)

self.hidden_html = pn.pane.HTML("")
Expand Down Expand Up @@ -96,9 +99,14 @@ def submit_changes(self, *event):
self.hidden_html.object = f"<script>window.location.href = '/login?next={pn.state.location.href}';</script>"
return

qc_update_to_id(self.id, self.data)
self.submit_button.disabled = True
self.hidden_html.object = "<script>window.location.reload();</script>"
response = qc_update_to_id(self.id, self.data)

if response.status_code != 200:
self.submit_error.value = f"Error ({response.status_code}) submitting changes: {response.text}"
return
else:
self.submit_button.disabled = True
self.hidden_html.object = "<script>window.location.reload();</script>"

def _update_modality_filter(self, event):
self.modality_filter = event.new
Expand Down Expand Up @@ -149,10 +157,11 @@ def panel(self):
# state row
state_row = pn.Row(state_pane, notes_box)
quality_control_pane = pn.Column(header, state_row)


# button
header_row = pn.Row(
quality_control_pane, pn.HSpacer(), self.submit_button
quality_control_pane, pn.HSpacer(), self.submit_col
)

# filters for modality and stage
Expand Down

0 comments on commit b8f95cd

Please sign in to comment.