All files / src/pages/flowsheet-page/flowsheet DuplicateFlowsheetCommand.tsx

90.9% Statements 10/11
50% Branches 1/2
100% Functions 2/2
90.9% Lines 10/11

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              33x     1718x 1718x   1718x 2x 2x 2x 2x 2x         1718x                          
import { useFlowsheetCopyCreateMutation } from "@/api/apiStore.gen";
import { RegisterCommand } from "@/commands/CommandProvider";
import { defineCommand } from "just-search-it";
import { Fullscreen } from "lucide-react";
import { useProjectId } from "../../../hooks/project";
import { toast } from "sonner";
 
export const DuplicateFlowsheet = defineCommand<[], void>("duplicateFlowsheet");
 
export function DuplicateFlowsheetCommand() {
  const projectId = useProjectId();
  const [copyFlowsheet] = useFlowsheetCopyCreateMutation();
 
  const handleCopyFlowsheet = async () => {
    const response = await copyFlowsheet({ flowsheet: projectId });
    const newFlowsheetId = response.data;
    if (newFlowsheetId){
      window.open(`/project/${newFlowsheetId}/flowsheet`);
      toast.success("Flowsheet Duplicated Successfully");
    } else E{
      toast.error("Something went wrong when duplicating the flowsheet");
    }
  };
  return (
    <RegisterCommand
      command={DuplicateFlowsheet}
      args={[]}
      name="Duplicate Flowsheet"
      description="Create a copy of the current flowsheet"
      group="Display & flowsheet controls"
      icon={<Fullscreen />}
      action={handleCopyFlowsheet}
      shortcuts={[]}
    />
  );
}