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
71.42% Lines 10/14

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                    37x     66x 66x 66x                               4292x 4292x 4292x   4292x 4064x     228x                                  
import { Download } from "lucide-react";
import { Button } from "../../../ahuora-design-system/ui/button";
import { ToolTipCover } from "../../../ahuora-design-system/ui/tooltip";
import { useProjectId } from "../../../hooks/project";
import { useCurrentScenario } from "../flowsheet/LeftSideBar/Scenarios/useCurrentScenario";
import { useLazyCoreExpressionDownloadTagMappingsRetrieveQuery } from "../../../api/apiStore.gen";
import { useSearchParam } from "../../../hooks/searchParams";
import { RegisterCommand } from "../../../commands/CommandProvider";
import { defineCommand } from "just-search-it";
 
export const ExportMSSResults = defineCommand<[], void>("downloadTagMappings");
 
export function DownloadTagMappingsButton() {
    const scenario = useCurrentScenario();
    const [downloadFile] = useLazyCoreExpressionDownloadTagMappingsRetrieveQuery();
    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] = useLazyCoreExpressionDownloadTagMappingsRetrieveQuery();
    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
                })
            }}
        />
    );
}