From de257830a3d870437386df7936c63f26c1c459e8 Mon Sep 17 00:00:00 2001
From: Aditya Choudhari <48932219+adityachoudhari26@users.noreply.github.com>
Date: Sat, 21 Dec 2024 14:02:05 -0500
Subject: [PATCH] fix: Remove unnecessary concurrency column and remove save
button for concurrency section (#270)
---
.../ApprovalAndGovernance.tsx | 10 +-
.../DeploymentControl.tsx | 168 +-
.../useInvalidatePolicy.ts | 14 +
.../environments/[environmentId]/openapi.ts | 6 +-
.../github-get-job-inputs/src/index.ts | 1 -
openapi.v1.json | 15 +-
.../drizzle/0047_square_william_stryker.sql | 3 +
packages/db/drizzle/meta/0047_snapshot.json | 4396 +++++++++++++++++
packages/db/drizzle/meta/_journal.json | 7 +
packages/db/src/schema/environment.ts | 6 +-
packages/job-dispatch/src/job-creation.ts | 2 +-
.../src/policies/concurrency-policy.ts | 4 +-
packages/node-sdk/src/schema.ts | 7 +-
13 files changed, 4502 insertions(+), 137 deletions(-)
create mode 100644 apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/useInvalidatePolicy.ts
create mode 100644 packages/db/drizzle/0047_square_william_stryker.sql
create mode 100644 packages/db/drizzle/meta/0047_snapshot.json
diff --git a/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx b/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx
index 9d096d6a3..7bb9ff132 100644
--- a/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx
+++ b/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx
@@ -13,18 +13,14 @@ import {
} from "@ctrlplane/ui/select";
import { api } from "~/trpc/react";
+import { useInvalidatePolicy } from "./useInvalidatePolicy";
export const ApprovalAndGovernance: React.FC<{
environmentPolicy: SCHEMA.EnvironmentPolicy;
}> = ({ environmentPolicy }) => {
const updatePolicy = api.environment.policy.update.useMutation();
- const utils = api.useUtils();
-
- const { id, systemId } = environmentPolicy;
- const invalidatePolicy = () => {
- utils.environment.policy.byId.invalidate(id);
- utils.environment.policy.bySystemId.invalidate(systemId);
- };
+ const invalidatePolicy = useInvalidatePolicy(environmentPolicy);
+ const { id } = environmentPolicy;
return (
diff --git a/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/DeploymentControl.tsx b/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/DeploymentControl.tsx
index a6387fa6e..0e2bd61f8 100644
--- a/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/DeploymentControl.tsx
+++ b/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/DeploymentControl.tsx
@@ -1,117 +1,91 @@
import type * as SCHEMA from "@ctrlplane/db/schema";
-import React from "react";
-import { z } from "zod";
+import React, { useState } from "react";
+import { useDebounce } from "react-use";
-import { Button } from "@ctrlplane/ui/button";
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- useForm,
-} from "@ctrlplane/ui/form";
import { Input } from "@ctrlplane/ui/input";
+import { Label } from "@ctrlplane/ui/label";
import { RadioGroup, RadioGroupItem } from "@ctrlplane/ui/radio-group";
+import { toast } from "@ctrlplane/ui/toast";
import { api } from "~/trpc/react";
-
-const schema = z.object({
- concurrencyType: z.enum(["all", "some"]),
- concurrencyLimit: z.number().min(1, "Must be a positive number"),
-});
+import { useInvalidatePolicy } from "./useInvalidatePolicy";
export const DeploymentControl: React.FC<{
environmentPolicy: SCHEMA.EnvironmentPolicy;
}> = ({ environmentPolicy }) => {
- const form = useForm({ schema, defaultValues: environmentPolicy });
+ const [concurrencyLimit, setConcurrencyLimit] = useState(
+ environmentPolicy.concurrencyLimit?.toString() ?? "",
+ );
const updatePolicy = api.environment.policy.update.useMutation();
- const utils = api.useUtils();
-
- const { id, systemId } = environmentPolicy;
- const onSubmit = form.handleSubmit((data) => {
- updatePolicy
- .mutateAsync({ id, data })
- .then(() => form.reset(data))
- .then(() => utils.environment.policy.byId.invalidate(id))
- .then(() => utils.environment.policy.bySystemId.invalidate(systemId));
- });
-
- const { concurrencyLimit } = form.watch();
+ const invalidatePolicy = useInvalidatePolicy(environmentPolicy);
+ const { id } = environmentPolicy;
+ useDebounce(
+ () => {
+ if (concurrencyLimit === "") return;
+ const limit = Number(concurrencyLimit);
+ if (Number.isNaN(limit)) return;
+ updatePolicy
+ .mutateAsync({ id, data: { concurrencyLimit: limit } })
+ .then(invalidatePolicy)
+ .catch((e) => toast.error(e.message));
+ },
+ 300,
+ [concurrencyLimit],
+ );
return (
-