diff --git a/components/reports/details-step.tsx b/components/reports/details-step.tsx index efcf7af22..19256ad6d 100644 --- a/components/reports/details-step.tsx +++ b/components/reports/details-step.tsx @@ -763,6 +763,14 @@ export function DetailsStep({ ) : null} + {/* Where the DOI leads, right after what the work is, so a change of place is found + first and not under every other detail. */} + {landing && offersLanding(landing, m.landing) ? ( +
+ set("landing", next)} /> +
+ ) : null} +
{m.authors.length}}>
- {landing && offersLanding(landing, m.landing) ? ( -
- set("landing", next)} /> -
- ) : null} -
{wrongLinks ? {t("wrongLink")} : null} {m.relations.length ? ( diff --git a/components/reports/doi-landing.tsx b/components/reports/doi-landing.tsx index e3cb4259d..ddd850911 100644 --- a/components/reports/doi-landing.tsx +++ b/components/reports/doi-landing.tsx @@ -19,7 +19,7 @@ import { Input } from "@/components/ui/input"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Switch } from "@/components/ui/switch"; import { StatusChip } from "@/components/evidence-libraries/configuration/status-chip"; -import { ArrowRight, ArrowUpRight, FileText, Globe, Hash, Hourglass, Lock } from "@/components/icons"; +import { ArrowRight, ArrowUpRight, Check, CircleCheck, Copy, FileText, Globe, Hash, Hourglass, Info, Lock } from "@/components/icons"; import { FieldLabel } from "@/components/reports/field-help"; import { LogoMark } from "@/components/logo"; import { LIST, LOCKED_LOOK, Locked, Shut, Zone } from "@/components/settings/parts"; @@ -92,6 +92,8 @@ export function LandingSettings({ landings, crossrefOn }: { landings: Landings; })}
  • {allowed.length > 1 ? t("pickNote") : t(needsUrl(allowed[0]!) ? "fixedUrlNote" : "fixedNote", { to: t(`to_${allowed[0]!}`) })} + {/* What a place past the report's page asks of its authors, said to the admin who allows it. */} + {landings.notice || landings.official ? ` ${t("adminWhy")}` : null}
  • @@ -229,9 +231,58 @@ export function LandingSection({ value, options, onChange, id, invalid }: { valu ) : null} - - {host ?

    {t("mustShow", { host, doi: options.doi })}

    : null} -
    + {/* The place picked leads into what the author has to do about it, and why. */} + + + ); +} + +/** + * Under the place picked, what its author has to do and why. Its page: nothing. A place + * past it: put the DOI on the official page, which readers from the DOI reach; with the DOI to copy once it is + * reserved, or word that it comes when they sign. + */ +function WhatToDo({ place, host, doi }: { place: LandingPlace; /** The official page's host, once its address is right. */ host: string | null; /** The report's DOI; empty before it is reserved. */ doi: string }) { + const t = useTranslations("publishReports.lead"); + const [copied, setCopied] = useState(false); + if (place === "page") { + return ( +

    + + {t("todoPage")} +

    + ); + } + return ( +
    +

    + + {host ? t("todoTitle", { host }) : t("todoTitleNoHost")} +

    +
    + {doi ? ( + <> +

    {t("todoDoi")}

    +

    + {`https://doi.org/${doi}`} + +

    + + ) : ( +

    {t("todoDoiLater")}

    + )} +

    {t(place === "notice" ? "todoWhy_notice" : "todoWhy_official", { seconds: NOTICE_SECONDS })}

    +

    {t("todoUnchecked")}

    +
    ); } diff --git a/components/reports/publish-flow.tsx b/components/reports/publish-flow.tsx index 51ac6df69..416b79b97 100644 --- a/components/reports/publish-flow.tsx +++ b/components/reports/publish-flow.tsx @@ -36,6 +36,7 @@ import { PaperCover } from "@/components/papers/paper-cover"; import { DetailsStep } from "@/components/reports/details-step"; import { NewPdf } from "@/components/reports/new-pdf"; import { FieldHelp, RegistrarsProvider, type HelpKey } from "@/components/reports/field-help"; +import { LandingSection, offersLanding } from "@/components/reports/doi-landing"; import { RegistrationChips } from "@/components/reports/registration"; import { SHOWS, STATUS, StatusFilter, YourReports, stageShown, useStageChip } from "@/components/reports/your-reports"; import { Problem, useProblem } from "@/components/reports/problem"; @@ -933,7 +934,7 @@ function Screens({ form, beside, preparing, onPrepared, onUnprepare, into, onInt // Until the run is there, a moment after Submit, the list is what the same rule says a run of it would run. ({ id: check.id, name: check.name, result: report.run?.results.find((result) => result.checkId === check.id) }))} report={null} humanReview={basics.humanReview} /> ) : report.step === "doi" ? ( - (toTop(), onMoved("upload"))} /> + (toTop(), onMoved("upload"))} /> ) : report.step === "upload" ? ( onMoved("details")} onBack={() => onStep("doi")} onNext={report.pdf?.pages !== undefined && report.metadata ? () => onStep("details") : undefined} /> ) : report.step === "details" && report.metadata && report.pdf ? ( @@ -1647,7 +1648,7 @@ function AgreementStep({ basics: ours, starts: here, workspaceId: pageWorkspace, * The DOI, and nothing else: its mark, then the DOI itself set large and arriving letter by letter, with one sweep of * light across it. Plays only right after signing; opened any other way it is already settled. */ -function DoiStep({ report, fresh, onNext }: { report: Report; fresh: boolean; onNext: () => void }) { +function DoiStep({ report, fresh, onNext, landings }: { report: Report; fresh: boolean; onNext: () => void; /** The places the report's series allows its DOI to lead. */ landings: Basics["landing"] }) { // A report signed where no byline is asked for has no line to make and no choice of who adds it. const { bylineOff } = report; // The choice made here, or the one a PDF already attached was uploaded with. @@ -1655,6 +1656,39 @@ function DoiStep({ report, fresh, onNext }: { report: Report; fresh: boolean; on const by = chosen ?? report.pdf?.bylineBy ?? null; const reduce = useReducedMotion(); const t = useTranslations("publishReports.flow"); + // Where the DOI leads, picked here where the DOI is first shown: kept as it is picked, a moment after the last change, + // as the report's until its details are read, then as theirs (convex/reports/flow.ts `chooseLanding`). + const tLead = useTranslations("publishReports.lead"); + const chooseLanding = useMutation(api.reports.flow.chooseLanding); + // Once the details are read they hold it, and none there is the report's page: the pick kept on the report is only + // for before then. + const [landing, setLanding] = useState(report.metadata ? report.metadata.landing : report.landing); + const keeping = useRef<{ timer: ReturnType; send: () => void } | null>(null); + const keepNow = () => { + if (!keeping.current) return; + clearTimeout(keeping.current.timer); + keeping.current.send(); + keeping.current = null; + }; + const pickLanding = (next: NonNullable) => { + setLanding(next); + if (keeping.current) clearTimeout(keeping.current.timer); + const send = () => { + if (workspaceId) void chooseLanding({ workspaceId, key: report.key, landing: next }).catch((error: unknown) => void toast.error(getErrorMessage(error, t("saveFailed")))); + }; + keeping.current = { send, timer: setTimeout(() => ((keeping.current = null), send()), 400) }; + }; + // The page closing or reloading: a pick still waiting to be kept is sent first, as the details form does. + useEffect(() => { + const leave = () => { + if (!keeping.current) return; + clearTimeout(keeping.current.timer); + keeping.current.send(); + keeping.current = null; + }; + window.addEventListener("pagehide", leave); + return () => window.removeEventListener("pagehide", leave); + }, []); // Next, pressed with the line's choice not made, says so at the choice and goes there. const choice = useId(); const { tried, go } = useStepForm(); @@ -1686,6 +1720,8 @@ function DoiStep({ report, fresh, onNext }: { report: Report; fresh: boolean; on const editor = useId(); const [nudged, setNudged] = useState(0); const next = () => { + // A place picked a moment ago is kept before the step moves on. + keepNow(); if (edit !== "none" && editing) setNudged((n) => n + 1); go([!printed && minting, edit !== "none" && editing && editor, !bylineOff && !by && bylineField(choice)], onNext); }; @@ -1819,6 +1855,14 @@ function DoiStep({ report, fresh, onNext }: { report: Report; fresh: boolean; on + {/* Where the DOI leads, chosen where the DOI is first shown, so the box under the place picked can give it to copy. + Without an address yet the report's page can stay, and the place changes later. */} + {offersLanding({ landings, crossref: report.registration.crossref, doi: report.doi }, landing) ? ( + + {tLead(landings.page ? "doiStepIntro" : "doiStepIntroNeeded")} + + + ) : null} {/* What the DOI is for, said where the author first meets it: the line their PDF needs, before they make it. Laid out as the upload's page is, which comes next. */} {bylineOff ? ( diff --git a/convex/reports/flow.test.ts b/convex/reports/flow.test.ts index 50e789761..c6a673e72 100644 --- a/convex/reports/flow.test.ts +++ b/convex/reports/flow.test.ts @@ -722,3 +722,32 @@ describe("a workspace's list of reports", () => { await expect(world.t.query(internal.reports.flow.pageForAssistant, { userId: world.strangerId, workspaceId: world.lab, page: 1 })).rejects.toThrow(); }); }); + +describe("where the DOI leads, picked on the DOI step", () => { + it("goes into the details once the PDF is read, follows the details after, and can't change once the checks start", async () => { + vi.stubEnv("NEXT_PUBLIC_APP_URL", "https://openscholar.test"); + onTestFinished(() => void vi.unstubAllEnvs()); + const world = await setup(); + const { author, own } = world; + const key = await sign(author, own); + const official = { place: "official" as const, url: "https://www.example.org/reports/shade-trees" }; + await author.mutation(api.reports.flow.chooseLanding, { workspaceId: own, key, landing: official }); + expect((await read(author, own, key)).landing).toEqual(official); + // Read from the PDF, the details take it: the reading itself knows nothing of it. + const file = await uploaded(world, { by: author, bytes: 17 }); + await author.mutation(api.reports.flow.attachPdf, { workspaceId: own, key, file, name: "report.pdf" }); + const { _id: reportId, pdf } = await row(world.t, key); + await world.t.mutation(internal.reports.readingState.finish, { reportId, at: pdf!.at, pages: 12, metadata: details() }); + expect((await read(author, own, key)).metadata?.landing).toEqual(official); + // Back on the DOI step, a new pick changes the details too. + const page = { place: "page" as const, url: official.url }; + await author.mutation(api.reports.flow.chooseLanding, { workspaceId: own, key, landing: page }); + expect((await read(author, own, key)).metadata?.landing).toEqual(page); + // A pick made on a report reopened from its checks sends it through them again. + await world.t.run((ctx) => ctx.db.patch("reports", reportId, { reopened: true })); + await author.mutation(api.reports.flow.chooseLanding, { workspaceId: own, key, landing: official }); + expect(await row(world.t, key)).not.toHaveProperty("reopened"); + await author.mutation(internal.reports.checkRuns.start, { workspaceId: own, key, metadata: details(), runId: "run-1", from: { pdfAt: pdf!.at } }); + await expect(author.mutation(api.reports.flow.chooseLanding, { workspaceId: own, key, landing: official })).rejects.toMatchObject(refused("CONFLICT")); + }); +}); diff --git a/convex/reports/flow.ts b/convex/reports/flow.ts index c815c0451..0f7fae674 100644 --- a/convex/reports/flow.ts +++ b/convex/reports/flow.ts @@ -34,7 +34,7 @@ import { formVersion } from "./corrections"; import { notify } from "./mail"; import { register } from "./registering"; import { accountsFor, checkNames, checksOf, humanReviewOf, limitsOf, reportSettings, reviewedIn, seriesFor, seriesReader, settingsRow, type ReportSettings } from "./settings"; -import { ELSEWHERE_WORKSPACES, doiEditValidator, authorRowValidator, checkNamesValidator, bylineByValidator, bylineTroubleValidator, fileAccessValidator, licenceValidator, metadataValidator, optionalPlainResults, pdfTroubleValidator, plainResults, referenceLookupValidator, reportRowsValidator, signedAgreementValidator, stageValidator, waitingWorkspacesValidator, payWithValidator, serviceIdValidator, voucherValidator } from "./validators"; +import { ELSEWHERE_WORKSPACES, landingValidator, doiEditValidator, authorRowValidator, checkNamesValidator, bylineByValidator, bylineTroubleValidator, fileAccessValidator, licenceValidator, metadataValidator, optionalPlainResults, pdfTroubleValidator, plainResults, referenceLookupValidator, reportRowsValidator, signedAgreementValidator, stageValidator, waitingWorkspacesValidator, payWithValidator, serviceIdValidator, voucherValidator } from "./validators"; /** What an upload is told while its report's numbered DOI is still being reserved: the line its PDF carries names it. */ const DOI_WAITS = "This report's DOI is still being reserved. Upload its PDF once it shows."; @@ -542,6 +542,28 @@ export const saveDetails = workspaceMutation({ }, }); +/** + * Where a report's DOI leads, picked on its DOI step: its details' own once they are read (./readingState.ts), and + * until then the report's. Checked like the rest of its details when its checks run (`requireLanding`): an address is + * kept as it is typed here. + */ +export const chooseLanding = workspaceMutation({ + args: { key: v.string(), landing: landingValidator }, + returns: v.null(), + handler: async (ctx, actor, { key, landing }) => { + await refuseApps(ctx); + const report = await changing(ctx, actor, key); + if (report.step === "done" || report.run) throw createError("CONFLICT", "This report's checks have started: change where its DOI leads in its details."); + if (landing.url.length > DETAIL_TEXT.link) throw createError("VALIDATION_ERROR", `Keep the official page's address to ${DETAIL_TEXT.link} characters.`); + const details = await detailsOf(ctx, report._id); + if (details.metadata) await ctx.db.patch("reportDetails", details._id, { metadata: { ...details.metadata, landing } }); + // Changed, its checks run again before it goes on, as a change to any other detail: one reopened from its checks + // can't go back to the results they gave before. + await touch(ctx, report, { landing, ...(details.metadata && { reopened: undefined }) }); + return null; + }, +}); + /** Gives up a report that never went live and no reviewer approved: it, its PDF and its reserved DOI are gone. The * day's start it used stays used. */ export const discard = workspaceMutation({ @@ -973,6 +995,8 @@ const reportValidator = v.object({ doi: v.string(), /** The DOI it was reserved, where its author chose another (./ownDoi.ts). */ reservedDoi: v.optional(v.string()), + /** Where its DOI leads, picked on its DOI step: its details' once they are read. */ + landing: v.optional(landingValidator), /** What its author may change of its DOI now (`doiEditOf`). */ doiEdit: doiEditValidator, /** Its author can go back to the DOI it was reserved (`doiBackOf`). */ @@ -1054,6 +1078,7 @@ export const getAction = defineUserQuery({ ...(await row(ctx, actor, report, settings, seriesReader(ctx, (await reportSettings(ctx)).series))), doi: report.doi, ...(report.reservedDoi && { reservedDoi: report.reservedDoi }), + ...(report.landing && { landing: report.landing }), doiEdit: mayChange(actor, report) ? doiEditOf(report, settings.series.doiEdit) : "none", doiBack: mayChange(actor, report) && doiBackOf(report), doiTaken: !!report.doiTaken && report.doiTaken === report.doi, diff --git a/convex/reports/readingState.ts b/convex/reports/readingState.ts index 970f11f0a..954d9864a 100644 --- a/convex/reports/readingState.ts +++ b/convex/reports/readingState.ts @@ -112,7 +112,8 @@ export const finish = internalMutation({ } if (text) await keepFor(ctx, reportId, text); const profile = (await ctx.db.get("users", report.ownerId))?.profile; - const kept = held ?? keptDetails(signerFilledIn(metadata!, report.signedBy.name, profile), licenceOf(report)); + // Where its DOI leads, if its author picked it on the DOI step, goes into the details made now. + const kept = held ?? keptDetails({ ...signerFilledIn(metadata!, report.signedBy.name, profile), ...(report.landing && { landing: report.landing }) }, licenceOf(report)); if (!held) { await ctx.db.patch("reportDetails", details._id, { metadata: kept }); await startLookup(ctx, details._id, reportId, kept.citations ?? [], titles ?? []); diff --git a/convex/reports/validators.ts b/convex/reports/validators.ts index d8008458c..a5e01c105 100644 --- a/convex/reports/validators.ts +++ b/convex/reports/validators.ts @@ -389,6 +389,8 @@ export const reportFields = { doiUnder: v.optional(v.string()), /** The DOI it was reserved, once its author chose another for it (reports/ownDoi.ts): theirs to go back to. */ reservedDoi: v.optional(v.string()), + /** Where its DOI leads, picked on its DOI step before its details are read: its details take it when they are made. */ + landing: v.optional(landingValidator), /** Its DOI, which doi.org said was registered elsewhere when asked before it went live (reports/ownDoi.ts): it can't go live with it. */ doiTaken: v.optional(v.string()), /** Why that reservation couldn't be made, until it is asked again: kept apart from `registrationError`, which DOCiD's minting clears. */ diff --git a/messages/en-GB.json b/messages/en-GB.json index f8d016250..9945ff848 100644 --- a/messages/en-GB.json +++ b/messages/en-GB.json @@ -6274,6 +6274,19 @@ "url_missing": "Give the official page's address.", "url_invalid": "That isn't a web address. It starts with https://.", "leadsTo": "DOI leads to", + "doiStepIntro": "Where readers who follow this DOI end up. No official page yet? Keep the report's page for now. You can change it in the details, or after the report is live.", + "doiStepIntroNeeded": "Where readers who follow this DOI end up. No address yet? You can give it when you check the details, and change it after the report is live.", + "adminWhy": "Authors who pick a place past the report's page are asked to put the DOI on that page, and told why. Readers from the DOI find it there, as Crossref asks of every page a DOI leads to.", + "todoPage": "Readers who follow the DOI land on the report's page here, so that page is its official page. There's nothing to add anywhere else.", + "todoTitle": "Put the DOI on {host}", + "todoTitleNoHost": "Put the DOI on the official page", + "todoDoi": "Show this DOI on that page as text, near the report's title, before the report goes live.", + "todoDoiLater": "Your DOI is reserved when you sign and shown to you on the next step. Show it on that page as text, near the report's title, before the report goes live.", + "todoWhy_notice": "Readers who follow the DOI see the report's page here for {seconds} seconds, then move on to that page. Finding the DOI there tells them they reached the right report, and Crossref asks it of every page a DOI leads to.", + "todoWhy_official": "Readers who follow the DOI land straight on that page and never see Openscholar. Finding the DOI there tells them they reached the right report, and Crossref asks it of every page a DOI leads to.", + "todoUnchecked": "Openscholar doesn't check the page, as many sites turn automated visits away.", + "copyDoi": "Copy the DOI", + "copied": "Copied", "leadsToAfter": "{host} after {seconds} s", "url_long": "That address is too long. Keep it to 500 characters.", "url_gone": "This place isn't allowed for this report any more. Choose another.", diff --git a/messages/en-US.json b/messages/en-US.json index 3d8d9e6ca..cd49b2fc4 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -6274,6 +6274,19 @@ "url_missing": "Give the official page's address.", "url_invalid": "That isn't a web address. It starts with https://.", "leadsTo": "DOI leads to", + "doiStepIntro": "Where readers who follow this DOI end up. No official page yet? Keep the report's page for now. You can change it in the details, or after the report is live.", + "doiStepIntroNeeded": "Where readers who follow this DOI end up. No address yet? You can give it when you check the details, and change it after the report is live.", + "adminWhy": "Authors who pick a place past the report's page are asked to put the DOI on that page, and told why. Readers from the DOI find it there, as Crossref asks of every page a DOI leads to.", + "todoPage": "Readers who follow the DOI land on the report's page here, so that page is its official page. There's nothing to add anywhere else.", + "todoTitle": "Put the DOI on {host}", + "todoTitleNoHost": "Put the DOI on the official page", + "todoDoi": "Show this DOI on that page as text, near the report's title, before the report goes live.", + "todoDoiLater": "Your DOI is reserved when you sign and shown to you on the next step. Show it on that page as text, near the report's title, before the report goes live.", + "todoWhy_notice": "Readers who follow the DOI see the report's page here for {seconds} seconds, then move on to that page. Finding the DOI there tells them they reached the right report, and Crossref asks it of every page a DOI leads to.", + "todoWhy_official": "Readers who follow the DOI land straight on that page and never see Openscholar. Finding the DOI there tells them they reached the right report, and Crossref asks it of every page a DOI leads to.", + "todoUnchecked": "Openscholar doesn't check the page, as many sites turn automated visits away.", + "copyDoi": "Copy the DOI", + "copied": "Copied", "leadsToAfter": "{host} after {seconds} s", "url_long": "That address is too long. Keep it to 500 characters.", "url_gone": "This place isn't allowed for this report any more. Choose another.", diff --git a/scripts/user-actions-exempt.json b/scripts/user-actions-exempt.json index ab1468696..1dd992693 100644 --- a/scripts/user-actions-exempt.json +++ b/scripts/user-actions-exempt.json @@ -340,6 +340,7 @@ "reports/settings:workspace": "Site administration, for Openscholar's own admins on the admin pages.", "reports/flow:sign": "Publishing a report under a signed agreement, with its PDF and its checks: done on the Publish page, where the person reads what they sign and sees what goes public.", "reports/flow:saveDetails": "Publishing a report under a signed agreement, with its PDF and its checks: done on the Publish page, where the person reads what they sign and sees what goes public.", + "reports/flow:chooseLanding": "Publishing a report under a signed agreement, with its PDF and its checks: done on the Publish page, where the person reads what they sign and sees what goes public.", "reports/flow:discard": "Publishing a report under a signed agreement, with its PDF and its checks: done on the Publish page, where the person reads what they sign and sees what goes public.", "reports/flow:goTo": "Publishing a report under a signed agreement, with its PDF and its checks: done on the Publish page, where the person reads what they sign and sees what goes public.", "reports/flow:backToChecks": "Publishing a report under a signed agreement, with its PDF and its checks: done on the Publish page, where the person reads what they sign and sees what goes public.",