Download frontend/src/components/RobForm.tsx from Smart-Slate/Systematic-tool-review: direct link, hf CLI and curl.
- Browser
- Download file 5.72 kB
-
https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/RobForm.tsx
- Command line
-
hf download hf://spaces/Smart-Slate/Systematic-tool-review/frontend/src/components/RobForm.tsx
-
curl -L -o RobForm.tsx https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/RobForm.tsx
5.72 kB
| import { useState } from "react"; | |
| import type { RobAnswer, RobAssessmentEntry, RobRating, RobReference, StudyDesign } from "../types"; | |
| import "./review-fixes.css"; | |
| export interface RobFormValues { | |
| outcome: string; | |
| study_design: StudyDesign; | |
| answers: RobAnswer[]; | |
| note: string; | |
| } | |
| interface RobFormProps { | |
| reference: RobReference; | |
| title: string; | |
| defaultOutcome: string; | |
| /** Pre-fill from an earlier assessment (own revision, or a reviewer's when resolving). */ | |
| initial?: RobAssessmentEntry; | |
| keyQuestionsFor: (design: StudyDesign) => number[]; | |
| /** Questions to highlight (reviewers disagreed). */ | |
| highlight?: number[]; | |
| requireNote?: boolean; | |
| lockOutcome?: boolean; | |
| busy: boolean; | |
| onCancel: () => void; | |
| onSubmit: (values: RobFormValues) => void; | |
| } | |
| /** One OHAT assessment: study design, then a rating + justification per applicable question. */ | |
| export function RobForm({ | |
| reference, | |
| title, | |
| defaultOutcome, | |
| initial, | |
| keyQuestionsFor, | |
| highlight = [], | |
| requireNote, | |
| lockOutcome, | |
| busy, | |
| onCancel, | |
| onSubmit, | |
| }: RobFormProps) { | |
| const [outcome, setOutcome] = useState(initial?.outcome ?? defaultOutcome); | |
| const [design, setDesign] = useState<StudyDesign | "">(initial?.study_design ?? ""); | |
| const [ratings, setRatings] = useState<Record<number, RobRating>>( | |
| Object.fromEntries((initial?.answers ?? []).map((a) => [a.question, a.rating])) | |
| ); | |
| const [justifications, setJustifications] = useState<Record<number, string>>( | |
| Object.fromEntries((initial?.answers ?? []).map((a) => [a.question, a.justification])) | |
| ); | |
| const [note, setNote] = useState(""); | |
| const [error, setError] = useState<string | null>(null); | |
| const questions = design ? reference.questions.filter((q) => q.applies_to.includes(design)) : []; | |
| const keys = design ? keyQuestionsFor(design) : []; | |
| function submit() { | |
| setError(null); | |
| if (!outcome.trim()) return setError("Enter the outcome this assessment is for."); | |
| if (!design) return setError("Choose the study design."); | |
| const missing = questions.filter((q) => !ratings[q.number]).map((q) => `Q${q.number}`); | |
| if (missing.length) return setError(`Rate every question (missing: ${missing.join(", ")}).`); | |
| const unjustified = questions.filter((q) => !justifications[q.number]?.trim()).map((q) => `Q${q.number}`); | |
| if (unjustified.length) return setError(`Every rating needs a justification (missing: ${unjustified.join(", ")}).`); | |
| if (requireNote && !note.trim()) return setError("Explain how the disagreement was resolved."); | |
| onSubmit({ | |
| outcome: outcome.trim(), | |
| study_design: design, | |
| answers: questions.map((q) => ({ | |
| question: q.number, | |
| rating: ratings[q.number], | |
| justification: justifications[q.number].trim(), | |
| })), | |
| note: note.trim(), | |
| }); | |
| } | |
| return ( | |
| <div className="rob-form"> | |
| <strong>{title}</strong> | |
| <div className="rob-form-row"> | |
| <label> | |
| Outcome{" "} | |
| <input type="text" value={outcome} disabled={lockOutcome} onChange={(e) => setOutcome(e.target.value)} /> | |
| </label> | |
| <label> | |
| Study design{" "} | |
| <select value={design} onChange={(e) => setDesign(e.target.value as StudyDesign)}> | |
| <option value="">Choose…</option> | |
| {reference.designs.map((d) => ( | |
| <option key={d.value} value={d.value}> | |
| {d.label} | |
| </option> | |
| ))} | |
| </select> | |
| </label> | |
| </div> | |
| {design && ( | |
| <p className="form-hint"> | |
| {questions.length} OHAT questions apply to this design. Key questions (marked ★) decide the tier. | |
| Rate <strong>NR</strong> when the paper doesn't report enough to judge — OHAT treats it as probably high. | |
| </p> | |
| )} | |
| {questions.map((q) => ( | |
| <div key={q.number} className={`rob-question${highlight.includes(q.number) ? " rob-question-conflict" : ""}`}> | |
| <div className="rob-question-text"> | |
| <strong> | |
| Q{q.number} | |
| {keys.includes(q.number) ? " ★" : ""} | |
| </strong>{" "} | |
| <span className="rob-bias-type">{q.bias_type}</span> — {q.text} | |
| </div> | |
| <div className="rob-ratings" role="radiogroup" aria-label={`Rating for question ${q.number}`}> | |
| {reference.ratings.map((r) => ( | |
| <label key={r.value} className={`rob-rating rob-${r.value}`} title={r.help}> | |
| <input | |
| type="radio" | |
| name={`q${q.number}`} | |
| checked={ratings[q.number] === r.value} | |
| onChange={() => setRatings({ ...ratings, [q.number]: r.value })} | |
| /> | |
| {r.symbol} {r.label} | |
| </label> | |
| ))} | |
| </div> | |
| <textarea | |
| className="rob-justification" | |
| placeholder="Justification — what in the paper supports this rating?" | |
| value={justifications[q.number] ?? ""} | |
| onChange={(e) => setJustifications({ ...justifications, [q.number]: e.target.value })} | |
| /> | |
| </div> | |
| ))} | |
| {requireNote && ( | |
| <textarea | |
| placeholder="How was the disagreement resolved? (required)" | |
| value={note} | |
| onChange={(e) => setNote(e.target.value)} | |
| /> | |
| )} | |
| {error && <div className="form-error">{error}</div>} | |
| <div className="form-actions"> | |
| <button className="secondary-btn" onClick={onCancel}> | |
| Cancel | |
| </button> | |
| <button className="primary-btn" disabled={busy} onClick={submit}> | |
| {busy ? "Saving…" : "Save assessment"} | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |