Skip to content

Commit

Permalink
fix: Remove unnecessary concurrency column and remove save button for…
Browse files Browse the repository at this point in the history
… concurrency section (#270)
  • Loading branch information
adityachoudhari26 authored Dec 21, 2024
1 parent be3b6ad commit de25783
Show file tree
Hide file tree
Showing 13 changed files with 4,502 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="space-y-10 p-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<Form {...form}>
<form onSubmit={onSubmit} className="space-y-10 p-2">
<div className="space-y-10 p-2">
<div className="flex flex-col gap-1">
<h1 className="text-lg font-medium">Deployment Control</h1>
<span className="text-sm text-muted-foreground">
Deployment control policies focus on regulating how deployments are
executed within an environment. These policies manage concurrency,
filtering of releases, and other operational constraints, ensuring
efficient and orderly deployment processes without overwhelming
resources or violating environment-specific rules.
</span>
</div>
<div className="space-y-4">
<div className="flex flex-col gap-1">
<h1 className="text-lg font-medium">Deployment Control</h1>
<span className="text-sm text-muted-foreground">
Deployment control policies focus on regulating how deployments are
executed within an environment. These policies manage concurrency,
filtering of releases, and other operational constraints, ensuring
efficient and orderly deployment processes without overwhelming
resources or violating environment-specific rules.
</span>
<Label>Concurrency</Label>
<div className="text-sm text-muted-foreground">
The number of jobs that can run concurrently in an environment.
</div>
</div>
<FormField
control={form.control}
name="concurrencyType"
render={({ field: { value, onChange } }) => (
<FormItem>
<div className="space-y-4">
<div className="flex flex-col gap-1">
<FormLabel>Concurrency</FormLabel>
<FormDescription>
The number of jobs that can run concurrently in an
environment.
</FormDescription>
</div>
<FormControl>
<RadioGroup value={value} onValueChange={onChange}>
<FormItem className="flex items-center space-x-3 space-y-0">
<FormControl>
<RadioGroupItem value="all" />
</FormControl>
<FormLabel className="flex items-center gap-2 font-normal">
All jobs can run concurrently
</FormLabel>
</FormItem>
<FormItem className="flex items-center space-x-3 space-y-0">
<FormControl>
<RadioGroupItem value="some" className="min-w-4" />
</FormControl>
<FormLabel className="flex flex-wrap items-center gap-2 font-normal">
A maximum of
<Input
disabled={value !== "some"}
type="number"
value={concurrencyLimit}
onChange={(e) =>
form.setValue(
"concurrencyLimit",
e.target.valueAsNumber,
)
}
className="border-b-1 h-6 w-16 text-xs"
/>
jobs can run concurrently
</FormLabel>
</FormItem>
</RadioGroup>
</FormControl>
</div>
</FormItem>
)}
/>

<Button
type="submit"
disabled={form.formState.isSubmitting || !form.formState.isDirty}
<RadioGroup
value={environmentPolicy.concurrencyLimit != null ? "some" : "all"}
onValueChange={(value) => {
const concurrencyLimit = value === "some" ? 1 : null;
setConcurrencyLimit(String(concurrencyLimit ?? ""));
updatePolicy
.mutateAsync({ id, data: { concurrencyLimit } })
.then(invalidatePolicy);
}}
>
Save
</Button>
</form>
</Form>
<div className="flex items-center space-x-3 space-y-0">
<RadioGroupItem value="all" />
<Label className="flex items-center gap-2 font-normal">
All jobs can run concurrently
</Label>
</div>
<div className="flex items-center space-x-3 space-y-0">
<RadioGroupItem value="some" className="min-w-4" />
<Label className="flex flex-wrap items-center gap-2 font-normal">
A maximum of
<Input
disabled={environmentPolicy.concurrencyLimit == null}
type="number"
value={concurrencyLimit}
onChange={(e) => setConcurrencyLimit(e.target.value)}
className="border-b-1 h-6 w-16 text-xs"
/>
jobs can run concurrently
</Label>
</div>
</RadioGroup>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type * as SCHEMA from "@ctrlplane/db/schema";

import { api } from "~/trpc/react";

export const useInvalidatePolicy = (
environmentPolicy: SCHEMA.EnvironmentPolicy,
) => {
const utils = api.useUtils();
const { id, systemId } = environmentPolicy;
return () => {
utils.environment.policy.byId.invalidate(id);
utils.environment.policy.bySystemId.invalidate(systemId);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ export const openapi: Swagger.SwaggerV3 = {
enum: ["some", "all", "optional"],
},
successMinimum: { type: "number" },
concurrencyType: {
type: "string",
enum: ["some", "all"],
},
concurrencyLimit: { type: "number" },
concurrencyLimit: { type: "number", nullable: true },
rolloutDuration: { type: "number" },
releaseSequencing: {
type: "string",
Expand Down
1 change: 0 additions & 1 deletion integrations/github-get-job-inputs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ async function run() {
setOutputAndLog("release_id", release?.id);
setOutputAndLog("release_version", release?.version);
setOutputsRecursively("release_config", release?.config);
setOutputsRecursively("release_metadata", release?.metadata);

if (approval?.approver != null) {
setOutputAndLog("approval_approver_id", approval.approver.id);
Expand Down
15 changes: 2 additions & 13 deletions openapi.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,9 @@
"successMinimum": {
"type": "number"
},
"concurrencyType": {
"type": "string",
"enum": [
"some",
"all"
]
},
"concurrencyLimit": {
"type": "number"
"type": "number",
"nullable": true
},
"rolloutDuration": {
"type": "number"
Expand Down Expand Up @@ -2355,10 +2349,6 @@
"type": "object",
"additionalProperties": true
},
"metadata": {
"type": "object",
"additionalProperties": { "type": "string" }
},
"deploymentId": {
"type": "string",
"format": "uuid"
Expand All @@ -2373,7 +2363,6 @@
"name",
"version",
"config",
"metadata",
"deploymentId",
"createdAt"
]
Expand Down
3 changes: 3 additions & 0 deletions packages/db/drizzle/0047_square_william_stryker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "environment_policy" ALTER COLUMN "concurrency_limit" SET DEFAULT NULL;--> statement-breakpoint
ALTER TABLE "environment_policy" ALTER COLUMN "concurrency_limit" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "environment_policy" DROP COLUMN IF EXISTS "concurrency_type";
Loading

0 comments on commit de25783

Please sign in to comment.