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

63.63% Statements 7/11
40% Branches 2/5
100% Functions 0/0
70% Lines 7/10

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              62x     7128x 7128x 7128x     6965x     163x         163x                                    
import { defineCommand } from "just-search-it";
import { Download } from "lucide-react";
import { useLazyMssDownloadResultsRetrieveQuery } from "../../../api/apiStore.gen";
import { RegisterCommand } from "../../../commands/CommandProvider";
import { useProjectId } from "../../../hooks/project";
import { useSearchParam } from "../../../hooks/searchParams";
 
export const ExportMSSResults = defineCommand<[], void>("exportMSSResults");
 
export function ExportMSSRResultsCommand() {
  const [export_data] = useLazyMssDownloadResultsRetrieveQuery();
  const [scenario_id] = useSearchParam("scenario");
  const flowsheet_id = useProjectId();
 
  if (!flowsheet_id || !scenario_id) {
    return null;
  }
 
  const scenario_id_parsed = parseInt(scenario_id, 10);
  if (Number.isNaN(scenario_id_parsed)) {
    return null;
  }
 
  return (
    <RegisterCommand
      command={ExportMSSResults}
      args={[]}
      name="Export MSS Results"
      description="Download the results data for the current multi-steady-state scenario as a CSV file"
      group="Export"
      icon={<Download />}
      action={async () => {
        Iif (!flowsheet_id || !scenario_id) return;
        export_data({
          flowsheet: flowsheet_id,
          scenario: scenario_id_parsed,
        });
      }}
    />
  );
}