Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions components/reports/details-step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ export function DetailsStep({
) : null}
</Section>

{/* 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) ? (
<Section title={tLead("title")} help="doiLeads">
<LandingSection value={m.landing} options={landing} id={`${id}-official`} invalid={tried} onChange={(next) => set("landing", next)} />
</Section>
) : null}

<Section title={t("authors")} help="authors" aside={<span className="text-xs tabular-nums text-muted-foreground">{m.authors.length}</span>}>
<Paged pager={authors.pager} rowHeight={AUTHOR_ROW} label={t("authorsPager")}>
<ul className="divide-y divide-border-subtle rounded-2xl border border-border-subtle">
Expand Down Expand Up @@ -1059,12 +1067,6 @@ export function DetailsStep({
<ReferenceBox onAdd={addReferences} onBusy={setAdding} onTrouble={(words) => void toast.error(words)} />
</Section>

{landing && offersLanding(landing, m.landing) ? (
<Section title={tLead("title")} help="doiLeads">
<LandingSection value={m.landing} options={landing} id={`${id}-official`} invalid={tried} onChange={(next) => set("landing", next)} />
</Section>
) : null}

<Section title={t("links")} help="links">
{wrongLinks ? <FieldMessage id={`${id}-links-error`} className="pt-0">{t("wrongLink")}</FieldMessage> : null}
{m.relations.length ? (
Expand Down
59 changes: 55 additions & 4 deletions components/reports/doi-landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -92,6 +92,8 @@ export function LandingSettings({ landings, crossrefOn }: { landings: Landings;
})}
<li className={cn("px-4 py-3 text-xs text-pretty text-muted-foreground transition-[opacity,filter] duration-200", !crossrefOn && LOCKED_LOOK)}>
{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}
</li>
</ul>
</Zone>
Expand Down Expand Up @@ -229,9 +231,58 @@ export function LandingSection({ value, options, onChange, id, invalid }: { valu
) : null}
</AutoHeight>
<LandingPath place={place} url={away ? url : undefined} />
<AutoHeight className="!mt-0">
{host ? <p className="pt-3 text-xs text-pretty text-muted-foreground">{t("mustShow", { host, doi: options.doi })}</p> : null}
</AutoHeight>
{/* The place picked leads into what the author has to do about it, and why. */}
<WhatToDo place={place} host={host || null} doi={options.doi} />
</div>
);
}

/**
* 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 (
<p className="flex items-start gap-2.5 rounded-xl bg-inset px-3.5 py-3 text-sm text-pretty">
<CircleCheck className="mt-0.5 size-4 shrink-0 ink-success" />
<span className="min-w-0">{t("todoPage")}</span>
</p>
);
}
return (
<div className="space-y-2 rounded-xl bg-inset px-3.5 py-3 text-sm">
<p className="flex items-start gap-2.5 font-medium text-pretty">
<Info className="mt-0.5 size-4 shrink-0 text-primary" />
<span className="min-w-0">{host ? t("todoTitle", { host }) : t("todoTitleNoHost")}</span>
</p>
<div className="space-y-2 ps-6.5 text-pretty text-muted-foreground">
{doi ? (
<>
<p>{t("todoDoi")}</p>
<p className="flex w-fit max-w-full items-center gap-1 rounded-lg border border-border bg-background py-0.5 ps-2.5 pe-1">
<span dir="ltr" className="truncate font-mono text-xs text-foreground">{`https://doi.org/${doi}`}</span>
<Button
type="button"
variant="ghost"
size="icon-xs"
aria-label={t(copied ? "copied" : "copyDoi")}
className="shrink-0 text-muted-foreground"
onClick={() => void navigator.clipboard.writeText(`https://doi.org/${doi}`).then(() => setCopied(true))}
>
{copied ? <Check /> : <Copy />}
</Button>
</p>
</>
) : (
<p>{t("todoDoiLater")}</p>
)}
<p>{t(place === "notice" ? "todoWhy_notice" : "todoWhy_official", { seconds: NOTICE_SECONDS })}</p>
<p className="text-xs">{t("todoUnchecked")}</p>
</div>
</div>
);
}
Expand Down
48 changes: 46 additions & 2 deletions components/reports/publish-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
<Checks rows={(report.run?.checks ?? report.checks).map((check) => ({ id: check.id, name: check.name, result: report.run?.results.find((result) => result.checkId === check.id) }))} report={null} humanReview={basics.humanReview} />
) : report.step === "doi" ? (
<DoiStep report={report} fresh={fresh?.key === report.key && fresh.step === "doi"} onNext={() => (toTop(), onMoved("upload"))} />
<DoiStep report={report} landings={basics.landing} fresh={fresh?.key === report.key && fresh.step === "doi"} onNext={() => (toTop(), onMoved("upload"))} />
) : report.step === "upload" ? (
<UploadStep report={report} workspaceId={workspaceId!} onAttached={() => onMoved("details")} onBack={() => onStep("doi")} onNext={report.pdf?.pages !== undefined && report.metadata ? () => onStep("details") : undefined} />
) : report.step === "details" && report.metadata && report.pdf ? (
Expand Down Expand Up @@ -1647,14 +1648,47 @@ 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.
const [chosen, setBy] = useBylineBy();
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<typeof setTimeout>; send: () => void } | null>(null);
const keepNow = () => {
if (!keeping.current) return;
clearTimeout(keeping.current.timer);
keeping.current.send();
keeping.current = null;
};
const pickLanding = (next: NonNullable<typeof landing>) => {
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();
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -1819,6 +1855,14 @@ function DoiStep({ report, fresh, onNext }: { report: Report; fresh: boolean; on
</AutoHeight>
</motion.div>
</div>
{/* 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) ? (
<motion.div className="mt-8 border-t border-border-subtle pt-6" {...rise(LETTERS_AT + shown.length * LETTER)}>
<StepHead title={tLead("title")} help="doiLeads">{tLead(landings.page ? "doiStepIntro" : "doiStepIntroNeeded")}</StepHead>
<LandingSection value={landing} options={{ landings, crossref: report.registration.crossref, doi: report.doi }} id={`${choice}-landing`} invalid={false} onChange={pickLanding} />
</motion.div>
) : 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 ? (
Expand Down
29 changes: 29 additions & 0 deletions convex/reports/flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
});
});
27 changes: 26 additions & 1 deletion convex/reports/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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`). */
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion convex/reports/readingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []);
Expand Down
2 changes: 2 additions & 0 deletions convex/reports/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Loading