-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Clean up release sequencing (#137)
- Loading branch information
1 parent
a28593d
commit 9cc03ba
Showing
11 changed files
with
239 additions
and
237 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
102 changes: 102 additions & 0 deletions
102
.../[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/ReleaseSequencingNode.tsx
This file contains 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,102 @@ | ||
import type { NodeProps } from "reactflow"; | ||
import { IconCheck, IconLoader2 } from "@tabler/icons-react"; | ||
import { Handle, Position } from "reactflow"; | ||
import colors from "tailwindcss/colors"; | ||
|
||
import { cn } from "@ctrlplane/ui"; | ||
import { JobStatus } from "@ctrlplane/validators/jobs"; | ||
|
||
import { api } from "~/trpc/react"; | ||
|
||
type ReleaseSequencingNodeProps = NodeProps<{ | ||
policyType?: "cancel" | "wait"; | ||
releaseId: string; | ||
deploymentId: string; | ||
environmentId: string; | ||
}>; | ||
|
||
const Passing: React.FC = () => ( | ||
<div className="rounded-full bg-green-400 p-0.5 dark:text-black"> | ||
<IconCheck strokeWidth={3} className="h-3 w-3" /> | ||
</div> | ||
); | ||
|
||
const Waiting: React.FC = () => ( | ||
<div className="animate-spin rounded-full bg-blue-400 p-0.5 dark:text-black"> | ||
<IconLoader2 strokeWidth={3} className="h-3 w-3" /> | ||
</div> | ||
); | ||
|
||
const Loading: React.FC = () => ( | ||
<div className="animate-spin rounded-full bg-muted-foreground p-0.5 dark:text-black"> | ||
<IconLoader2 strokeWidth={3} className="h-3 w-3" /> | ||
</div> | ||
); | ||
|
||
const WaitingOnActiveCheck: React.FC<ReleaseSequencingNodeProps["data"]> = ({ | ||
releaseId, | ||
deploymentId, | ||
environmentId, | ||
}) => { | ||
const allJobs = api.job.config.byDeploymentId.useQuery(deploymentId, { | ||
refetchInterval: 10_000, | ||
}); | ||
const isReleasePending = allJobs.data?.some( | ||
(j) => | ||
j.job.status === JobStatus.Pending && | ||
j.release.id === releaseId && | ||
j.environmentId === environmentId, | ||
); | ||
const isWaitingOnActive = | ||
isReleasePending && | ||
allJobs.data?.some( | ||
(j) => | ||
j.job.status === JobStatus.InProgress && | ||
j.release.id !== releaseId && | ||
j.environmentId === environmentId, | ||
); | ||
|
||
return ( | ||
<div className="flex items-center gap-2"> | ||
{allJobs.isLoading && <Loading />} | ||
{isWaitingOnActive && ( | ||
<> | ||
<Waiting /> Another release is in progress | ||
</> | ||
)} | ||
{!isWaitingOnActive && !allJobs.isLoading && ( | ||
<> | ||
<Passing /> All other releases finished | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export const ReleaseSequencingNode: React.FC<ReleaseSequencingNodeProps> = ({ | ||
data, | ||
}) => { | ||
return ( | ||
<> | ||
<div | ||
className={cn( | ||
"relative w-[250px] space-y-1 rounded-md border px-2 py-1.5 text-sm", | ||
)} | ||
> | ||
<WaitingOnActiveCheck {...data} /> | ||
</div> | ||
<Handle | ||
type="target" | ||
className="h-2 w-2 rounded-full border border-neutral-500" | ||
style={{ background: colors.neutral[800] }} | ||
position={Position.Left} | ||
/> | ||
<Handle | ||
type="source" | ||
className="h-2 w-2 rounded-full border border-neutral-500" | ||
style={{ background: colors.neutral[800] }} | ||
position={Position.Right} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.