All files / src/pages/flowsheet-page/economics/cost-driver/model propertyOptionGroups.ts

100% Statements 11/11
50% Branches 1/2
100% Functions 5/5
100% Lines 9/9

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                            17x 450x   17x   450x     30x 17x 30x   17x                                                           51x    
import type { CostDriverPropertyOption } from "@/api/apiStore.gen";
import { CostDriverPropertyOptionScopeEnum } from "@/api/apiStore.gen";
import { costCurveUnitsCompatible } from "../../shared/model/economicsUnitCompatibility";
 
export type PropertyOptionPickerGroup = {
  label: string;
  options: CostDriverPropertyOption[];
};
 
export function propertyOptionsByPickerGroup(
  options: readonly CostDriverPropertyOption[],
  selectedCurveInputUnit?: string | null,
  manualPropertyInfo?: number | null,
) {
  const selectableOptions = options.filter(
    (option) => option.property_info !== manualPropertyInfo,
  );
  const compatibleOptions = selectedCurveInputUnit
    ? selectableOptions.filter((option) =>
        costCurveUnitsCompatible(option.unit, selectedCurveInputUnit),
      )
    : [];
  const recommended = compatibleOptions.filter((option) => option.recommended);
  const otherOptions = compatibleOptions.filter(
    (option) => !option.recommended,
  );
  return [
    { label: "Recommended", options: recommended },
    {
      label: "Unit properties",
      options: optionsForScope(
        otherOptions,
        CostDriverPropertyOptionScopeEnum.Unit,
      ),
    },
    {
      label: "Input stream properties",
      options: optionsForScope(
        otherOptions,
        CostDriverPropertyOptionScopeEnum.InputStream,
      ),
    },
    {
      label: "Output stream properties",
      options: optionsForScope(
        otherOptions,
        CostDriverPropertyOptionScopeEnum.OutputStream,
      ),
    },
  ];
}
 
function optionsForScope(
  options: readonly CostDriverPropertyOption[],
  scope: CostDriverPropertyOptionScopeEnum,
) {
  return options.filter((option) => option.scope === scope);
}