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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 76x 7x 7x 7x 7x 7x 7x 7x 2x 5x 18x 38x 18x | import type { EconomicsStudyRead } from "@/api/apiStore.gen";
import {
economicsResultIsStale,
staleReasonLabel,
} from "../../shared/model/economicsStaleReasons";
export const ECONOMICS_STEPS = [
{ value: "operating-lines", label: "Operating costs" },
{ value: "unit-costs", label: "Capital costs" },
{ value: "project-overview", label: "Project overview" },
{ value: "settings", label: "Settings" },
] as const;
export type EconomicsStepValue = (typeof ECONOMICS_STEPS)[number]["value"];
export type EconomicsStepState = "Incomplete" | "Warnings" | "Ready" | "Stale";
export function economicsStepStates(
study: EconomicsStudyRead,
): Record<EconomicsStepValue, EconomicsStepState> {
const resultState = study.result_state;
const hasWarnings = resultState.warnings.length > 0;
const isStale = economicsResultIsStale(resultState);
const hasResultRun = Boolean(resultState.run_id);
const calculatedState: EconomicsStepState = isStale
? "Stale"
: hasWarnings
? "Warnings"
: hasResultRun
? "Ready"
: "Incomplete";
const settingsState: EconomicsStepState = hasWarnings ? "Warnings" : "Ready";
return {
"operating-lines": calculatedState,
"unit-costs": calculatedState,
"project-overview": calculatedState,
settings: settingsState,
};
}
export function reviewResultsDetail(study: EconomicsStudyRead) {
if (study.result_state.latest_stale_reason) {
return staleReasonLabel(study.result_state.latest_stale_reason);
}
if (study.result_state.run_id) {
return `Calculation #${study.result_state.run_id}`;
}
return "No calculated result";
}
export function selectedEconomicsStep(stepParam?: string) {
const stepAliases: Partial<Record<string, EconomicsStepValue>> = {
setup: "settings",
baseline: "settings",
"review-results": "project-overview",
};
if (stepParam && stepAliases[stepParam]) {
return stepAliases[stepParam];
}
if (ECONOMICS_STEPS.some((step) => step.value === stepParam)) {
return stepParam as EconomicsStepValue;
}
return "operating-lines";
}
|