Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 63x 54x 36x 27x 2x 12x 12x 31x 18x 18x 12x 13x | import type { EconomicsStudyRead } from "@/api/apiStore.gen";
export type EconomicsLoadState = "loading" | "error" | "empty" | "ready";
export function selectedEconomicsStudyId(
studies: EconomicsStudyRead[],
studyParam?: string,
routeFlowsheetId?: number,
) {
const requestedId = Number(studyParam);
if (Number.isFinite(requestedId)) {
const requestedStudy = studies.find((study) => study.id === requestedId);
if (
requestedStudy &&
(routeFlowsheetId === undefined ||
requestedStudy.flowsheet === routeFlowsheetId)
) {
return requestedStudy.id;
}
}
return (
studies.find((study) => study.flowsheet === routeFlowsheetId)?.id ??
(routeFlowsheetId === undefined ? studies[0]?.id : undefined)
);
}
export function selectedEconomicsUnitId(unitParam?: string) {
const unitId = Number(unitParam);
if (!Number.isInteger(unitId) || unitId <= 0) return undefined;
return unitId;
}
export function selectorPlaceholder(state: EconomicsLoadState) {
if (state === "loading") return "Loading studies";
Iif (state === "error") return "Unavailable";
if (state === "empty") return "No studies";
return "Select study";
}
export function queryErrorStatus(error: unknown) {
if (!error || typeof error !== "object" || !("status" in error)) return;
return String(error.status);
}
|