Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Oct 22, 2024
1 parent 5521078 commit 4c7d63f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Button, buttonVariants } from "@ctrlplane/ui/button";
import { Drawer, DrawerContent, DrawerTitle } from "@ctrlplane/ui/drawer";
import { ReservedMetadataKey } from "@ctrlplane/validators/targets";

import { TargetDropdownMenu } from "~/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/TargetDropdownMenu";
import { JobDropdownMenu } from "~/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/JobDropdownMenu";
import { api } from "~/trpc/react";
import { JobAgent } from "./JobAgent";
import { JobMetadata } from "./JobMetadata";
Expand Down Expand Up @@ -51,7 +51,7 @@ export const JobDrawer: React.FC = () => {
</div>
Job
{job != null && (
<TargetDropdownMenu
<JobDropdownMenu
release={job.release}
environmentId={job.environment.id}
target={job.target}
Expand All @@ -61,7 +61,7 @@ export const JobDrawer: React.FC = () => {
<Button variant="ghost" size="icon" className="h-6 w-6">
<IconDotsVertical className="h-3 w-3" />
</Button>
</TargetDropdownMenu>
</JobDropdownMenu>
)}
</div>
{links != null && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const JobPropertiesTable: React.FC<JobPropertiesTableProps> = ({
<td className="w-[110px] p-1 pr-2 text-muted-foreground">
Environment
</td>
<td>{capitalCase(job.environment.name)}</td>
<td>{job.environment.name}</td>
</tr>
<tr>
<td className="w-[110px] p-1 pr-2 text-muted-foreground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
} from "@ctrlplane/ui/tooltip";
import { activeStatus, JobStatus } from "@ctrlplane/validators/jobs";

import { useJobDrawer } from "~/app/[workspaceSlug]/_components/job-drawer/useJobDrawer";
import { api } from "~/trpc/react";

const overrideJobStatusFormSchema = z.object({
Expand All @@ -77,9 +78,7 @@ const OverrideJobStatusDialog: React.FC<{

const form = useForm({
schema: overrideJobStatusFormSchema,
defaultValues: {
status: JobStatus.Completed,
},
defaultValues: { status: job.status },
});

const onSubmit = form.handleSubmit((data) =>
Expand All @@ -89,6 +88,7 @@ const OverrideJobStatusDialog: React.FC<{
data,
})
.then(() => utils.job.config.byReleaseId.invalidate())
.then(() => utils.job.config.byId.invalidate(job.id))
.then(() => setOpen(false))
.then(() => onClose()),
);
Expand Down Expand Up @@ -125,13 +125,11 @@ const OverrideJobStatusDialog: React.FC<{
</SelectTrigger>
<SelectContent>
<SelectGroup>
{Object.values(JobStatus)
.filter((status) => status !== job.status)
.map((status) => (
<SelectItem key={status} value={status}>
{capitalCase(status)}
</SelectItem>
))}
{Object.values(JobStatus).map((status) => (
<SelectItem key={status} value={status}>
{capitalCase(status)}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</SelectGroup>
Expand All @@ -155,6 +153,7 @@ const OverrideJobStatusDialog: React.FC<{
<Button
type="submit"
className={buttonVariants({ variant: "destructive" })}
disabled={updateJob.isPending}
>
Override
</Button>
Expand Down Expand Up @@ -184,6 +183,7 @@ const ForceReleaseTargetDialog: React.FC<{
const forceRelease = api.release.deploy.toTarget.useMutation();
const router = useRouter();
const [open, setOpen] = useState(false);
const { setJobId } = useJobDrawer();

return (
<AlertDialog open={open} onOpenChange={setOpen}>
Expand Down Expand Up @@ -217,11 +217,10 @@ const ForceReleaseTargetDialog: React.FC<{
environmentId: environmentId,
isForcedRelease: true,
})
.then(() => {
router.refresh();
setOpen(false);
onClose();
})
.then((rjt) => setJobId(rjt.jobId))
.then(() => router.refresh())
.then(() => setOpen(false))
.then(() => onClose())
}
>
Force Release
Expand All @@ -241,6 +240,7 @@ const RedeployReleaseDialog: React.FC<{
const router = useRouter();
const redeploy = api.release.deploy.toTarget.useMutation();
const [isOpen, setIsOpen] = useState(false);
const { setJobId } = useJobDrawer();
return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>{children}</DialogTrigger>
Expand Down Expand Up @@ -268,8 +268,8 @@ const RedeployReleaseDialog: React.FC<{
targetId: target.id,
releaseId: release.id,
})
.then((rjt) => setJobId(rjt.jobId))
.then(() => router.refresh())
.then(() => setIsOpen(false))
}
>
Redeploy
Expand All @@ -280,7 +280,7 @@ const RedeployReleaseDialog: React.FC<{
);
};

export const TargetDropdownMenu: React.FC<{
export const JobDropdownMenu: React.FC<{
release: { id: string; version: string; name: string };
environmentId: string;
target: { id: string; name: string; lockedAt: Date | null } | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ReservedMetadataKey } from "@ctrlplane/validators/targets";
import { useJobDrawer } from "~/app/[workspaceSlug]/_components/job-drawer/useJobDrawer";
import { JobTableStatusIcon } from "~/app/[workspaceSlug]/_components/JobTableStatusIcon";
import { api } from "~/trpc/react";
import { TargetDropdownMenu } from "./TargetDropdownMenu";
import { JobDropdownMenu } from "./JobDropdownMenu";

type TargetReleaseTableProps = {
release: { id: string; version: string; name: string };
Expand Down Expand Up @@ -128,7 +128,7 @@ export const TargetReleaseTable: React.FC<TargetReleaseTableProps> = ({
</TableCell>
<TableCell>
<div className="flex justify-end">
<TargetDropdownMenu
<JobDropdownMenu
release={release}
deploymentName={deploymentName}
target={job.target}
Expand All @@ -141,7 +141,7 @@ export const TargetReleaseTable: React.FC<TargetReleaseTableProps> = ({
<Button variant="ghost" size="icon">
<IconDots size={16} />
</Button>
</TargetDropdownMenu>
</JobDropdownMenu>
</div>
</TableCell>
</TableRow>
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/router/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ export const releaseRouter = createTRPCRouter({
)
.then(cancelOldReleaseJobTriggersOnJobDispatch)
.dispatch();

return releaseJobTriggers[0]!;
}),
}),

Expand Down

0 comments on commit 4c7d63f

Please sign in to comment.