Skip to content

Commit fce18c1

Browse files
chore: clean up checks endpoints (ctrlplanedev#552)
1 parent b5475ea commit fce18c1

12 files changed

Lines changed: 93 additions & 463 deletions

File tree

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/Approval.tsx

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
import { Button } from "@ctrlplane/ui/button";
2-
import {
3-
Tooltip,
4-
TooltipContent,
5-
TooltipProvider,
6-
TooltipTrigger,
7-
} from "@ctrlplane/ui/tooltip";
82

93
import { ApprovalDialog } from "~/app/[workspaceSlug]/(app)/(deploy)/_components/deployment-version/ApprovalDialog";
104
import { api } from "~/trpc/react";
@@ -16,16 +10,24 @@ export const ApprovalCheck: React.FC<{
1610
versionId: string;
1711
versionTag: string;
1812
}> = (props) => {
19-
const { data, isLoading } =
20-
api.deployment.version.checks.approval.status.useQuery(props);
13+
const { data, isLoading } = api.policy.evaluate.useQuery(props);
2114
const utils = api.useUtils();
22-
const invalidate = () =>
23-
utils.deployment.version.checks.approval.status.invalidate(props);
15+
const invalidate = () => utils.policy.evaluate.invalidate(props);
2416

25-
const isApproved = data?.approved ?? false;
26-
const rejectionReasonEntries = Array.from(
27-
data?.rejectionReasons.entries() ?? [],
28-
);
17+
const isAnyApprovalSatisfied = Object.values(
18+
data?.rules.anyApprovals ?? {},
19+
).every((reasons) => reasons.length === 0);
20+
const isUserApprovalSatisfied = Object.values(
21+
data?.rules.userApprovals ?? {},
22+
).every((reasons) => reasons.length === 0);
23+
const isRoleApprovalSatisfied = Object.values(
24+
data?.rules.roleApprovals ?? {},
25+
).every((reasons) => reasons.length === 0);
26+
27+
const isApproved =
28+
isAnyApprovalSatisfied &&
29+
isUserApprovalSatisfied &&
30+
isRoleApprovalSatisfied;
2931

3032
if (isLoading)
3133
return (
@@ -41,35 +43,6 @@ export const ApprovalCheck: React.FC<{
4143
</div>
4244
);
4345

44-
if (rejectionReasonEntries.length > 0)
45-
return (
46-
<TooltipProvider>
47-
<Tooltip>
48-
<TooltipTrigger>
49-
<div className="flex items-center justify-between">
50-
<div className="flex items-center gap-2">
51-
<Waiting /> Not enough approvals
52-
</div>
53-
<ApprovalDialog {...props} onSubmit={invalidate}>
54-
<Button size="sm" className="h-6">
55-
Approve
56-
</Button>
57-
</ApprovalDialog>
58-
</div>
59-
</TooltipTrigger>
60-
<TooltipContent>
61-
<ul>
62-
{rejectionReasonEntries.map(([reason, comment]) => (
63-
<li key={reason}>
64-
{reason}: {comment}
65-
</li>
66-
))}
67-
</ul>
68-
</TooltipContent>
69-
</Tooltip>
70-
</TooltipProvider>
71-
);
72-
7346
return (
7447
<div className="flex items-center justify-between">
7548
<div className="flex items-center gap-2">

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/DenyWindow.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/checks/VersionSelector.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ export const VersionSelectorCheck: React.FC<{
55
versionId: string;
66
environmentId: string;
77
}> = ({ versionId, environmentId }) => {
8-
const { data, isLoading } =
9-
api.deployment.version.checks.versionSelector.useQuery({
10-
versionId,
11-
environmentId,
12-
});
8+
const { data, isLoading } = api.policy.evaluate.useQuery({
9+
environmentId,
10+
versionId,
11+
});
1312

14-
const isPassingVersionSelector = data ?? false;
13+
const isPassingVersionSelector = Object.values(
14+
data?.rules.versionSelector ?? {},
15+
).every((isPassing) => isPassing);
1516

1617
if (isLoading)
1718
return (

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/_components/flow-diagram/nodes/EnvironmentNode.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { cn } from "@ctrlplane/ui";
88
import { Separator } from "@ctrlplane/ui/separator";
99

1010
import { ApprovalCheck } from "../checks/Approval";
11-
import { DenyWindowCheck } from "../checks/DenyWindow";
1211
import { VersionSelectorCheck } from "../checks/VersionSelector";
1312

1413
type EnvironmentNodeProps = NodeProps<{
@@ -35,7 +34,6 @@ export const EnvironmentNode: React.FC<EnvironmentNodeProps> = ({ data }) => (
3534
<Separator className="!m-0 bg-neutral-800" />
3635
<div className="space-y-1 px-2 pb-2">
3736
<ApprovalCheck {...data} />
38-
<DenyWindowCheck {...data} />
3937
<VersionSelectorCheck {...data} />
4038
</div>
4139
</div>

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(raw)/releases/[releaseId]/checks/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata } from "next";
22
import { notFound } from "next/navigation";
33
import { IconMenu2 } from "@tabler/icons-react";
4+
import _ from "lodash";
45

56
import { SidebarTrigger } from "@ctrlplane/ui/sidebar";
67

@@ -44,9 +45,15 @@ export default async function ChecksPage(props: PageProps) {
4445
if (deploymentVersion == null || deployment == null) return notFound();
4546

4647
const { system } = deployment;
47-
const environments = await api.deployment.version.checks.environmentsToCheck(
48-
deployment.id,
48+
const releaseTargets = await api.releaseTarget.list({
49+
deploymentId: deployment.id,
50+
});
51+
52+
const environments = _.uniqBy(
53+
releaseTargets.map((r) => r.environment),
54+
(env) => env.id,
4955
);
56+
5057
return (
5158
<div className="relative h-full">
5259
<SidebarTrigger

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/_components/deployment-version/ApprovalDialog.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export const ApprovalDialog: React.FC<{
2626
onSubmit?: () => void;
2727
}> = ({ versionId, versionTag, environmentId, children, onSubmit }) => {
2828
const [open, setOpen] = useState(false);
29-
const addRecord =
30-
api.deployment.version.checks.approval.addRecord.useMutation();
29+
const addRecord = api.deployment.version.addApprovalRecord.useMutation();
3130

3231
const router = useRouter();
3332

packages/api/src/router/deployment-version-checks/approvals.ts

Lines changed: 0 additions & 126 deletions
This file was deleted.

packages/api/src/router/deployment-version-checks/deny-window.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)