All files / src/pages/flowsheet-page/export DownloadFlowsheetTagMappings.tsx

61.11% Statements 11/18
75% Branches 3/4
100% Functions 1/1
61.53% Lines 8/13

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            103x       945x 945x   945x             135x   945x       945x         1215x      
import { defineCommand } from "just-search-it";
import { Download } from "lucide-react";
import { RegisterCommand } from "@/commands/CommandProvider";
import { useFlowsheetId } from "@/hooks/project";
import { useLazyCorePropertyvalueDownloadTagMappingsRetrieveQuery } from "../../../api/apiStore.gen";
 
export const DownloadFlowsheetTagMappings = defineCommand<[], void>(
  "downloadFlowsheetTagMappings",
);
 
export function DownloadFlowsheetTagMappingsCommand() {
  const flowsheetId = useFlowsheetId();
  const [downloadFile] =
    useLazyCorePropertyvalueDownloadTagMappingsRetrieveQuery();
 
  if (!flowsheetId) {
    return null;
  }
 
  return (
    <RegisterCommand
      command={DownloadFlowsheetTagMappings}
      args={[]}
      name="Download Flowsheet Tag Mappings"
      description="Download the tag mappings for the current flowsheet as a JSON file, for use in Ahuora Live"
      group="Export"
      icon={<Download />}
      action={async () => {
        Iif (!flowsheetId) return;
        downloadFile({ flowsheet: flowsheetId });
      }}
    />
  );
}