All files / src/pages/flowsheet-page/flowsheet/PropertiesSidebar SelectPropertiesDialog.tsx

78.94% Statements 30/38
77.77% Branches 28/36
25% Functions 1/4
80% Lines 28/35

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                              112x           112x 112x                       112x   112x         4x 215x   112x       294x   112x 4x 3x 3x 326x   112x 111x 98x 98x 112x 210x 98x 112x     210x 308x   111x                                                                             778x 334x 448x      
import { useState } from "react";
import { toast } from "sonner";
import {
  AlertDialog,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from "@/ahuora-design-system/ui/alert-dialog";
import { Button } from "@/ahuora-design-system/ui/button";
import { DataPanel } from "./components/DataPanel";
import { PropertySelectionSummary } from "./components/PropertySelectionSummary";
import { SelectedPropertyInfo } from "./ObjectDetailsPanel";
 
export default function SelectPropertiesDialog({
  isDialogOpen,
  setIsDialogOpen,
  tempSelectedProperties,
  setTempSelectedProperties,
  handleSave,
  handleCancel = () => {},
  description = "Choose which properties you want to observe for this module.",
}: {
  isDialogOpen: boolean;
  setIsDialogOpen: (isOpen: boolean) => void;
  tempSelectedProperties: SelectedPropertyInfo[];
  setTempSelectedProperties: React.Dispatch<
    React.SetStateAction<SelectedPropertyInfo[]>
  >;
  handleSave: () => void;
  handleCancel?: () => void;
  description?: string;
}) {
  const [view, setView] = useState<"selection" | "summary">("selection");
 
  const handleNext = () => {
    if (tempSelectedProperties?.length === 0) {
      toast.warning("No properties selected!");
      return;
    }
    setView("summary");
  };
 
  const handleCancelDialog = () => {
    handleCancel();
    setIsDialogOpen(false);
    setView("selection");
  };
 
  const handleSaveDialog = () => {
    handleSave();
    setIsDialogOpen(false);
    setView("selection");
  };
  return (
    <AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>
            {view === "selection" ? "Select Properties" : "Selected Properties"}
          </AlertDialogTitle>
          <AlertDialogDescription>
            {view === "selection"
              ? description
              : "Review your selected properties."}
          </AlertDialogDescription>
        </AlertDialogHeader>
 
        <div className="">
          {view === "selection" ? (
            <div>
              <div className="lg:h-[55vh] md:h-[55vh] sm:h-[30vh] w-[50vw]">
                <DataPanel
                  setSelectedProperties={setTempSelectedProperties}
                  selectedProperties={tempSelectedProperties}
                />
              </div>
 
              <AlertDialogFooter className="flex justify-end">
                <Button variant="secondary" onClick={handleCancelDialog}>
                  Cancel
                </Button>
                <Button onClick={handleNext}>Next</Button>
              </AlertDialogFooter>
            </div>
          ) : (
            <div>
              <PropertySelectionSummary
                selectedProperties={tempSelectedProperties}
              />
 
              <AlertDialogFooter className="flex justify-end">
                <Button
                  variant="secondary"
                  onClick={() => setView("selection")}
                >
                  Back
                </Button>
                <Button
                  onClick={handleSaveDialog}
                  disabled={tempSelectedProperties.length === 0}
                >
                  Save
                </Button>
              </AlertDialogFooter>
            </div>
          )}
        </div>
      </AlertDialogContent>
    </AlertDialog>
  );
}