All files / src/pages/flowsheet-page/flowsheet/LeftSideBar/Formulas CustomProperties.tsx

90.9% Statements 10/11
75% Branches 6/8
100% Functions 4/4
100% Lines 10/10

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                              90x 90x 90x     90x   90x 1x 1x         90x             91x   12x                                          
import {
  useUnitopsSimulationobjectsAddExpressionCreateMutation
} from "@/api/apiStore.gen";
import {
  useCurrentObjectId,
  useObjectSchema
} from "@/hooks/flowsheetObjects";
import { useSimulationObjectPropertySet } from "@/hooks/properties";
import { Plus } from "lucide-react";
import { Button } from "../../../../../ahuora-design-system/ui/button";
import { ToolTipCover } from "../../../../../ahuora-design-system/ui/tooltip";
import { FormulaCard } from "./FormulaCard";
import { FormulaTemplates } from "./FormulaTemplates";
 
export function CustomProperties() {
  const currentObjectId = useCurrentObjectId();
  const propertySet = useSimulationObjectPropertySet(currentObjectId);
  const objectSchema = useObjectSchema(currentObjectId);
 
  const [addExpression] =
    useUnitopsSimulationobjectsAddExpressionCreateMutation();
 
  const onAddExpression = () => {
    Iif (!currentObjectId) return;
    addExpression({
      id: currentObjectId,
    });
  };
 
  return (
    // All the padding at the bottom is so that the dropdown for the expressions is not cut off.
    <div className="w-full flex flex-col gap-2 py-2">
      {propertySet &&
        propertySet.ContainedProperties.filter(
          (property) =>
            // only show properties that are not defined in the object config
            !(property.key in (objectSchema?.properties || {})),
        ).map((property) => (
          <FormulaCard key={property.key + currentObjectId} property={property} />
        ))}
      <ToolTipCover
        asChild
        content="Add a property defined by a custom formula."
      >
        <Button variant="secondary" onClick={onAddExpression}>
          <Plus aria-label="Add Custom Property" /> Add Custom Property
        </Button>
      </ToolTipCover>
      {(!propertySet || propertySet.ContainedProperties.length === 0) && (
        <p>Add custom properties (e.g capital or operation costs) here.</p>
      )}
      <FormulaTemplates />
    </div>
  );
}