diff --git a/apps/web/app/routes/ws/deployments/_components/plans/PlanDiffDialog.tsx b/apps/web/app/routes/ws/deployments/_components/plans/PlanDiffDialog.tsx index b3951f73f..dfc615e99 100644 --- a/apps/web/app/routes/ws/deployments/_components/plans/PlanDiffDialog.tsx +++ b/apps/web/app/routes/ws/deployments/_components/plans/PlanDiffDialog.tsx @@ -8,15 +8,15 @@ import { DialogContent, DialogHeader, DialogTitle, - DialogTrigger, } from "~/components/ui/dialog"; import { Tabs, TabsList, TabsTrigger } from "~/components/ui/tabs"; type PlanDiffDialogProps = { deploymentId: string; - resultId: string; + resultId: string | undefined; title: string; - children: React.ReactNode; + open: boolean; + onOpenChange: (open: boolean) => void; }; type DiffView = "split" | "unified"; @@ -25,20 +25,19 @@ export function PlanDiffDialog({ deploymentId, resultId, title, - children, + open, + onOpenChange, }: PlanDiffDialogProps) { - const [open, setOpen] = useState(false); const [view, setView] = useState("split"); const { theme } = useTheme(); const diffQuery = trpc.deployment.plans.resultDiff.useQuery( - { deploymentId, resultId }, - { enabled: open }, + { deploymentId, resultId: resultId ?? "" }, + { enabled: open && resultId != null }, ); return ( - - {children} + {title} diff --git a/apps/web/app/routes/ws/deployments/_hooks/usePlanResultParam.ts b/apps/web/app/routes/ws/deployments/_hooks/usePlanResultParam.ts new file mode 100644 index 000000000..57451b23c --- /dev/null +++ b/apps/web/app/routes/ws/deployments/_hooks/usePlanResultParam.ts @@ -0,0 +1,20 @@ +import { useSearchParams } from "react-router"; + +export function usePlanResultParam() { + const [searchParams, setSearchParams] = useSearchParams(); + const resultId = searchParams.get("resultId") ?? undefined; + + const openResult = (id: string) => { + const newParams = new URLSearchParams(searchParams); + newParams.set("resultId", id); + setSearchParams(newParams); + }; + + const closeResult = () => { + const newParams = new URLSearchParams(searchParams); + newParams.delete("resultId"); + setSearchParams(newParams); + }; + + return { resultId, openResult, closeResult }; +} diff --git a/apps/web/app/routes/ws/deployments/page.$deploymentId.plans.$planId.tsx b/apps/web/app/routes/ws/deployments/page.$deploymentId.plans.$planId.tsx index df9d90f55..621b5e0cb 100644 --- a/apps/web/app/routes/ws/deployments/page.$deploymentId.plans.$planId.tsx +++ b/apps/web/app/routes/ws/deployments/page.$deploymentId.plans.$planId.tsx @@ -26,6 +26,7 @@ import { useDeployment } from "./_components/DeploymentProvider"; import { DeploymentsNavbarTabs } from "./_components/DeploymentsNavbarTabs"; import { PlanDiffDialog } from "./_components/plans/PlanDiffDialog"; import { PlanStatusBadge } from "./_components/plans/PlanStatusBadge"; +import { usePlanResultParam } from "./_hooks/usePlanResultParam"; export function meta() { return [ @@ -36,12 +37,16 @@ export function meta() { type Result = RouterOutputs["deployment"]["plans"]["results"][number]; +function resultTitle(result: Result) { + return `${result.environment.name} · ${result.resource.name} · ${result.agent.name}`; +} + function ChangesCell({ result, - deploymentId, + onViewDiff, }: { result: Result; - deploymentId: string; + onViewDiff: (resultId: string) => void; }) { if (result.status === "computing") return ; @@ -58,19 +63,14 @@ function ChangesCell({ return Unsupported; if (result.hasChanges === true) return ( - onViewDiff(result.resultId)} > - - + View diff + ); if (result.hasChanges === false) return No changes; @@ -93,10 +93,10 @@ function ResultsTableHeader() { function ResultsTableRow({ result, - deploymentId, + onViewDiff, }: { result: Result; - deploymentId: string; + onViewDiff: (resultId: string) => void; }) { return ( @@ -107,7 +107,7 @@ function ResultsTableRow({ - + ); @@ -135,6 +135,7 @@ export default function DeploymentPlanDetail() { const { workspace } = useWorkspace(); const { deployment } = useDeployment(); const { planId } = useParams<{ planId: string }>(); + const { resultId, openResult, closeResult } = usePlanResultParam(); const resultsQuery = trpc.deployment.plans.results.useQuery( { deploymentId: deployment.id, planId: planId! }, @@ -142,6 +143,7 @@ export default function DeploymentPlanDetail() { ); const results = resultsQuery.data ?? []; + const activeResult = results.find((r) => r.resultId === resultId); return ( <> @@ -192,12 +194,22 @@ export default function DeploymentPlanDetail() { ))} )} + + { + if (!o) closeResult(); + }} + /> ); }