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

63.63% Statements 14/22
50% Branches 7/14
100% Functions 1/1
64.7% Lines 11/17

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              76x   7930x 7930x 7930x 7930x   7579x       351x           26x   351x       351x               455x      
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,
        });
      }}
    />
  );
}