swarm-ui: the report, review and classifier-key pages read through useResource
Part of the unification order in the UI sweep issue (step d, the rest). The pull-request and issue reports (the repo list and the report), the review try-out's repo list and classifier cap, and the classifier key move to the shared read hook. A failed report still drops its rows, now by reading 'error ? null : loaded' instead of a handler that cleared them. The reads that seed a draft, post, or are not a plain request stay as they were.
This commit is contained in:
parent
bbdd32c2e0
commit
c5cc961028
8 changed files with 103 additions and 191 deletions
|
|
@ -27,18 +27,24 @@
|
||||||
// checkbox row — folded into the "labels" column's own `Table` filter
|
// checkbox row — folded into the "labels" column's own `Table` filter
|
||||||
// (`filterMode: "multiselect"`) per mara's "fold filters into table"
|
// (`filterMode: "multiselect"`) per mara's "fold filters into table"
|
||||||
// request, one mechanism instead of two.
|
// request, one mechanism instead of two.
|
||||||
import { useEffect, useMemo, useState } from "preact/hooks";
|
import { useMemo } from "preact/hooks";
|
||||||
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
||||||
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
|
|
||||||
import { Badge } from "@hive/shared/badge.js";
|
import { Badge } from "@hive/shared/badge.js";
|
||||||
import { useLocalSetting } from "@hive/shared/settings-storage.js";
|
import { useLocalSetting } from "@hive/shared/settings-storage.js";
|
||||||
|
import { fetchJson } from "../ui/polled/usePolled.js";
|
||||||
|
import { useResource } from "../ui/polled/useResource.js";
|
||||||
import { ExternalLink } from "../ui/external-link/ExternalLink.js";
|
import { ExternalLink } from "../ui/external-link/ExternalLink.js";
|
||||||
import { LazyDisclosure } from "../ui/disclosure/LazyDisclosure.js";
|
import { LazyDisclosure } from "../ui/disclosure/LazyDisclosure.js";
|
||||||
import { CheckboxField } from "../ui/checkbox-field/CheckboxField.js";
|
import { CheckboxField } from "../ui/checkbox-field/CheckboxField.js";
|
||||||
import { SelectField } from "../ui/select-field/SelectField.js";
|
import { SelectField } from "../ui/select-field/SelectField.js";
|
||||||
import { Table, type TableColumn } from "../ui/table/Table.js";
|
import { Table, type TableColumn } from "../ui/table/Table.js";
|
||||||
import { TableSkeleton } from "../ui/table/TableSkeleton.js";
|
import { TableSkeleton } from "../ui/table/TableSkeleton.js";
|
||||||
import { ALL_REPOS, reportUrl, repoOptions } from "./issue-report-repo.js";
|
import {
|
||||||
|
ALL_REPOS,
|
||||||
|
reportRows,
|
||||||
|
reportUrl,
|
||||||
|
repoOptions,
|
||||||
|
} from "./issue-report-repo.js";
|
||||||
import "./IssueReportPage.css";
|
import "./IssueReportPage.css";
|
||||||
|
|
||||||
interface IssueReportRow {
|
interface IssueReportRow {
|
||||||
|
|
@ -131,17 +137,10 @@ function SortHeader({
|
||||||
}
|
}
|
||||||
|
|
||||||
function IssueReportBody() {
|
function IssueReportBody() {
|
||||||
const [repos, setRepos] = useState<string[] | null>(null);
|
|
||||||
const [repoFilter, setRepoFilter] = useLocalSetting(
|
const [repoFilter, setRepoFilter] = useLocalSetting(
|
||||||
REPO_FILTER_KEY,
|
REPO_FILTER_KEY,
|
||||||
ALL_REPOS,
|
ALL_REPOS,
|
||||||
);
|
);
|
||||||
const [rows, setRows] = useState<IssueReportRow[] | null>(null);
|
|
||||||
// One slot per request, so a report that loads does not clear a repo
|
|
||||||
// list that failed.
|
|
||||||
const [reposError, setReposError] = useState<ProblemDetails | null>(null);
|
|
||||||
const [error, setError] = useState<ProblemDetails | null>(null);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [hideBlocked, setHideBlocked] = useLocalSetting(
|
const [hideBlocked, setHideBlocked] = useLocalSetting(
|
||||||
HIDE_BLOCKED_KEY,
|
HIDE_BLOCKED_KEY,
|
||||||
false,
|
false,
|
||||||
|
|
@ -154,62 +153,24 @@ function IssueReportBody() {
|
||||||
|
|
||||||
// Repo dropdown source, fetched once — this page has no refresh
|
// Repo dropdown source, fetched once — this page has no refresh
|
||||||
// cadence, and a repo gaining/losing its first/last open issue between
|
// cadence, and a repo gaining/losing its first/last open issue between
|
||||||
// visits is rare enough that a manual reload covers it. Same
|
// visits is rare enough that a manual reload covers it.
|
||||||
// `cancelled` guard as the repo-filter effect below, so an unmount
|
const { data: repos, error: reposError } = useResource(
|
||||||
// mid-flight (navigating away before this resolves) doesn't call
|
(signal) => fetchJson<string[]>("/api/repos", signal),
|
||||||
// `setRepos`/`setReposError` on a component that's already gone.
|
[],
|
||||||
useEffect(() => {
|
);
|
||||||
let cancelled = false;
|
|
||||||
(async () => {
|
|
||||||
const r = await fetch("/api/repos");
|
|
||||||
if (!r.ok) {
|
|
||||||
if (!cancelled) setReposError(await readApiError(r));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = (await r.json()) as string[];
|
|
||||||
if (!cancelled) setRepos(data);
|
|
||||||
})().catch((e: unknown) => {
|
|
||||||
if (!cancelled) setReposError({ detail: String(e) });
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// The one fetch this page re-runs on state change — everything else
|
// The one read this page re-runs on a state change: the repo choice. A failed
|
||||||
// (sort, hide-blocked, the table's own per-column filters) works over
|
// report drops the rows, so the table never shows another repo's rows under
|
||||||
// what's already loaded.
|
// this repo's error.
|
||||||
useEffect(() => {
|
const {
|
||||||
let cancelled = false;
|
data: loaded,
|
||||||
setLoading(true);
|
error,
|
||||||
// A failed report drops the rows, so the table never shows another
|
loading,
|
||||||
// repo's issues under this repo's error.
|
} = useResource(
|
||||||
const fail = (problem: ProblemDetails) => {
|
(signal) => fetchJson<IssueReportRow[]>(reportUrl(repoFilter), signal),
|
||||||
setRows(null);
|
[repoFilter],
|
||||||
setError(problem);
|
);
|
||||||
};
|
const rows = reportRows(error, loaded);
|
||||||
(async () => {
|
|
||||||
const r = await fetch(reportUrl(repoFilter));
|
|
||||||
if (!r.ok) {
|
|
||||||
const problem = await readApiError(r);
|
|
||||||
if (!cancelled) fail(problem);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = (await r.json()) as IssueReportRow[];
|
|
||||||
if (cancelled) return;
|
|
||||||
setRows(data);
|
|
||||||
setError(null);
|
|
||||||
})()
|
|
||||||
.catch((e: unknown) => {
|
|
||||||
if (!cancelled) fail({ detail: String(e) });
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (!cancelled) setLoading(false);
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [repoFilter]);
|
|
||||||
|
|
||||||
const visibleRows = useMemo(() => {
|
const visibleRows = useMemo(() => {
|
||||||
let out = rows ?? [];
|
let out = rows ?? [];
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,18 @@
|
||||||
// loaded; only the repo selection fetches again. No default filter is applied.
|
// loaded; only the repo selection fetches again. No default filter is applied.
|
||||||
// The filters the user sets are kept in the browser (the table's storage key,
|
// The filters the user sets are kept in the browser (the table's storage key,
|
||||||
// and the repo choice).
|
// and the repo choice).
|
||||||
import { useEffect, useState } from "preact/hooks";
|
|
||||||
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
||||||
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
|
|
||||||
import { Badge, type BadgeTone } from "@hive/shared/badge.js";
|
import { Badge, type BadgeTone } from "@hive/shared/badge.js";
|
||||||
import { useLocalSetting } from "@hive/shared/settings-storage.js";
|
import { useLocalSetting } from "@hive/shared/settings-storage.js";
|
||||||
import { LazyDisclosure } from "../ui/disclosure/LazyDisclosure.js";
|
import { LazyDisclosure } from "../ui/disclosure/LazyDisclosure.js";
|
||||||
import { ExternalLink } from "../ui/external-link/ExternalLink.js";
|
import { ExternalLink } from "../ui/external-link/ExternalLink.js";
|
||||||
|
import { fetchJson } from "../ui/polled/usePolled.js";
|
||||||
|
import { useResource } from "../ui/polled/useResource.js";
|
||||||
import { RelativeTime } from "../ui/relative-time/RelativeTime.js";
|
import { RelativeTime } from "../ui/relative-time/RelativeTime.js";
|
||||||
import { SelectField } from "../ui/select-field/SelectField.js";
|
import { SelectField } from "../ui/select-field/SelectField.js";
|
||||||
import { Table, type TableColumn } from "../ui/table/Table.js";
|
import { Table, type TableColumn } from "../ui/table/Table.js";
|
||||||
import { TableSkeleton } from "../ui/table/TableSkeleton.js";
|
import { TableSkeleton } from "../ui/table/TableSkeleton.js";
|
||||||
import { ALL_REPOS, repoOptions } from "./issue-report-repo.js";
|
import { ALL_REPOS, repoOptions, reportRows } from "./issue-report-repo.js";
|
||||||
import {
|
import {
|
||||||
approvalsText,
|
approvalsText,
|
||||||
diffSize,
|
diffSize,
|
||||||
|
|
@ -173,70 +173,30 @@ const COLUMNS: TableColumn<PrReportRow>[] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
function PrReportBody() {
|
function PrReportBody() {
|
||||||
const [repos, setRepos] = useState<string[] | null>(null);
|
|
||||||
const [repoFilter, setRepoFilter] = useLocalSetting(
|
const [repoFilter, setRepoFilter] = useLocalSetting(
|
||||||
REPO_FILTER_KEY,
|
REPO_FILTER_KEY,
|
||||||
ALL_REPOS,
|
ALL_REPOS,
|
||||||
);
|
);
|
||||||
const [rows, setRows] = useState<PrReportRow[] | null>(null);
|
|
||||||
// One slot per request, so a report that loads does not clear a repo list
|
|
||||||
// that failed.
|
|
||||||
const [reposError, setReposError] = useState<ProblemDetails | null>(null);
|
|
||||||
const [error, setError] = useState<ProblemDetails | null>(null);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
// The dropdown's source, read once: a repo gaining or losing its first or
|
// The dropdown's source, read once: a repo gaining or losing its first or
|
||||||
// last open PR between visits is rare enough that a reload covers it.
|
// last open PR between visits is rare enough that a reload covers it.
|
||||||
useEffect(() => {
|
const { data: repos, error: reposError } = useResource(
|
||||||
let cancelled = false;
|
(signal) => fetchJson<string[]>("/api/pulls/repos", signal),
|
||||||
(async () => {
|
[],
|
||||||
const r = await fetch("/api/pulls/repos");
|
);
|
||||||
if (!r.ok) {
|
|
||||||
if (!cancelled) setReposError(await readApiError(r));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = (await r.json()) as string[];
|
|
||||||
if (!cancelled) setRepos(data);
|
|
||||||
})().catch((e: unknown) => {
|
|
||||||
if (!cancelled) setReposError({ detail: String(e) });
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// The one fetch that re-runs on a state change: the repo choice.
|
// The one read this page re-runs on a state change: the repo choice. A failed
|
||||||
useEffect(() => {
|
// report drops the rows, so the table never shows another repo's rows under
|
||||||
let cancelled = false;
|
// this repo's error.
|
||||||
setLoading(true);
|
const {
|
||||||
// A failed report drops the rows, so the table never shows another
|
data: loaded,
|
||||||
// repo's PRs under this repo's error.
|
error,
|
||||||
const fail = (problem: ProblemDetails) => {
|
loading,
|
||||||
setRows(null);
|
} = useResource(
|
||||||
setError(problem);
|
(signal) => fetchJson<PrReportRow[]>(prReportUrl(repoFilter), signal),
|
||||||
};
|
[repoFilter],
|
||||||
(async () => {
|
);
|
||||||
const r = await fetch(prReportUrl(repoFilter));
|
const rows = reportRows(error, loaded);
|
||||||
if (!r.ok) {
|
|
||||||
const problem = await readApiError(r);
|
|
||||||
if (!cancelled) fail(problem);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = (await r.json()) as PrReportRow[];
|
|
||||||
if (cancelled) return;
|
|
||||||
setRows(data);
|
|
||||||
setError(null);
|
|
||||||
})()
|
|
||||||
.catch((e: unknown) => {
|
|
||||||
if (!cancelled) fail({ detail: String(e) });
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (!cancelled) setLoading(false);
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [repoFilter]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
|
|
@ -42,3 +42,11 @@ export function repoOptions(
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rows a report shows: none while the report is in error, so the table
|
||||||
|
* never keeps the last repo's rows under this repo's error.
|
||||||
|
*/
|
||||||
|
export function reportRows<T>(error: unknown, loaded: T[] | null): T[] | null {
|
||||||
|
return error ? null : loaded;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
|
||||||
import { ActionRow } from "../../ui/action-row/ActionRow.js";
|
import { ActionRow } from "../../ui/action-row/ActionRow.js";
|
||||||
import { Button } from "../../ui/button/Button.js";
|
import { Button } from "../../ui/button/Button.js";
|
||||||
import { Hint } from "../../ui/hint/Hint.js";
|
import { Hint } from "../../ui/hint/Hint.js";
|
||||||
|
import { fetchJson } from "../../ui/polled/usePolled.js";
|
||||||
|
import { useResource } from "../../ui/polled/useResource.js";
|
||||||
import { TextField } from "../../ui/text-field/TextField.js";
|
import { TextField } from "../../ui/text-field/TextField.js";
|
||||||
import { keyOf, keyProblem, keyStatus, type KeysBody } from "./KeyTypes.js";
|
import { keyOf, keyProblem, keyStatus, type KeysBody } from "./KeyTypes.js";
|
||||||
import type { Runtime } from "./SettingsTypes.js";
|
import type { Runtime } from "./SettingsTypes.js";
|
||||||
|
|
@ -17,35 +19,17 @@ import type { Runtime } from "./SettingsTypes.js";
|
||||||
const KEYS = "/api/review-classifier/keys";
|
const KEYS = "/api/review-classifier/keys";
|
||||||
|
|
||||||
export function ClassifierKey({ runtime }: { runtime: Runtime }) {
|
export function ClassifierKey({ runtime }: { runtime: Runtime }) {
|
||||||
const [keys, setKeys] = useState<KeysBody | null>(null);
|
const {
|
||||||
const [loadError, setLoadError] = useState<ProblemDetails | null>(null);
|
data: keys,
|
||||||
|
error: loadError,
|
||||||
|
setData: setKeys,
|
||||||
|
} = useResource((signal) => fetchJson<KeysBody>(KEYS, signal), []);
|
||||||
const [saveError, setSaveError] = useState<ProblemDetails | null>(null);
|
const [saveError, setSaveError] = useState<ProblemDetails | null>(null);
|
||||||
// The key as typed. Never kept after a save.
|
// The key as typed. Never kept after a save.
|
||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [justSaved, setJustSaved] = useState(false);
|
const [justSaved, setJustSaved] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let cancelled = false;
|
|
||||||
void (async () => {
|
|
||||||
try {
|
|
||||||
const res = await fetch(KEYS);
|
|
||||||
if (cancelled) return;
|
|
||||||
if (!res.ok) {
|
|
||||||
setLoadError(await readApiError(res));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const body = (await res.json()) as KeysBody;
|
|
||||||
if (!cancelled) setKeys(body);
|
|
||||||
} catch (e: unknown) {
|
|
||||||
if (!cancelled) setLoadError({ detail: String(e) });
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// A key typed for one runtime must not be saved to the other.
|
// A key typed for one runtime must not be saved to the other.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setText("");
|
setText("");
|
||||||
|
|
@ -71,7 +55,8 @@ export function ClassifierKey({ runtime }: { runtime: Runtime }) {
|
||||||
setSaveError(await readApiError(res));
|
setSaveError(await readApiError(res));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setKeys((await res.json()) as KeysBody);
|
const saved = (await res.json()) as KeysBody;
|
||||||
|
setKeys(() => saved);
|
||||||
setText("");
|
setText("");
|
||||||
setJustSaved(true);
|
setJustSaved(true);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
|
||||||
import { Disclosure } from "../../ui/disclosure/Disclosure.js";
|
import { Disclosure } from "../../ui/disclosure/Disclosure.js";
|
||||||
import { ExternalLink } from "../../ui/external-link/ExternalLink.js";
|
import { ExternalLink } from "../../ui/external-link/ExternalLink.js";
|
||||||
import { Panel } from "../../ui/panel/Panel.js";
|
import { Panel } from "../../ui/panel/Panel.js";
|
||||||
|
import { fetchJson } from "../../ui/polled/usePolled.js";
|
||||||
|
import { useResource } from "../../ui/polled/useResource.js";
|
||||||
import { TextField } from "../../ui/text-field/TextField.js";
|
import { TextField } from "../../ui/text-field/TextField.js";
|
||||||
import { ClassificationEditor } from "./ClassificationEditor.js";
|
import { ClassificationEditor } from "./ClassificationEditor.js";
|
||||||
import { TryOutResult } from "../review-common/TryOutResult.js";
|
import { TryOutResult } from "../review-common/TryOutResult.js";
|
||||||
|
|
@ -40,6 +42,7 @@ import {
|
||||||
addProblem,
|
addProblem,
|
||||||
draftFromRule,
|
draftFromRule,
|
||||||
hasTypedText,
|
hasTypedText,
|
||||||
|
maxClassificationsOf,
|
||||||
prNumber,
|
prNumber,
|
||||||
repoProblem,
|
repoProblem,
|
||||||
rowsProblem,
|
rowsProblem,
|
||||||
|
|
@ -109,14 +112,8 @@ export function ReviewTryOut() {
|
||||||
|
|
||||||
// What the two fields offer to complete to. The fields stay free text, so a
|
// What the two fields offer to complete to. The fields stay free text, so a
|
||||||
// repo or a PR the lists lack, a merged one say, can still be typed.
|
// repo or a PR the lists lack, a merged one say, can still be typed.
|
||||||
const [repoChoices, setRepoChoices] = useState<string[]>([]);
|
|
||||||
const [repoChoicesError, setRepoChoicesError] =
|
|
||||||
useState<ProblemDetails | null>(null);
|
|
||||||
const [pulls, setPulls] = useState<OpenPull[]>([]);
|
const [pulls, setPulls] = useState<OpenPull[]>([]);
|
||||||
const [pullsError, setPullsError] = useState<ProblemDetails | null>(null);
|
const [pullsError, setPullsError] = useState<ProblemDetails | null>(null);
|
||||||
const [maxClassifications, setMaxClassifications] = useState<number | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
const running = starting || runId !== null;
|
const running = starting || runId !== null;
|
||||||
|
|
||||||
|
|
@ -125,46 +122,19 @@ export function ReviewTryOut() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
// The repos with an open PR, read once when the page opens.
|
// The repos with an open PR, read once when the page opens.
|
||||||
useEffect(() => {
|
const { data: repoList, error: repoChoicesError } = useResource(
|
||||||
let cancelled = false;
|
(signal) => fetchJson<string[]>(PULL_REPOS, signal),
|
||||||
void (async () => {
|
[],
|
||||||
try {
|
);
|
||||||
const res = await fetch(PULL_REPOS);
|
const repoChoices = repoList ?? [];
|
||||||
if (cancelled) return;
|
|
||||||
if (!res.ok) {
|
|
||||||
setRepoChoicesError(await readApiError(res));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setRepoChoices((await res.json()) as string[]);
|
|
||||||
} catch (e: unknown) {
|
|
||||||
if (!cancelled) setRepoChoicesError({ detail: String(e) });
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// How many rows a run takes: the classifier settings', read once. Until it
|
// How many rows a run takes: the classifier settings', read once. Until it
|
||||||
// is known, or when it cannot be read, the run endpoint is the only cap.
|
// is known, or when it cannot be read, the run endpoint is the only cap.
|
||||||
useEffect(() => {
|
const { data: settings } = useResource(
|
||||||
let cancelled = false;
|
(signal) => fetchJson<{ max_classifications?: number }>(SETTINGS, signal),
|
||||||
void (async () => {
|
[],
|
||||||
try {
|
);
|
||||||
const res = await fetch(SETTINGS);
|
const maxClassifications = maxClassificationsOf(settings);
|
||||||
if (cancelled || !res.ok) return;
|
|
||||||
const body = (await res.json()) as { max_classifications?: number };
|
|
||||||
if (!cancelled && typeof body.max_classifications === "number") {
|
|
||||||
setMaxClassifications(body.max_classifications);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// The endpoint still refuses a run that is too long.
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// The open PRs of the repo once it is typed or picked and has stopped
|
// The open PRs of the repo once it is typed or picked and has stopped
|
||||||
// changing. A repo that is not valid yet has no list.
|
// changing. A repo that is not valid yet has no list.
|
||||||
|
|
|
||||||
|
|
@ -197,3 +197,15 @@ export function toBody(d: ClassificationDraft): ClassificationBody {
|
||||||
threshold: thresholdValue(d.threshold) ?? 0,
|
threshold: thresholdValue(d.threshold) ?? 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The classifier settings' cap on rows per run, or `null` when it is not known
|
||||||
|
* yet or the settings lack one: then the run endpoint is the only cap.
|
||||||
|
*/
|
||||||
|
export function maxClassificationsOf(
|
||||||
|
settings: { max_classifications?: unknown } | null,
|
||||||
|
): number | null {
|
||||||
|
return typeof settings?.max_classifications === "number"
|
||||||
|
? settings.max_classifications
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { test } from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import {
|
import {
|
||||||
ALL_REPOS,
|
ALL_REPOS,
|
||||||
|
reportRows,
|
||||||
reportUrl,
|
reportUrl,
|
||||||
repoOptions,
|
repoOptions,
|
||||||
} from "../src/pages/issue-report-repo.ts";
|
} from "../src/pages/issue-report-repo.ts";
|
||||||
|
|
@ -53,3 +54,10 @@ test("repoOptions: a remembered repo missing from the list says why", () => {
|
||||||
label: "a/x (no open issues)",
|
label: "a/x (no open issues)",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("reportRows: a failed report shows no rows, a good one shows them", () => {
|
||||||
|
const rows = [{ n: 1 }];
|
||||||
|
assert.equal(reportRows({ detail: "boom" }, rows), null);
|
||||||
|
assert.equal(reportRows(null, rows), rows);
|
||||||
|
assert.equal(reportRows(null, null), null);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
draftProblem,
|
draftProblem,
|
||||||
duplicateName,
|
duplicateName,
|
||||||
hasTypedText,
|
hasTypedText,
|
||||||
|
maxClassificationsOf,
|
||||||
prNumber,
|
prNumber,
|
||||||
repoProblem,
|
repoProblem,
|
||||||
rowsProblem,
|
rowsProblem,
|
||||||
|
|
@ -154,3 +155,10 @@ test("the page's one hint names what disables opening a PR before the PR number"
|
||||||
assert.equal(rowsProblem("o/r", [row()]), null);
|
assert.equal(rowsProblem("o/r", [row()]), null);
|
||||||
assert.equal(runProblem("o/r", "7", [row()]), null);
|
assert.equal(runProblem("o/r", "7", [row()]), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("maxClassificationsOf: the settings cap when it is a number, else none", () => {
|
||||||
|
assert.equal(maxClassificationsOf({ max_classifications: 20 }), 20);
|
||||||
|
assert.equal(maxClassificationsOf({}), null);
|
||||||
|
assert.equal(maxClassificationsOf({ max_classifications: "20" }), null);
|
||||||
|
assert.equal(maxClassificationsOf(null), null);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue