Commit Β·
aae35e2
1
Parent(s): ffe34a7
Show collaboration details and add acknowledge action for non-PR requests
Browse files- app.py +36 -6
- submissions.py +13 -0
app.py
CHANGED
|
@@ -56,18 +56,33 @@ def history_rows():
|
|
| 56 |
def load_submission(submission_id: str):
|
| 57 |
"""Populate the detail panel + editable fields for a selected submission."""
|
| 58 |
if not submission_id:
|
| 59 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
row = submissions.get_submission(submission_id)
|
| 62 |
if row is None:
|
| 63 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
detail_md = (
|
| 66 |
f"**Type:** {row['type']} \n"
|
| 67 |
f"**Title/link:** {row['title'] or '_none given_'} \n"
|
| 68 |
-
f"**Submitted:** {row['submitted_at']} via {row['source']} \n
|
| 69 |
-
f"{row['description']}"
|
| 70 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
visible = FIELD_VISIBILITY.get(row["type"], set())
|
| 73 |
guessed_slug = _guess_slug(row["title"])
|
|
@@ -88,7 +103,13 @@ def load_submission(submission_id: str):
|
|
| 88 |
field_updates.append(gr.update(visible=False))
|
| 89 |
|
| 90 |
show_pr_button = row["type"] in PR_TYPES
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
with gr.Blocks(title="Hugging Science β requests review") as demo:
|
|
@@ -121,6 +142,7 @@ with gr.Blocks(title="Hugging Science β requests review") as demo:
|
|
| 121 |
|
| 122 |
with gr.Row():
|
| 123 |
approve_btn = gr.Button("Approve β open PR", variant="primary", visible=False)
|
|
|
|
| 124 |
reject_reason = gr.Textbox(label="Reject reason (optional)", scale=2)
|
| 125 |
reject_btn = gr.Button("Reject", variant="stop")
|
| 126 |
|
|
@@ -132,7 +154,7 @@ with gr.Blocks(title="Hugging Science β requests review") as demo:
|
|
| 132 |
refresh_btn.click(do_refresh, outputs=pending_dd)
|
| 133 |
demo.load(do_refresh, outputs=pending_dd)
|
| 134 |
|
| 135 |
-
pending_dd.change(load_submission, inputs=pending_dd, outputs=[detail, *all_fields, approve_btn])
|
| 136 |
|
| 137 |
def do_approve(submission_id, id_, name, title, slug, org_id, entry_type,
|
| 138 |
description, excerpt, link, date, featured, upvotes, tags):
|
|
@@ -161,6 +183,14 @@ with gr.Blocks(title="Hugging Science β requests review") as demo:
|
|
| 161 |
outputs=[result_md, pending_dd],
|
| 162 |
)
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
def do_reject(submission_id, reason):
|
| 165 |
if not submission_id:
|
| 166 |
return "Nothing selected.", gr.update()
|
|
|
|
| 56 |
def load_submission(submission_id: str):
|
| 57 |
"""Populate the detail panel + editable fields for a selected submission."""
|
| 58 |
if not submission_id:
|
| 59 |
+
return (
|
| 60 |
+
gr.update(value=""),
|
| 61 |
+
*[gr.update(visible=False) for _ in ALL_FIELD_KEYS],
|
| 62 |
+
gr.update(visible=False),
|
| 63 |
+
gr.update(visible=False),
|
| 64 |
+
)
|
| 65 |
|
| 66 |
row = submissions.get_submission(submission_id)
|
| 67 |
if row is None:
|
| 68 |
+
return (
|
| 69 |
+
gr.update(value="Not found."),
|
| 70 |
+
*[gr.update(visible=False) for _ in ALL_FIELD_KEYS],
|
| 71 |
+
gr.update(visible=False),
|
| 72 |
+
gr.update(visible=False),
|
| 73 |
+
)
|
| 74 |
|
| 75 |
detail_md = (
|
| 76 |
f"**Type:** {row['type']} \n"
|
| 77 |
f"**Title/link:** {row['title'] or '_none given_'} \n"
|
| 78 |
+
f"**Submitted:** {row['submitted_at']} via {row['source']} \n"
|
|
|
|
| 79 |
)
|
| 80 |
+
if row["type"] == "collaboration":
|
| 81 |
+
detail_md += (
|
| 82 |
+
f"**Email:** {row.get('email') or '_none given_'} \n"
|
| 83 |
+
f"**Institution:** {row.get('institution') or '_none given_'} \n"
|
| 84 |
+
)
|
| 85 |
+
detail_md += f"\n{row['description']}"
|
| 86 |
|
| 87 |
visible = FIELD_VISIBILITY.get(row["type"], set())
|
| 88 |
guessed_slug = _guess_slug(row["title"])
|
|
|
|
| 103 |
field_updates.append(gr.update(visible=False))
|
| 104 |
|
| 105 |
show_pr_button = row["type"] in PR_TYPES
|
| 106 |
+
show_ack_button = row["type"] not in PR_TYPES
|
| 107 |
+
return (
|
| 108 |
+
gr.update(value=detail_md),
|
| 109 |
+
*field_updates,
|
| 110 |
+
gr.update(visible=show_pr_button),
|
| 111 |
+
gr.update(visible=show_ack_button),
|
| 112 |
+
)
|
| 113 |
|
| 114 |
|
| 115 |
with gr.Blocks(title="Hugging Science β requests review") as demo:
|
|
|
|
| 142 |
|
| 143 |
with gr.Row():
|
| 144 |
approve_btn = gr.Button("Approve β open PR", variant="primary", visible=False)
|
| 145 |
+
ack_btn = gr.Button("Mark as reviewed", variant="primary", visible=False)
|
| 146 |
reject_reason = gr.Textbox(label="Reject reason (optional)", scale=2)
|
| 147 |
reject_btn = gr.Button("Reject", variant="stop")
|
| 148 |
|
|
|
|
| 154 |
refresh_btn.click(do_refresh, outputs=pending_dd)
|
| 155 |
demo.load(do_refresh, outputs=pending_dd)
|
| 156 |
|
| 157 |
+
pending_dd.change(load_submission, inputs=pending_dd, outputs=[detail, *all_fields, approve_btn, ack_btn])
|
| 158 |
|
| 159 |
def do_approve(submission_id, id_, name, title, slug, org_id, entry_type,
|
| 160 |
description, excerpt, link, date, featured, upvotes, tags):
|
|
|
|
| 183 |
outputs=[result_md, pending_dd],
|
| 184 |
)
|
| 185 |
|
| 186 |
+
def do_ack(submission_id):
|
| 187 |
+
if not submission_id:
|
| 188 |
+
return "Nothing selected.", gr.update()
|
| 189 |
+
submissions.mark_acknowledged(submission_id)
|
| 190 |
+
return "Marked as reviewed.", gr.update(choices=pending_choices(), value=None)
|
| 191 |
+
|
| 192 |
+
ack_btn.click(do_ack, inputs=[pending_dd], outputs=[result_md, pending_dd])
|
| 193 |
+
|
| 194 |
def do_reject(submission_id, reason):
|
| 195 |
if not submission_id:
|
| 196 |
return "Nothing selected.", gr.update()
|
submissions.py
CHANGED
|
@@ -71,6 +71,19 @@ def mark_approved(submission_id: str, pr_url: str) -> None:
|
|
| 71 |
_write_all(rows)
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def mark_rejected(submission_id: str, reason: str | None) -> None:
|
| 75 |
with _lock:
|
| 76 |
rows = _read_all()
|
|
|
|
| 71 |
_write_all(rows)
|
| 72 |
|
| 73 |
|
| 74 |
+
def mark_acknowledged(submission_id: str) -> None:
|
| 75 |
+
"""For non-PR types (collaboration, challenge): close out a request
|
| 76 |
+
without opening a PR β e.g. once the reviewer has emailed the requester."""
|
| 77 |
+
with _lock:
|
| 78 |
+
rows = _read_all()
|
| 79 |
+
for row in rows:
|
| 80 |
+
if row["id"] == submission_id:
|
| 81 |
+
row["status"] = "acknowledged"
|
| 82 |
+
row["reviewed_at"] = _now()
|
| 83 |
+
break
|
| 84 |
+
_write_all(rows)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def mark_rejected(submission_id: str, reason: str | None) -> None:
|
| 88 |
with _lock:
|
| 89 |
rows = _read_all()
|