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
29 changes: 0 additions & 29 deletions apps/jobs/src/expired-env-checker/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/jobs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import { z } from "zod";

import { logger } from "@ctrlplane/logger";

import { run as expiredEnvChecker } from "./expired-env-checker/index.js";
import { run as jobPolicyChecker } from "./policy-checker/index.js";
import { run as timeoutChecker } from "./timeout-checker/index.js";

const jobs: Record<string, { run: () => Promise<void>; schedule: string }> = {
"policy-checker": { run: jobPolicyChecker, schedule: "* * * * *" },
"expired-env-checker": { run: expiredEnvChecker, schedule: "* * * * *" },
"timeout-checker": { run: timeoutChecker, schedule: "* * * * *" },
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
import type * as SCHEMA from "@ctrlplane/db/schema";
import { IconX } from "@tabler/icons-react";
import { z } from "zod";

import { Button } from "@ctrlplane/ui/button";
import { DateTimePicker } from "@ctrlplane/ui/datetime-picker";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
useForm,
} from "@ctrlplane/ui/form";
import { Input } from "@ctrlplane/ui/input";
import { Textarea } from "@ctrlplane/ui/textarea";

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

const schema = z.object({
name: z.string().min(1).max(100),
description: z.string().max(1000).nullable(),
expiresAt: z
.date()
.min(new Date(), "Expires at must be in the future")
.optional(),
});

type OverviewProps = {
environment: SCHEMA.Environment;
};
const name = z.string().min(1).max(100);
const description = z.string().max(1000).nullable();
const schema = z.object({ name, description });
type OverviewProps = { environment: SCHEMA.Environment };

export const Overview: React.FC<OverviewProps> = ({ environment }) => {
const expiresAt = environment.expiresAt ?? undefined;
const defaultValues = { ...environment, expiresAt };
const defaultValues = { ...environment };
const form = useForm({ schema, defaultValues });
const update = api.environment.update.useMutation();
const envOverride = api.job.trigger.create.byEnvId.useMutation();
Expand Down Expand Up @@ -80,34 +68,6 @@ export const Overview: React.FC<OverviewProps> = ({ environment }) => {
</FormItem>
)}
/>
<FormField
control={form.control}
name="expiresAt"
render={({ field: { value, onChange } }) => (
<FormItem>
<FormLabel>Expires at</FormLabel>
<FormControl>
<div className="flex items-center gap-2">
<DateTimePicker
value={value}
onChange={onChange}
granularity="minute"
className="w-60"
/>
<Button
variant="ghost"
size="icon"
type="button"
onClick={() => onChange(undefined)}
>
<IconX className="h-4 w-4" />
</Button>
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>

<div className="flex items-center gap-2">
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { RouterOutputs } from "@ctrlplane/api";
import type * as schema from "@ctrlplane/db/schema";
import type { ReleaseStatusType } from "@ctrlplane/validators/releases";
import type { ResourceCondition } from "@ctrlplane/validators/resources";
import { useState } from "react";
import { useParams, useRouter } from "next/navigation";
import {
IconCircleFilled,
Expand All @@ -21,9 +20,7 @@ import { isPresent } from "ts-is-present";
import { cn } from "@ctrlplane/ui";
import { Badge } from "@ctrlplane/ui/badge";
import { Button } from "@ctrlplane/ui/button";
import { Label } from "@ctrlplane/ui/label";
import { Skeleton } from "@ctrlplane/ui/skeleton";
import { Switch } from "@ctrlplane/ui/switch";
import {
Table,
TableBody,
Expand Down Expand Up @@ -155,13 +152,13 @@ export const DeploymentPageContent: React.FC<DeploymentPageContentProps> = ({
const loading = releases.isLoading;
const router = useRouter();

const [showEphemeralEnvs, setShowEphemeralEnvs] = useState(false);
// const [showEphemeralEnvs, setShowEphemeralEnvs] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove commented out code.

Instead of keeping commented out code, remove it entirely since we're removing the expired environments feature.

-  // const [showEphemeralEnvs, setShowEphemeralEnvs] = useState(false);


const selectedEnvironments = showEphemeralEnvs
? environments
: environments.filter((e) => e.expiresAt == null);
// const selectedEnvironments = showEphemeralEnvs
// ? environments
// : environments.filter((e) => e.expiresAt == null);
Comment on lines +157 to +159
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove commented out environment filtering logic.

Remove the commented out filtering logic as it's no longer needed with the removal of expired environments feature.

-  // const selectedEnvironments = showEphemeralEnvs
-  //   ? environments
-  //   : environments.filter((e) => e.expiresAt == null);


const numEnvironmentBlocks = Math.min(3, selectedEnvironments.length);
const numEnvironmentBlocks = Math.min(3, environments.length);

return (
<div>
Expand Down Expand Up @@ -202,7 +199,7 @@ export const DeploymentPageContent: React.FC<DeploymentPageContentProps> = ({
)}
</div>

<div className="flex items-center gap-2">
{/* <div className="flex items-center gap-2">
<Switch
checked={showEphemeralEnvs}
id="show-ephemeral-envs"
Expand All @@ -214,7 +211,7 @@ export const DeploymentPageContent: React.FC<DeploymentPageContentProps> = ({
>
Show ephemeral environments
</Label>
</div>
</div> */}

<div className="flex items-center gap-2 rounded-lg border border-neutral-800/50 px-2 py-1 text-sm text-muted-foreground">
Total:
Expand Down Expand Up @@ -271,7 +268,7 @@ export const DeploymentPageContent: React.FC<DeploymentPageContentProps> = ({
Version
</div>
</TableHead>
{selectedEnvironments.map((env) => (
{environments.map((env) => (
<EnvHeader
key={env.id}
environment={env}
Expand Down Expand Up @@ -336,7 +333,7 @@ export const DeploymentPageContent: React.FC<DeploymentPageContentProps> = ({
</Badge>
</div>
</TableCell>
{selectedEnvironments.map((env) => (
{environments.map((env) => (
<TableCell
className={cn(
"h-[60px] w-[220px] border-l",
Expand Down
7 changes: 1 addition & 6 deletions apps/webservice/src/app/api/v1/environments/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ export const POST = request()
try {
const environment = await ctx.db
.insert(schema.environment)
.values({
...ctx.body,
expiresAt: isPresent(ctx.body.expiresAt)
? new Date(ctx.body.expiresAt)
: undefined,
})
.values({ ...ctx.body })
.returning()
.then(takeFirst);

Expand Down
1 change: 1 addition & 0 deletions packages/db/drizzle/0063_mute_william_stryker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "environment" DROP COLUMN IF EXISTS "expires_at";
Loading
Loading