All files / web/src/components/agents/skills/clusters reset-cluster-dialog.tsx

0% Statements 0/71
100% Branches 1/1
100% Functions 1/1
0% Lines 0/71

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                                                                                                                                                                                                           
'use client';
 
import type { SkillOptimizationCluster } from '@shared/types/data';
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
} from '@web/components/ui/alert-dialog';
import { Checkbox } from '@web/components/ui/checkbox';
import { Label } from '@web/components/ui/label';
import type { ReactElement } from 'react';
import { useId, useState } from 'react';
 
interface ResetClusterDialogProps {
  cluster: SkillOptimizationCluster | null;
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onConfirm: (clearObservabilityCount: boolean) => void | Promise<void>;
  isResetting?: boolean;
}
 
export function ResetClusterDialog({
  cluster,
  open,
  onOpenChange,
  onConfirm,
  isResetting = false,
}: ResetClusterDialogProps): ReactElement {
  const [clearObservabilityCount, setClearObservabilityCount] = useState(false);
  const checkboxId = useId();
 
  const handleConfirm = async () => {
    await onConfirm(clearObservabilityCount);
    onOpenChange(false);
    setClearObservabilityCount(false); // Reset checkbox for next time
  };
 
  return (
    <AlertDialog open={open} onOpenChange={onOpenChange}>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Reset Partition</AlertDialogTitle>
          <AlertDialogDescription asChild>
            <div className="space-y-3">
              <p>
                Are you sure you want to reset partition{' '}
                <span className="font-semibold text-foreground">
                  {cluster?.name}
                </span>
                ?
              </p>
              <p className="font-medium text-foreground">This will:</p>
              <ul className="list-disc pl-5 space-y-1 text-sm">
                <li>Delete all configurations</li>
                <li>Reset learning progress</li>
                <li>
                  {clearObservabilityCount
                    ? 'Reset observability request count'
                    : 'Keep observability request count'}
                </li>
              </ul>
              <div className="flex items-center space-x-2 pt-2">
                <Checkbox
                  id={checkboxId}
                  checked={clearObservabilityCount}
                  onCheckedChange={(checked) =>
                    setClearObservabilityCount(checked === true)
                  }
                />
                <Label
                  htmlFor={checkboxId}
                  className="text-sm font-normal cursor-pointer"
                >
                  Also reset observability request count
                </Label>
              </div>
              <p className="text-sm">
                The partition will be regenerated with fresh configurations.
              </p>
            </div>
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel disabled={isResetting}>Cancel</AlertDialogCancel>
          <AlertDialogAction
            onClick={handleConfirm}
            disabled={isResetting}
            variant={'destructive'}
          >
            {isResetting ? 'Resetting...' : 'Reset Partition'}
          </AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}