-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Deployment resource drawer #237
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b8703f
fix: Deployment resource drawer
adityachoudhari26 5d628cd
extra links
adityachoudhari26 677b578
cleanup
adityachoudhari26 2d85a99
use zod for uuid validation
adityachoudhari26 74f868a
more cleanup
adityachoudhari26 2057a92
cleanup
adityachoudhari26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...[workspaceSlug]/(app)/_components/deployment-resource-drawer/DeploymentResourceDrawer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| "use client"; | ||
|
|
||
| import { IconLoader2, IconShip } from "@tabler/icons-react"; | ||
|
|
||
| import { | ||
| Drawer, | ||
| DrawerContent, | ||
| DrawerDescription, | ||
| DrawerTitle, | ||
| } from "@ctrlplane/ui/drawer"; | ||
|
|
||
| import { api } from "~/trpc/react"; | ||
| import { ReleaseTable } from "./ReleaseTable"; | ||
| import { useDeploymentEnvResourceDrawer } from "./useDeploymentResourceDrawer"; | ||
|
|
||
| export const DeploymentResourceDrawer: React.FC = () => { | ||
| const { | ||
| deploymentId, | ||
| environmentId, | ||
| resourceId, | ||
| setDeploymentEnvResourceId, | ||
| } = useDeploymentEnvResourceDrawer(); | ||
| const isOpen = | ||
| deploymentId != null && environmentId != null && resourceId != null; | ||
| const setIsOpen = () => setDeploymentEnvResourceId(null, null, null); | ||
|
|
||
| const { data: deployment, ...deploymentQ } = api.deployment.byId.useQuery( | ||
| deploymentId ?? "", | ||
| { enabled: isOpen }, | ||
| ); | ||
|
|
||
| const { data: resource, ...resourceQ } = api.resource.byId.useQuery( | ||
| resourceId ?? "", | ||
| { enabled: isOpen }, | ||
| ); | ||
|
|
||
| const { data: environment, ...environmentQ } = api.environment.byId.useQuery( | ||
| environmentId ?? "", | ||
| { enabled: isOpen }, | ||
| ); | ||
|
|
||
| const { data: releaseWithTriggersData, ...releaseWithTriggersQ } = | ||
| api.job.config.byDeploymentEnvAndResource.useQuery( | ||
| { | ||
| deploymentId: deploymentId ?? "", | ||
| environmentId: environmentId ?? "", | ||
| resourceId: resourceId ?? "", | ||
| }, | ||
| { enabled: isOpen, refetchInterval: 5_000 }, | ||
| ); | ||
| const releaseWithTriggers = releaseWithTriggersData ?? []; | ||
|
|
||
| const loading = | ||
| deploymentQ.isLoading || | ||
| resourceQ.isLoading || | ||
| environmentQ.isLoading || | ||
| releaseWithTriggersQ.isLoading; | ||
|
|
||
| return ( | ||
| <Drawer open={isOpen} onOpenChange={setIsOpen}> | ||
| <DrawerContent | ||
| showBar={false} | ||
| className="scrollbar-thin scrollbar-thumb-neutral-800 scrollbar-track-neutral-900 left-auto right-0 top-0 mt-0 h-screen w-2/3 max-w-7xl overflow-auto rounded-none focus-visible:outline-none" | ||
| > | ||
| {loading && ( | ||
| <div className="flex h-full w-full items-center justify-center"> | ||
| <IconLoader2 className="h-8 w-8 animate-spin" /> | ||
| {/* | ||
| Drawer component throws an error if the title and description are not present, so just render empty elements. | ||
| Technically shadcn recommends using the VisuallyHidden radix component, but this fixes without any additional dependencies. | ||
| */} | ||
| <DrawerTitle /> | ||
| <DrawerDescription /> | ||
| </div> | ||
| )} | ||
| {!loading && | ||
| deployment != null && | ||
| resource != null && | ||
| environment != null && ( | ||
| <> | ||
| <DrawerTitle className="flex flex-col gap-2 border-b p-6"> | ||
| <div className="flex items-center gap-2"> | ||
| <div className="flex-shrink-0 rounded bg-amber-500/20 p-1 text-amber-400"> | ||
| <IconShip className="h-4 w-4" /> | ||
| </div> | ||
| {deployment.name} | ||
| </div> | ||
| <div className="flex flex-col gap-1 text-xs text-muted-foreground"> | ||
| <span>Resource: {resource.name}</span> | ||
| <span>Environment: {environment.name}</span> | ||
| </div> | ||
| </DrawerTitle> | ||
|
|
||
| <div className="flex flex-col gap-4 p-6"> | ||
| <ReleaseTable | ||
| releasesWithTriggers={releaseWithTriggers} | ||
| environment={environment} | ||
| deployment={deployment} | ||
| resource={resource} | ||
| /> | ||
| </div> | ||
| </> | ||
| )} | ||
| </DrawerContent> | ||
| </Drawer> | ||
| ); | ||
| }; | ||
65 changes: 65 additions & 0 deletions
65
...ice/src/app/[workspaceSlug]/(app)/_components/deployment-resource-drawer/ReleaseTable.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { RouterOutputs } from "@ctrlplane/api"; | ||
| import type * as SCHEMA from "@ctrlplane/db/schema"; | ||
|
|
||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeader, | ||
| TableRow, | ||
| } from "@ctrlplane/ui/table"; | ||
|
|
||
| import { ReleaseRows } from "./TableRow"; | ||
|
|
||
| type ReleaseWithTriggers = | ||
| RouterOutputs["job"]["config"]["byDeploymentEnvAndResource"][number]; | ||
|
|
||
| type ReleaseTableProps = { | ||
| releasesWithTriggers: ReleaseWithTriggers[]; | ||
| environment: SCHEMA.Environment & { system: SCHEMA.System }; | ||
| deployment: SCHEMA.Deployment; | ||
| resource: SCHEMA.Resource; | ||
| }; | ||
|
|
||
| export const ReleaseTable: React.FC<ReleaseTableProps> = ({ | ||
| releasesWithTriggers, | ||
| environment, | ||
| deployment, | ||
| resource, | ||
| }) => ( | ||
| <div className="rounded-md border border-neutral-800"> | ||
| <Table className="table-fixed"> | ||
| <TableHeader> | ||
| <TableRow> | ||
| <TableHead>Release</TableHead> | ||
| <TableHead>Status</TableHead> | ||
| <TableHead>Created</TableHead> | ||
| <TableHead>Links</TableHead> | ||
| <TableHead /> | ||
| </TableRow> | ||
| </TableHeader> | ||
| <TableBody> | ||
| {releasesWithTriggers.map((release) => ( | ||
| <ReleaseRows | ||
| release={release} | ||
| environment={environment} | ||
| deployment={deployment} | ||
| resource={resource} | ||
| key={release.id} | ||
| /> | ||
| ))} | ||
| {releasesWithTriggers.length === 0 && ( | ||
| <TableRow> | ||
| <TableCell | ||
| colSpan={5} | ||
| className="text-center text-muted-foreground" | ||
| > | ||
| No releases found | ||
| </TableCell> | ||
| </TableRow> | ||
| )} | ||
| </TableBody> | ||
| </Table> | ||
| </div> | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Optimize query conditions to prevent unnecessary API calls
The current implementation uses empty strings when IDs are null, which could trigger unnecessary API calls. Consider enhancing the
enabledcondition to check for valid IDs:api.job.config.byDeploymentEnvAndResource.useQuery( { - deploymentId: deploymentId ?? "", - environmentId: environmentId ?? "", - resourceId: resourceId ?? "", + deploymentId, + environmentId, + resourceId, }, - { enabled: isOpen, refetchInterval: 5_000 }, + { + enabled: isOpen && deploymentId && environmentId && resourceId, + refetchInterval: 5_000 + }, );📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isOpen already checks if the vars are null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adityachoudhari26, understood. Since
isOpenalready checks if the variables are null, the current implementation is appropriate.✏️ Learnings added