All files / src/pages/flowsheet-page/multi-steady-state DownloadTagMappings.tsx

62.5% Statements 10/16
42.85% Branches 3/7
50% Functions 2/4
66.66% Lines 10/15

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                    49x     61x   61x 61x                                                   5514x 5514x 5514x   5514x 5385x     129x                                    
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 { useLazyCoreDataColumnDownloadTagMappingsRetrieveQuery } from "../../../api/apiStore.gen";
import { RegisterCommand } from "../../../commands/CommandProvider";
import { useProjectId } from "../../../hooks/project";
import { useSearchParam } from "../../../hooks/searchParams";
import { useCurrentScenario } from "../flowsheet/LeftSideBar/Scenarios/useCurrentScenario";
 
export const ExportMSSResults = defineCommand<[], void>("downloadTagMappings");
 
export function DownloadTagMappingsButton() {
  const scenario = useCurrentScenario();
  const [downloadFile] =
    useLazyCoreDataColumnDownloadTagMappingsRetrieveQuery();
  return (
    <ToolTipCover
      delay={100}
      asChild
      content="Download the MSS mappings for Ahuora Live"
    >
      <Button
        size="sm"
        variant="outline"
        onClick={() => {
          console.log("Downloading tag mappings for scenario", scenario);
          Iif (scenario)
            downloadFile({
              flowsheet: scenario.flowsheet,
              scenario: scenario.id,
            });
        }}
      >
        <Download size="sm"></Download>
      </Button>
    </ToolTipCover>
  );
}
 
export function DownloadTagMappingsCommand() {
  const [downloadFile] =
    useLazyCoreDataColumnDownloadTagMappingsRetrieveQuery();
  const [scenario_id] = useSearchParam("scenario");
  const flowsheet_id = useProjectId();
 
  if (!flowsheet_id || !scenario_id) {
    return null;
  }
 
  return (
    <RegisterCommand
      command={ExportMSSResults}
      args={[]}
      name="Download MSS Tag Mappings"
      description="Download the tag mappings for the current multi-steady-state scenario as a JSON file, for use in Ahuora Live"
      group="Export"
      icon={<Download />}
      action={async () => {
        Iif (!flowsheet_id || !scenario_id) return;
        downloadFile({
          flowsheet: flowsheet_id,
          scenario: scenario_id,
        });
      }}
    />
  );
}