All files / src/pages/flowsheet-page/economics/cost-items-panel/unit-costs UnitCostTable.tsx

81.81% Statements 27/33
60.78% Branches 31/51
40% Functions 2/5
94.73% Lines 18/19

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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159                                                144x                                                                                                   161x 161x   161x         7x     144x   7x       151x 144x         144x                                             2880x 432x         7x       151x 144x                                           2592x 432x 432x      
import { useMemo } from "react";
import type {
  BulkEquipmentSetupRequest,
  BulkEquipmentSetupResult,
  CapitalCostLineRead,
  CostableItemRead,
  CostCurveAuthoring,
  CostCurveEquipmentCategoryRead,
  CostCurveRead,
  EconomicsLangFactorDefaultRead,
  EconomicsResultLineRead,
  EquipmentMappingRead,
  PatchedCapitalCostLine,
  PatchedCostableItem,
  PatchedEquipmentMapping,
  SimulationObjectRead,
} from "@/api/apiStore.gen";
import { isUnsupportedUnitCost } from "../model/capitalLineHelpers";
import type { UnitCostRow } from "../model/capitalLineTypes";
import { groupRowsByEquipmentCategory } from "../model/unitCostGrouping";
import { EmptyState, SectionHeading } from "../ui/CapitalLineUi";
import { UnitCostCardList } from "./UnitCostCardList";
import { UnitCostCategoryGroup } from "./UnitCostCategoryGroup";
 
export function UnitCostTable({
  rows,
  curves,
  equipmentOptions,
  langFactorDefaults,
  capitalLines,
  resultLines,
  canEdit,
  busy,
  onEnableCosting,
  onCostableItemPatch,
  onMappingPatch,
  onBulkEquipmentSetup,
  onCapitalLinePatch,
  onCreateCurve,
  costCurveSaving,
  resultStale,
  resultRunId,
  focusedSimulationObjectId,
}: {
  rows: UnitCostRow[];
  curves: CostCurveRead[];
  equipmentOptions: readonly CostCurveEquipmentCategoryRead[];
  langFactorDefaults: EconomicsLangFactorDefaultRead[];
  capitalLines: CapitalCostLineRead[];
  resultLines: EconomicsResultLineRead[];
  canEdit: boolean;
  busy: boolean;
  onEnableCosting: (unit: SimulationObjectRead) => Promise<void>;
  onCostableItemPatch: (
    item: CostableItemRead,
    patch: PatchedCostableItem,
  ) => Promise<void>;
  onMappingPatch: (
    mapping: EquipmentMappingRead,
    patch: PatchedEquipmentMapping,
  ) => Promise<void>;
  onBulkEquipmentSetup: (
    request: BulkEquipmentSetupRequest,
  ) => Promise<BulkEquipmentSetupResult[]>;
  onCapitalLinePatch: (
    line: CapitalCostLineRead,
    patch: PatchedCapitalCostLine,
  ) => Promise<void>;
  onCreateCurve: (curve: CostCurveAuthoring) => Promise<CostCurveRead>;
  costCurveSaving: boolean;
  resultStale: boolean;
  resultRunId: number | null;
  focusedSimulationObjectId?: number;
}) {
  const supportedRows = rows.filter((row) => !isUnsupportedUnitCost(row));
  const unsupportedRows = rows.filter(isUnsupportedUnitCost);
  const supportedGroups = useMemo(
    () => groupRowsByEquipmentCategory(supportedRows),
    [supportedRows],
  );
  return (
    <div className="space-y-5" aria-label="Unit operations">
      <SectionHeading
        title="Unit operations"
        help="Unit operations that can generate capital lines for this study."
      />
      <section aria-label="Supported unit operations" className="space-y-3">
        <SectionHeading
          title="Supported unit operations"
          count={supportedRows.length}
          help="Compatible unit operations can be enabled and configured for calculated capital lines."
        />
        {supportedRows.length === 0 ? (
          <EmptyState text="No supported unit operations found." />
        ) : (
          <div className="grid gap-4">
            {supportedGroups.map((group) => (
              <UnitCostCategoryGroup
                key={group.key}
                group={group}
                curves={curves}
                equipmentOptions={equipmentOptions}
                langFactorDefaults={langFactorDefaults}
                capitalLines={capitalLines}
                resultLines={resultLines}
                canEdit={canEdit}
                busy={busy}
                onEnableCosting={onEnableCosting}
                onCostableItemPatch={onCostableItemPatch}
                onMappingPatch={onMappingPatch}
                onBulkEquipmentSetup={onBulkEquipmentSetup}
                onCapitalLinePatch={onCapitalLinePatch}
                onCreateCurve={onCreateCurve}
                costCurveSaving={costCurveSaving}
                resultStale={resultStale}
                resultRunId={resultRunId}
                focusedSimulationObjectId={focusedSimulationObjectId}
              />
            ))}
          </div>
        )}
      </section>
      <section
        aria-label="Partially supported unit operations"
        className="space-y-3"
      >
        <SectionHeading
          title="Partially supported unit operations"
          count={unsupportedRows.length}
          help="These unit operations can be costed with a custom curve, but do not have a default sizing template yet."
        />
        {unsupportedRows.length === 0 ? (
          <EmptyState text="No partially supported unit operations in this study." />
        ) : (
          <UnitCostCardList
            rows={unsupportedRows}
            curves={curves}
            equipmentOptions={equipmentOptions}
            langFactorDefaults={langFactorDefaults}
            capitalLines={capitalLines}
            resultLines={resultLines}
            canEdit={canEdit}
            busy={busy}
            onEnableCosting={onEnableCosting}
            onCostableItemPatch={onCostableItemPatch}
            onMappingPatch={onMappingPatch}
            onCapitalLinePatch={onCapitalLinePatch}
            onCreateCurve={onCreateCurve}
            costCurveSaving={costCurveSaving}
            resultStale={resultStale}
            resultRunId={resultRunId}
            focusedSimulationObjectId={focusedSimulationObjectId}
          />
        )}
      </section>
    </div>
  );
}