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

68.96% Statements 20/29
85.71% Branches 6/7
100% Functions 2/2
68.18% Lines 15/22

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                76x       857x 857x   857x     79x                       1015x   857x   936x       7930x 7930x   7930x             81x   7930x       7930x         8092x      
import { defineCommand } from "just-search-it";
import { Download } from "lucide-react";
import { Button } from "@/ahuora-design-system/ui/button";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import { RegisterCommand } from "@/commands/CommandProvider";
import { useProjectId } from "@/hooks/project";
import { useLazyCorePropertyvalueDownloadTagMappingsRetrieveQuery } from "../../../api/apiStore.gen";
 
export const DownloadFlowsheetTagMappings = defineCommand<[], void>(
  "downloadFlowsheetTagMappings",
);
 
export function DownloadFlowsheetTagMappingsButton() {
  const flowsheetId = useProjectId();
  const [downloadFile] =
    useLazyCorePropertyvalueDownloadTagMappingsRetrieveQuery();
 
  return (
    <ToolTipCover
      delay={100}
      asChild
      content="Download the flowsheet tag mappings for Ahuora Live"
    >
      <Button
        size="sm"
        variant="outline"
        onClick={() => {
          if (flowsheetId) {
            downloadFile({ flowsheet: flowsheetId });
          }
        }}
      >
        <Download size={16} />
      </Button>
    </ToolTipCover>
  );
}
 
export function DownloadFlowsheetTagMappingsCommand() {
  const flowsheetId = useProjectId();
  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 });
      }}
    />
  );
}