Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -25,20 +25,19 @@ export function PlanDiffDialog({
deploymentId,
resultId,
title,
children,
open,
onOpenChange,
}: PlanDiffDialogProps) {
const [open, setOpen] = useState(false);
const [view, setView] = useState<DiffView>("split");
const { theme } = useTheme();

const diffQuery = trpc.deployment.plans.resultDiff.useQuery(
{ deploymentId, resultId },
{ enabled: open },
{ deploymentId, resultId: resultId ?? "" },
{ enabled: open && resultId != null },
Comment on lines 34 to +36
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabled: open && resultId != null will still run the query when resultId is an empty string (e.g. URL ?resultId=). That will call the API with resultId: "" due to resultId ?? "". Tighten the guard to require a non-empty id (e.g. !!resultId) and avoid passing a placeholder empty string as the query input.

Copilot uses AI. Check for mistakes.
);

return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>{children}</DialogTrigger>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="flex h-[90vh] w-[95vw] max-w-[95vw] flex-col p-0 sm:max-w-[95vw]">
<DialogHeader className="flex-row items-center justify-between border-b p-4 pr-12">
<DialogTitle>{title}</DialogTitle>
Expand Down
20 changes: 20 additions & 0 deletions apps/web/app/routes/ws/deployments/_hooks/usePlanResultParam.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Comment on lines +5 to +7
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searchParams.get("resultId") can return an empty string when the URL contains ?resultId=. In that case resultId becomes "" (not undefined), which will cause the diff dialog to open and attempt to fetch a diff for an invalid id. Consider normalizing empty strings to undefined (e.g., treat "" as absent) and optionally guarding openResult against being called with an empty id.

Suggested change
const resultId = searchParams.get("resultId") ?? undefined;
const openResult = (id: string) => {
const resultId = searchParams.get("resultId") || undefined;
const openResult = (id: string) => {
if (!id) {
return;
}

Copilot uses AI. Check for mistakes.
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 };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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 <span className="text-muted-foreground">—</span>;
Expand All @@ -58,19 +63,14 @@ function ChangesCell({
return <span className="text-muted-foreground">Unsupported</span>;
if (result.hasChanges === true)
return (
<PlanDiffDialog
deploymentId={deploymentId}
resultId={result.resultId}
title={`${result.environment.name} · ${result.resource.name} · ${result.agent.name}`}
<Button
variant="outline"
size="sm"
className="h-6 cursor-pointer hover:bg-accent hover:text-accent-foreground"
onClick={() => onViewDiff(result.resultId)}
>
<Button
variant="outline"
size="sm"
className="h-6 cursor-pointer hover:bg-accent hover:text-accent-foreground"
>
View diff
</Button>
</PlanDiffDialog>
View diff
</Button>
);
if (result.hasChanges === false)
return <span className="text-muted-foreground">No changes</span>;
Expand All @@ -93,10 +93,10 @@ function ResultsTableHeader() {

function ResultsTableRow({
result,
deploymentId,
onViewDiff,
}: {
result: Result;
deploymentId: string;
onViewDiff: (resultId: string) => void;
}) {
return (
<TableRow className="hover:bg-muted/50">
Expand All @@ -107,7 +107,7 @@ function ResultsTableRow({
<PlanStatusBadge status={result.status} />
</TableCell>
<TableCell>
<ChangesCell result={result} deploymentId={deploymentId} />
<ChangesCell result={result} onViewDiff={onViewDiff} />
</TableCell>
</TableRow>
);
Expand Down Expand Up @@ -135,13 +135,15 @@ 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! },
{ enabled: !!planId, refetchInterval: 5000 },
);

const results = resultsQuery.data ?? [];
const activeResult = results.find((r) => r.resultId === resultId);

return (
<>
Expand Down Expand Up @@ -192,12 +194,22 @@ export default function DeploymentPlanDetail() {
<ResultsTableRow
key={r.resultId}
result={r}
deploymentId={deployment.id}
onViewDiff={openResult}
/>
))}
</TableBody>
</Table>
)}

<PlanDiffDialog
deploymentId={deployment.id}
resultId={resultId}
title={activeResult ? resultTitle(activeResult) : ""}
open={resultId != null}
Comment on lines +206 to +208
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dialog title can be an empty string when resultId is present in the URL but activeResult hasn’t loaded yet (or the id is invalid). This leaves the dialog without an accessible title and can create a confusing blank header. Consider providing a non-empty fallback title (e.g. "Plan diff"/"Loading…") and/or closing the dialog when resultId doesn’t match any loaded result.

Copilot uses AI. Check for mistakes.
onOpenChange={(o) => {
if (!o) closeResult();
}}
/>
</>
);
}
Loading