All files / src/pages/flowsheet-page/flowsheet/revisions FlowsheetRevisionDialogs.tsx

86.95% Statements 40/46
50% Branches 28/56
100% Functions 2/2
89.74% Lines 35/39

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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125                                                              141x             141x 141x     203x     30x           141x   31x           203x 141x 141x 564x   423x 564x         110x                     110x 110x         550x   110x 110x     158x     24x 110x   24x 134x   134x 110x 24x           158x 110x         110x 440x 330x 330x 440x 330x      
import { Button } from "@/ahuora-design-system/ui/button";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/ahuora-design-system/ui/dialog";
import { FlowsheetRevisionRead } from "@/api/apiStore.gen.ts";
import { getFlowsheetVersionLabel } from "./versionLabels";
 
type FlowsheetRevisionDialogsProps = {
  restoreTarget: FlowsheetRevisionRead | null;
  deleteTarget: FlowsheetRevisionRead | null;
  restorePending: boolean;
  deletePending: boolean;
  onDismissRestore: () => void;
  onConfirmRestore: () => void;
  onDismissDelete: () => void;
  onConfirmDelete: () => void;
};
 
type FlowsheetRevisionRestoreDialogProps = {
  restoreTarget: FlowsheetRevisionRead | null;
  restorePending: boolean;
  onDismissRestore: () => void;
  onConfirmRestore: () => void;
};
 
/** Confirm replacing Current with one immutable revision. */
export function FlowsheetRevisionRestoreDialog({
  restoreTarget,
  restorePending,
  onDismissRestore,
  onConfirmRestore,
}: FlowsheetRevisionRestoreDialogProps) {
  return (
    <Dialog
      open={restoreTarget !== null}
      onOpenChange={(open) => {
        Iif (!open && !restorePending) onDismissRestore();
      }}
    >
      <DialogContent className="w-[min(30rem,calc(100vw-2rem))]">
        <DialogHeader>
          <DialogTitle>Restore this version?</DialogTitle>
          <DialogDescription>
            Your current flowsheet will be replaced by this version. Scenario
            solutions and economics calculations will be cleared.
          </DialogDescription>
        </DialogHeader>
        <DialogFooter>
          <Button
            variant="outline"
            onClick={onDismissRestore}
            disabled={restorePending}
          >
            Cancel
          </Button>
          <Button onClick={onConfirmRestore} disabled={restorePending}>
            {restorePending ? "Restoring..." : "Restore"}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}
 
/** Destructive revision confirmations kept outside the inline accordion flow. */
export function FlowsheetRevisionDialogs({
  restoreTarget,
  deleteTarget,
  restorePending,
  deletePending,
  onDismissRestore,
  onConfirmRestore,
  onDismissDelete,
  onConfirmDelete,
}: FlowsheetRevisionDialogsProps) {
  return (
    <>
      <FlowsheetRevisionRestoreDialog
        restoreTarget={restoreTarget}
        restorePending={restorePending}
        onDismissRestore={onDismissRestore}
        onConfirmRestore={onConfirmRestore}
      />
 
      <Dialog
        open={deleteTarget !== null}
        onOpenChange={(open) => {
          Iif (!open && !deletePending) onDismissDelete();
        }}
      >
        <DialogContent className="w-[min(30rem,calc(100vw-2rem))]">
          <DialogHeader>
            <DialogTitle>Delete this version?</DialogTitle>
            <DialogDescription>
              {deleteTarget &&
                `${getFlowsheetVersionLabel(deleteTarget)} will be permanently deleted. This action cannot be undone.`}
            </DialogDescription>
          </DialogHeader>
          <DialogFooter>
            <Button
              variant="outline"
              onClick={onDismissDelete}
              disabled={deletePending}
            >
              Cancel
            </Button>
            <Button
              variant="delete"
              onClick={onConfirmDelete}
              disabled={deletePending}
            >
              {deletePending ? "Deleting..." : "Delete"}
            </Button>
          </DialogFooter>
        </DialogContent>
      </Dialog>
    </>
  );
}