diff --git a/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOutPage.tsx b/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOutPage.tsx index 25c3a763..78fcc663 100644 --- a/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOutPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOutPage.tsx @@ -41,6 +41,7 @@ import { prNumber, repoProblem, rowsProblem, + runProblem, toBody, type ClassificationDraft, type OpenPrAnswer, @@ -218,9 +219,7 @@ export function ReviewTryOutPage() { }, [runId]); const openPrProblem = rowsProblem(repo, drafts); - const problem = - (prNumber(pr) === null ? "a PR number is a whole number above 0" : null) ?? - openPrProblem; + const problem = runProblem(repo, pr, drafts); async function run(e: Event) { e.preventDefault(); diff --git a/frontend/packages/swarm-ui/src/pages/review-tryout/TryOutTypes.ts b/frontend/packages/swarm-ui/src/pages/review-tryout/TryOutTypes.ts index 0195ac1f..7143ac3c 100644 --- a/frontend/packages/swarm-ui/src/pages/review-tryout/TryOutTypes.ts +++ b/frontend/packages/swarm-ui/src/pages/review-tryout/TryOutTypes.ts @@ -164,6 +164,21 @@ export function rowsProblem( ); } +/** What keeps the rows from a run, or null: everything `rowsProblem` checks, + * then the PR number. The page shows this one reason for both of its buttons, + * so whatever disables opening a PR comes before the PR number it doesn't + * need. */ +export function runProblem( + repo: string, + pr: string, + drafts: ClassificationDraft[], +): string | null { + return ( + rowsProblem(repo, drafts) ?? + (prNumber(pr) === null ? "a PR number is a whole number above 0" : null) + ); +} + export function toBody(d: ClassificationDraft): ClassificationBody { return { name: d.name.trim(), diff --git a/frontend/packages/swarm-ui/test/tryout-types.test.mjs b/frontend/packages/swarm-ui/test/tryout-types.test.mjs index 95fa18af..c64d036f 100644 --- a/frontend/packages/swarm-ui/test/tryout-types.test.mjs +++ b/frontend/packages/swarm-ui/test/tryout-types.test.mjs @@ -12,6 +12,7 @@ import { prNumber, repoProblem, rowsProblem, + runProblem, thresholdValue, toBody, } from "../src/pages/review-tryout/TryOutTypes.ts"; @@ -130,3 +131,13 @@ test("only a typed name or description counts as the user's work", () => { assert.equal(hasTypedText([row({ name: " ", description: "" })]), false); assert.equal(hasTypedText([row({ name: "", description: "x" })]), true); }); + +test("the page's one hint names what disables opening a PR before the PR number", () => { + // No PR number and a bad row: the row is what disables both buttons. + assert.match(runProblem("o/r", "", [row({ name: "" })]), /a name/); + assert.match(runProblem("o", "", [row()]), /owner\/name/); + // Rows ready but no PR number: only the run is held back. + assert.match(runProblem("o/r", "", [row()]), /PR number/); + assert.equal(rowsProblem("o/r", [row()]), null); + assert.equal(runProblem("o/r", "7", [row()]), null); +});