All files / src/pages/flowsheet-page/flowsheet/PropertiesSidebar/PropertyPanel/InputFields PropertyOptions.tsx

100% Statements 6/6
100% Branches 17/17
100% Functions 2/2
100% Lines 6/6

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                                                                      14209x           14209x       14209x 10229x     3980x                             1x                                                
import { EllipsisVertical, Replace, SquareFunction } from "lucide-react";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuRadioGroup,
  DropdownMenuTrigger,
} from "@/ahuora-design-system/ui/dropdown-menu";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import { PropertyInfoRead, PropertyValueRead } from "@/api/apiStore.gen";
import { CalculateFromTarget } from "../ControlTarget";
 
export default function PropertyOptions({
  value,
  property,
  isEditable,
  isControlSetPoint,
  isControlManipulated,
  onToggleFormula,
  isGuess,
  ratingMode,
  recycleFixed,
  showFormula,
}: {
  value: PropertyValueRead;
  property: PropertyInfoRead;
  isEditable: boolean;
  isControlSetPoint: number;
  isControlManipulated: number;
  onToggleFormula?: () => void;
  isGuess?: boolean;
  ratingMode?: boolean;
  recycleFixed?: boolean;
  showFormula?: boolean;
}) {
  const showReplaceDoF =
    (isEditable || recycleFixed) &&
    !isControlSetPoint &&
    !isControlManipulated &&
    !isGuess &&
    !ratingMode;
  const showAddConstraint =
    (isEditable || recycleFixed) && !isGuess && !showFormula;
 
  // If there are no options to show, don't render the options trigger at all.
  if (!showReplaceDoF && !showAddConstraint) {
    return null;
  }
 
  return (
    <DropdownMenu>
      <DropdownMenuTrigger>
        <ToolTipCover content="Options..." delay={0} asChild>
          <EllipsisVertical
            aria-label={`Options for ${property.displayName}`}
          />
        </ToolTipCover>
      </DropdownMenuTrigger>
      <DropdownMenuContent align="start">
        <DropdownMenuRadioGroup>
          {showReplaceDoF && (
            <CalculateFromTarget value={value} property={property}>
              <DropdownMenuItem
                className="flex gap-2 items-center w-full"
                onSelect={(event) => event.preventDefault()}
              >
                <Replace className="mr-2 h-4 w-4" />
                <span>Replace DoF</span>
              </DropdownMenuItem>
            </CalculateFromTarget>
          )}
          {showAddConstraint && (
            <DropdownMenuItem
              key="add-constraint"
              value="constraint"
              onSelect={onToggleFormula}
            >
              <div className="flex gap-2 items-center w-full">
                <SquareFunction className="mr-2 h-4 w-4" />
                <span>Add Constraint</span>
              </div>
            </DropdownMenuItem>
          )}
        </DropdownMenuRadioGroup>
      </DropdownMenuContent>
    </DropdownMenu>
  );
}