import { useRef } from "react"; import type { UnsavedWork, WipChoice } from "../../lib/types"; import Modal from "../ui/Modal"; import Button from "../ui/Button"; export type StopGuardChoice = WipChoice | "unguarded" | null; interface Props { projectName: string; work: UnsavedWork; /** The project's "push work in progress when the workspace stops" setting. */ wipPushOnStop?: boolean; /** `null` = Cancel. `"unguarded"` = stop without recording any choice * (the unchecked case: the workspace's own shutdown push still runs). */ onChoose: (choice: StopGuardChoice) => void; } function describeRepo(dirty: boolean, unpushed: number): string { const parts: string[] = []; if (dirty) parts.push("uncommitted changes"); if (unpushed > 0) parts.push(`${unpushed} unpushed commit${unpushed === 1 ? "" : "s"}`); return parts.join(", "); } /** * Asked before an AWS workspace stops when its repositories hold work no * remote has, or when Triple-C could not check. Pushing to a WIP branch is * the default (it has focus); it is not offered when the check could not * run, since the push goes the same way the check did. */ export default function StopGuardModal({ projectName, work, wipPushOnStop = false, onChoose }: Props) { const pushRef = useRef(null); const stopRef = useRef(null); const atRisk = work.repos.filter((r) => !r.cloning && (r.dirty || r.unpushed > 0)); const cloning = work.repos.filter((r) => r.cloning); return ( onChoose(null)} widthClassName="w-[30rem]" initialFocusRef={work.checked ? pushRef : stopRef} footer={ <> {work.checked && ( )} } > {work.checked ? ( <>

Stopping {projectName} ends its workspace. These repositories have work that no remote has yet:

    {atRisk.map((r) => (
  • /workspace/{r.folder}{" "} ({r.branch}): {describeRepo(r.dirty, r.unpushed)}
  • ))} {cloning.map((r) => (
  • /workspace/{r.folder}{" "} still cloning — nothing to push
  • ))}

Push to WIP branch saves a snapshot of each repository to a{" "} triple-c/wip/… branch on its remote, without touching your branches. If the push fails, the workspace keeps running. Stop without pushing skips that push, including the one the workspace would make as it shuts down.

) : ( <>

Triple-C could not check{" "} {projectName} for unsaved work, so it can’t push it to a WIP branch first.

{work.error && (

{work.error}

)}

Uncommitted or unpushed work in the workspace may be lost if you stop it now. {wipPushOnStop && " The workspace's own push of work in progress still runs as it shuts down, if it can reach the remote."}

)}
); }