-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Job drawer #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Job drawer #162
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type * as SCHEMA from "@ctrlplane/db/schema"; | ||
| import type { JobStatus } from "@ctrlplane/validators/jobs"; | ||
|
|
||
| export type Job = SCHEMA.ReleaseJobTrigger & { | ||
| job: Omit<SCHEMA.Job, "status"> & { | ||
| metadata: SCHEMA.JobMetadata[]; | ||
| status: JobStatus; | ||
| }; | ||
| jobAgent: SCHEMA.JobAgent; | ||
| target: SCHEMA.Target; | ||
| release: SCHEMA.Release & { deployment: SCHEMA.Deployment }; | ||
| environment: SCHEMA.Environment; | ||
| rolloutDate: Date | null; | ||
| causedBy?: SCHEMA.User | null; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import * as yaml from "js-yaml"; | ||
|
|
||
| import type { Job } from "./Job"; | ||
| import { ConfigEditor } from "../ConfigEditor"; | ||
|
|
||
| type JobAgentProps = { | ||
| job: Job; | ||
| }; | ||
|
|
||
| export const JobAgent: React.FC<JobAgentProps> = ({ job }) => ( | ||
| <div className="space-y-2"> | ||
| <div className="text-sm">Agent</div> | ||
| <table width="100%" className="table-fixed text-xs"> | ||
| <tbody> | ||
| <tr> | ||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground">Name</td> | ||
| <td>{job.jobAgent.name}</td> | ||
adityachoudhari26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </tr> | ||
| <tr> | ||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground">Type</td> | ||
| <td>{job.jobAgent.type}</td> | ||
| </tr> | ||
| <tr> | ||
| <td className="w-[110px] p-1 pr-2 align-top text-muted-foreground"> | ||
| Job Config | ||
| </td> | ||
| <td /> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| <div className="scrollbar-none max-h-[250px] overflow-auto"> | ||
| <ConfigEditor value={yaml.dump(job.job.jobAgentConfig)} readOnly /> | ||
adityachoudhari26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
|
Comment on lines
+31
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding loading states and error boundaries. The scrollable container for the config editor should handle loading and error states gracefully. Consider implementing error boundaries and loading states: - <div className="scrollbar-none max-h-[250px] overflow-auto">
+ <div
+ className="scrollbar-none max-h-[250px] overflow-auto relative"
+ role="region"
+ aria-label="Job Configuration"
+ >
+ {job.job.jobAgentConfig ? (
<ConfigEditor
value={/* ... */}
readOnly
/>
+ ) : (
+ <div className="p-2 text-sm text-muted-foreground">
+ No configuration available
+ </div>
+ )}
</div>
|
||
| </div> | ||
| ); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,110 @@ | ||||||||||||||||||
| "use client"; | ||||||||||||||||||
|
|
||||||||||||||||||
| import type React from "react"; | ||||||||||||||||||
| import Link from "next/link"; | ||||||||||||||||||
| import { | ||||||||||||||||||
| IconDotsVertical, | ||||||||||||||||||
| IconExternalLink, | ||||||||||||||||||
| IconLoader2, | ||||||||||||||||||
| IconRocket, | ||||||||||||||||||
| } from "@tabler/icons-react"; | ||||||||||||||||||
|
|
||||||||||||||||||
| import { Button, buttonVariants } from "@ctrlplane/ui/button"; | ||||||||||||||||||
| import { Drawer, DrawerContent, DrawerTitle } from "@ctrlplane/ui/drawer"; | ||||||||||||||||||
| import { ReservedMetadataKey } from "@ctrlplane/validators/targets"; | ||||||||||||||||||
|
|
||||||||||||||||||
| 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"; | ||||||||||||||||||
| import { JobPropertiesTable } from "./JobProperties"; | ||||||||||||||||||
| import { useJobDrawer } from "./useJobDrawer"; | ||||||||||||||||||
|
|
||||||||||||||||||
| export const JobDrawer: React.FC = () => { | ||||||||||||||||||
| const { jobId, removeJobId } = useJobDrawer(); | ||||||||||||||||||
| const isOpen = jobId != null && jobId != ""; | ||||||||||||||||||
| const setIsOpen = removeJobId; | ||||||||||||||||||
|
|
||||||||||||||||||
| const jobQ = api.job.config.byId.useQuery(jobId ?? "", { | ||||||||||||||||||
| enabled: isOpen, | ||||||||||||||||||
| refetchInterval: 10_000, | ||||||||||||||||||
| }); | ||||||||||||||||||
adityachoudhari26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| const job = jobQ.data; | ||||||||||||||||||
| const linksMetadata = job?.job.metadata.find( | ||||||||||||||||||
| (m) => m.key === String(ReservedMetadataKey.Links), | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| const links = | ||||||||||||||||||
| linksMetadata != null | ||||||||||||||||||
| ? (JSON.parse(linksMetadata.value) as Record<string, string>) | ||||||||||||||||||
| : null; | ||||||||||||||||||
adityachoudhari26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <Drawer open={isOpen} onOpenChange={setIsOpen}> | ||||||||||||||||||
| <DrawerContent | ||||||||||||||||||
| showBar={false} | ||||||||||||||||||
| className="left-auto right-0 top-0 mt-0 h-screen w-1/3 overflow-auto rounded-none focus-visible:outline-none" | ||||||||||||||||||
| > | ||||||||||||||||||
|
Comment on lines
+44
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using responsive width classes. The hardcoded width of 1/3 might not provide the best experience across different screen sizes. -className="left-auto right-0 top-0 mt-0 h-screen w-1/3 overflow-auto rounded-none focus-visible:outline-none"
+className="left-auto right-0 top-0 mt-0 h-screen w-full md:w-1/2 lg:w-1/3 overflow-auto rounded-none focus-visible:outline-none"📝 Committable suggestion
Suggested change
|
||||||||||||||||||
| {jobQ.isLoading && ( | ||||||||||||||||||
| <div className="flex h-full w-full items-center justify-center"> | ||||||||||||||||||
| <IconLoader2 className="h-8 w-8 animate-spin" /> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| )} | ||||||||||||||||||
| {!jobQ.isLoading && ( | ||||||||||||||||||
| <> | ||||||||||||||||||
| <DrawerTitle className="border-b p-6"> | ||||||||||||||||||
| <div className="flex items-center gap-2 "> | ||||||||||||||||||
| <div className="flex flex-shrink-0 items-center gap-2 rounded bg-blue-500/20 p-1 text-blue-400"> | ||||||||||||||||||
| <IconRocket className="h-4 w-4" /> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| Job | ||||||||||||||||||
| {job != null && ( | ||||||||||||||||||
| <JobDropdownMenu | ||||||||||||||||||
| release={job.release} | ||||||||||||||||||
| environmentId={job.environment.id} | ||||||||||||||||||
| target={job.target} | ||||||||||||||||||
| deploymentName={job.release.deployment.name} | ||||||||||||||||||
| job={job.job} | ||||||||||||||||||
| > | ||||||||||||||||||
| <Button variant="ghost" size="icon" className="h-6 w-6"> | ||||||||||||||||||
| <IconDotsVertical className="h-3 w-3" /> | ||||||||||||||||||
| </Button> | ||||||||||||||||||
| </JobDropdownMenu> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </div> | ||||||||||||||||||
| {links != null && ( | ||||||||||||||||||
| <div className="mt-3 flex flex-wrap gap-2"> | ||||||||||||||||||
| <> | ||||||||||||||||||
| {Object.entries(links).map(([label, url]) => ( | ||||||||||||||||||
| <Link | ||||||||||||||||||
| key={label} | ||||||||||||||||||
| href={url} | ||||||||||||||||||
| target="_blank" | ||||||||||||||||||
| rel="noopener noreferrer" | ||||||||||||||||||
| className={buttonVariants({ | ||||||||||||||||||
| variant: "secondary", | ||||||||||||||||||
| size: "sm", | ||||||||||||||||||
| className: "gap-1", | ||||||||||||||||||
| })} | ||||||||||||||||||
| > | ||||||||||||||||||
| <IconExternalLink className="h-4 w-4" /> | ||||||||||||||||||
| {label} | ||||||||||||||||||
| </Link> | ||||||||||||||||||
| ))} | ||||||||||||||||||
| </> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </DrawerTitle> | ||||||||||||||||||
| {job != null && ( | ||||||||||||||||||
| <div className="flex w-full flex-col gap-6 p-6"> | ||||||||||||||||||
| <JobPropertiesTable job={job} /> | ||||||||||||||||||
| <JobMetadata job={job} /> | ||||||||||||||||||
| <JobAgent job={job} /> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </> | ||||||||||||||||||
| )} | ||||||||||||||||||
| </DrawerContent> | ||||||||||||||||||
| </Drawer> | ||||||||||||||||||
| ); | ||||||||||||||||||
| }; | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { IconSparkles } from "@tabler/icons-react"; | ||
|
|
||
| import { Input } from "@ctrlplane/ui/input"; | ||
| import { ReservedMetadataKey } from "@ctrlplane/validators/targets"; | ||
|
|
||
| import type { Job } from "./Job"; | ||
| import { useMatchSorterWithSearch } from "~/utils/useMatchSorter"; | ||
|
|
||
| type JobMetadataProps = { | ||
| job: Job; | ||
| }; | ||
|
|
||
| export const JobMetadata: React.FC<JobMetadataProps> = ({ job }) => { | ||
| const sortedMetadata = job.job.metadata | ||
| .map(({ key, value }) => [key, value] as [string, string]) | ||
| .sort(([keyA], [keyB]) => keyA.localeCompare(keyB)); | ||
| const { search, setSearch, result } = useMatchSorterWithSearch( | ||
| sortedMetadata, | ||
| { keys: ["0", "1"] }, | ||
| ); | ||
| return ( | ||
| <div className="space-y-2"> | ||
| <span className="text-sm">Metadata ({sortedMetadata.length})</span> | ||
| <div className="text-xs"> | ||
| <Input | ||
| className="w-full rounded-b-none text-xs" | ||
| placeholder="Search ..." | ||
| aria-label="Search metadata" | ||
| role="searchbox" | ||
| value={search} | ||
| onChange={(e) => setSearch(e.target.value)} | ||
| /> | ||
| <div className="scrollbar-thin scrollbar-thumb-neutral-800 scrollbar-track-neutral-900 max-h-[250px] overflow-auto rounded-b-lg border-x border-b p-1.5"> | ||
| {result.length === 0 && ( | ||
| <div className="text-center text-muted-foreground"> | ||
| No matching metadata found | ||
| </div> | ||
| )} | ||
| {result.map(([key, value]) => ( | ||
| <div className="text-nowrap font-mono" key={key}> | ||
| <span> | ||
| {Object.values(ReservedMetadataKey).includes( | ||
| key as ReservedMetadataKey, | ||
| ) && ( | ||
| <IconSparkles className="inline-block h-3 w-3 text-yellow-300" /> | ||
| )}{" "} | ||
| </span> | ||
| <span className="text-red-400">{key}:</span> | ||
| <span className="text-green-300"> {value}</span> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | ||||||||||||||||||||||||||||||||||||||
| import React from "react"; | ||||||||||||||||||||||||||||||||||||||
| import { capitalCase } from "change-case"; | ||||||||||||||||||||||||||||||||||||||
| import { format } from "date-fns"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import { JobStatusReadable } from "@ctrlplane/validators/jobs"; | ||||||||||||||||||||||||||||||||||||||
| import { ReservedMetadataKey } from "@ctrlplane/validators/targets"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import type { Job } from "./Job"; | ||||||||||||||||||||||||||||||||||||||
| import { JobTableStatusIcon } from "../JobTableStatusIcon"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| type JobPropertiesTableProps = { | ||||||||||||||||||||||||||||||||||||||
| job: Job; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export const JobPropertiesTable: React.FC<JobPropertiesTableProps> = ({ | ||||||||||||||||||||||||||||||||||||||
| job, | ||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||
| const linksMetadata = job.job.metadata.find( | ||||||||||||||||||||||||||||||||||||||
| (m) => m.key === String(ReservedMetadataKey.Links), | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const links = | ||||||||||||||||||||||||||||||||||||||
| linksMetadata != null | ||||||||||||||||||||||||||||||||||||||
| ? (JSON.parse(linksMetadata.value) as Record<string, string>) | ||||||||||||||||||||||||||||||||||||||
| : null; | ||||||||||||||||||||||||||||||||||||||
adityachoudhari26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||
| <div className="space-y-2"> | ||||||||||||||||||||||||||||||||||||||
| <div className="text-sm">Properties</div> | ||||||||||||||||||||||||||||||||||||||
| <table width="100%" className="table-fixed text-xs"> | ||||||||||||||||||||||||||||||||||||||
| <tbody> | ||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Job Status | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td> | ||||||||||||||||||||||||||||||||||||||
| <div className="flex items-center gap-2"> | ||||||||||||||||||||||||||||||||||||||
| <JobTableStatusIcon | ||||||||||||||||||||||||||||||||||||||
| status={job.job.status} | ||||||||||||||||||||||||||||||||||||||
| className="h-3 w-3" | ||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||
| {JobStatusReadable[job.job.status]} | ||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Environment | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td>{job.environment.name}</td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Deployment | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td>{capitalCase(job.release.deployment.name)}</td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Release | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td>{job.release.name}</td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
| {job.causedBy != null && ( | ||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Caused by | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td>{job.causedBy.name}</td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Created at | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td>{format(job.job.createdAt, "MMM d, yyyy 'at' h:mm a")}</td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="w-[110px] p-1 pr-2 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||
| Updated at | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| <td>{format(job.job.updatedAt, "MMM d, yyyy 'at' h:mm a")}</td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| <tr> | ||||||||||||||||||||||||||||||||||||||
| <td className="p-1 pr-2 align-top text-muted-foreground">Links</td> | ||||||||||||||||||||||||||||||||||||||
| <td> | ||||||||||||||||||||||||||||||||||||||
| {links == null ? ( | ||||||||||||||||||||||||||||||||||||||
| <span className="cursor-help italic text-gray-500"> | ||||||||||||||||||||||||||||||||||||||
| Not set | ||||||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||
| <div className="pt-1"> | ||||||||||||||||||||||||||||||||||||||
| {Object.entries(links).map(([name, url]) => ( | ||||||||||||||||||||||||||||||||||||||
| <a | ||||||||||||||||||||||||||||||||||||||
| key={name} | ||||||||||||||||||||||||||||||||||||||
| referrerPolicy="no-referrer" | ||||||||||||||||||||||||||||||||||||||
| href={url} | ||||||||||||||||||||||||||||||||||||||
| className="inline-block w-full overflow-hidden text-ellipsis text-nowrap text-blue-300 hover:text-blue-400" | ||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||
| {name} | ||||||||||||||||||||||||||||||||||||||
| </a> | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+96
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add security attributes for external links. The current implementation of external links lacks proper security attributes. Apply this fix: <a
key={name}
referrerPolicy="no-referrer"
href={url}
+ target="_blank"
+ rel="noopener noreferrer"
className="inline-block w-full overflow-hidden text-ellipsis text-nowrap text-blue-300 hover:text-blue-400"
>
{name}
</a>📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||
| </tbody> | ||||||||||||||||||||||||||||||||||||||
| </table> | ||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||
adityachoudhari26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.