All files / src/pages/flowsheet-page/economics/shared/model economicsStaleReasons.ts

80% Statements 4/5
71.42% Branches 5/7
100% Functions 0/0
75% Lines 3/4

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          76x                                                     433x 33x              
import type {
  EconomicsResultRunRead,
  ResultStatePayload,
} from "@/api/apiStore.gen";
 
const STALE_REASON_LABELS: Record<string, string> = {
  assumptions_changed: "Settings profile changed",
  baseline_changed: "Settings profile changed",
  capital_lines_changed: "Capital lines changed",
  cost_curve_changed: "Cost curve changed",
  economics_api_saved: "Economics configuration changed",
  economics_assumptions_api_saved: "Settings profile changed",
  economics_baseline_api_saved: "Settings profile changed",
  economics_capital_line_api_saved: "Capital lines changed",
  economics_cost_driver_api_saved: "Cost driver settings changed",
  economics_costable_item_api_saved: "Cost item settings changed",
  economics_enable_costing_api: "Cost item settings changed",
  economics_equipment_mapping_api_saved: "Equipment costing settings changed",
  economics_operating_line_api_saved: "Operating lines changed",
  economics_operating_line_property_selected: "Operating lines changed",
  economics_settings_profile_saved: "Settings profile changed",
  economics_settings_profile_selected: "Settings profile changed",
  operating_lines_changed: "Operating lines changed",
};
 
export function staleReasonLabel(reason: string) {
  return STALE_REASON_LABELS[reason] ?? "Economics configuration changed";
}
 
export function economicsResultIsStale(
  resultState: EconomicsResultRunRead | ResultStatePayload | undefined,
) {
  if (!resultState) return false;
  return (
    resultState.status === "stale" ||
    resultState.classification === "stale" ||
    Boolean(resultState.requires_solve) ||
    Boolean(resultState.latest_stale_reason)
  );
}