tttjjj commited on
Commit
5b2ebd8
·
1 Parent(s): a9aec68

Show reviews when retrieving a version

Browse files

- list_versions() now includes each version's status, review_count, and full
reviews timeline (single repo listing, no extra round-trips).
- Form version selector shows status + review count per version.
- After 'Load selected version', the submitter sees that version's reviewer
feedback (status + reviewer + comment) so they can edit accordingly.

Files changed (2) hide show
  1. app.py +42 -6
  2. lib/storage.py +7 -1
app.py CHANGED
@@ -52,6 +52,11 @@ if "form_nonce" not in st.session_state:
52
  # Versions found for the current trial_id + username (after "Find versions").
53
  if "versions" not in st.session_state:
54
  st.session_state.versions = []
 
 
 
 
 
55
 
56
 
57
  # ------------- callbacks -------------------------------------------------
@@ -127,6 +132,12 @@ def _load_selected() -> None:
127
  prompts = (record.get("comparison") or {}).get("prompts") or []
128
  st.session_state.questions = prompts
129
  st.session_state.form_nonce += 1 # force question widgets to refresh
 
 
 
 
 
 
130
  st.session_state.last_result = {
131
  "kind": "success",
132
  "msg": f"Loaded version {record.get('version', '')} "
@@ -189,20 +200,30 @@ st.button(
189
  help="List all previously submitted versions for this trial_id + username.",
190
  )
191
 
 
 
192
  versions = st.session_state.versions
193
  if versions:
194
  options = [v["submissionId"] for v in versions]
195
- labels = {
196
- v["submissionId"]: f"{v['submittedAt']} · v{v['version']} · "
197
- f"{v['num_questions']} question(s)"
198
- for v in versions
199
- }
 
 
 
 
 
 
 
 
200
  vc1, vc2 = st.columns([3, 1])
201
  with vc1:
202
  st.selectbox(
203
  "Select a version to load",
204
  options=options,
205
- format_func=lambda sid: labels.get(sid, sid),
206
  key="version_select",
207
  )
208
  with vc2:
@@ -210,6 +231,21 @@ if versions:
210
  st.write("")
211
  st.button("Load selected version", on_click=_load_selected, use_container_width=True)
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  st.divider()
214
 
215
  # ------------- questions list --------------------------------------------
 
52
  # Versions found for the current trial_id + username (after "Find versions").
53
  if "versions" not in st.session_state:
54
  st.session_state.versions = []
55
+ # Reviews of the version currently loaded into the form (if any).
56
+ if "loaded_reviews" not in st.session_state:
57
+ st.session_state.loaded_reviews = []
58
+ if "loaded_version" not in st.session_state:
59
+ st.session_state.loaded_version = ""
60
 
61
 
62
  # ------------- callbacks -------------------------------------------------
 
132
  prompts = (record.get("comparison") or {}).get("prompts") or []
133
  st.session_state.questions = prompts
134
  st.session_state.form_nonce += 1 # force question widgets to refresh
135
+ # Stash this version's reviews so the submitter can see reviewer feedback.
136
+ match = next(
137
+ (v for v in st.session_state.versions if v["submissionId"] == sub_id), None
138
+ )
139
+ st.session_state.loaded_reviews = (match or {}).get("reviews") or []
140
+ st.session_state.loaded_version = record.get("version", "")
141
  st.session_state.last_result = {
142
  "kind": "success",
143
  "msg": f"Loaded version {record.get('version', '')} "
 
200
  help="List all previously submitted versions for this trial_id + username.",
201
  )
202
 
203
+ _STATUS_EMOJI = {"pending": "🟡", "reviewed": "🟢", "needs_fix": "🔴"}
204
+
205
  versions = st.session_state.versions
206
  if versions:
207
  options = [v["submissionId"] for v in versions]
208
+
209
+ def _ver_label(sid: str) -> str:
210
+ v = next((x for x in versions if x["submissionId"] == sid), None)
211
+ if not v:
212
+ return sid
213
+ emoji = _STATUS_EMOJI.get(v.get("status", "pending"), "⚪")
214
+ rc = v.get("review_count", 0)
215
+ rtag = f"{rc} review(s)" if rc else "no reviews"
216
+ return (
217
+ f"{v['submittedAt']} · {v['num_questions']} Q · "
218
+ f"{emoji} {v.get('status','pending')} ({rtag})"
219
+ )
220
+
221
  vc1, vc2 = st.columns([3, 1])
222
  with vc1:
223
  st.selectbox(
224
  "Select a version to load",
225
  options=options,
226
+ format_func=_ver_label,
227
  key="version_select",
228
  )
229
  with vc2:
 
231
  st.write("")
232
  st.button("Load selected version", on_click=_load_selected, use_container_width=True)
233
 
234
+ # Show reviewer feedback for the version that was loaded into the form.
235
+ loaded_reviews = st.session_state.loaded_reviews
236
+ if loaded_reviews:
237
+ with st.container(border=True):
238
+ st.markdown(f"**Reviewer feedback on the loaded version (v{st.session_state.loaded_version})**")
239
+ for rev in reversed(loaded_reviews): # newest first
240
+ emoji = _STATUS_EMOJI.get(rev.get("status", ""), "⚪")
241
+ line = (
242
+ f"- {emoji} **{rev.get('status','')}** — "
243
+ f"{rev.get('reviewer') or 'anon'} · _{rev.get('at','')}_"
244
+ )
245
+ if rev.get("note"):
246
+ line += f" \n {rev['note']}"
247
+ st.markdown(line)
248
+
249
  st.divider()
250
 
251
  # ------------- questions list --------------------------------------------
lib/storage.py CHANGED
@@ -191,7 +191,8 @@ def list_versions(
191
  ) -> List[Dict[str, Any]]:
192
  """All saved versions for (trial_id, username), newest first.
193
 
194
- Each item: submissionId, version, submittedAt, num_questions.
 
195
  """
196
  prefix = f"{_pair_dir(trial_id, username)}/"
197
  files = all_files if all_files is not None else _all_files()
@@ -205,12 +206,17 @@ def list_versions(
205
  if not rec:
206
  continue
207
  prompts = (rec.get("comparison") or {}).get("prompts") or []
 
 
208
  out.append(
209
  {
210
  "submissionId": p,
211
  "version": rec.get("version", ""),
212
  "submittedAt": rec.get("submittedAt", ""),
213
  "num_questions": len(prompts),
 
 
 
214
  }
215
  )
216
  return out
 
191
  ) -> List[Dict[str, Any]]:
192
  """All saved versions for (trial_id, username), newest first.
193
 
194
+ Each item: submissionId, version, submittedAt, num_questions, status,
195
+ review_count, reviews (full timeline for that version).
196
  """
197
  prefix = f"{_pair_dir(trial_id, username)}/"
198
  files = all_files if all_files is not None else _all_files()
 
206
  if not rec:
207
  continue
208
  prompts = (rec.get("comparison") or {}).get("prompts") or []
209
+ reviews = list_reviews(p, all_files=files)
210
+ latest = reviews[-1] if reviews else None
211
  out.append(
212
  {
213
  "submissionId": p,
214
  "version": rec.get("version", ""),
215
  "submittedAt": rec.get("submittedAt", ""),
216
  "num_questions": len(prompts),
217
+ "status": latest["status"] if latest else "pending",
218
+ "review_count": len(reviews),
219
+ "reviews": reviews,
220
  }
221
  )
222
  return out