From 1cdc954b55a0f23ca4716ef396251a4d929f13b0 Mon Sep 17 00:00:00 2001 From: Aditya Choudhari <48932219+adityachoudhari26@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:48:18 -0700 Subject: [PATCH] fix: Show release channel status in policy flow (#192) --- .../releases/[versionId]/FlowDiagram.tsx | 1 + .../[versionId]/ReleaseSequencingNode.tsx | 112 +++++++++++++++++- 2 files changed, 110 insertions(+), 3 deletions(-) diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowDiagram.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowDiagram.tsx index 984d4550..d2d4221c 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowDiagram.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowDiagram.tsx @@ -76,6 +76,7 @@ export const FlowDiagram: React.FC<{ data: { workspaceId: workspace.id, releaseId: release.id, + releaseVersion: release.version, deploymentId: release.deploymentId, environmentId: env.id, policyType: policy?.releaseSequencing, diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/ReleaseSequencingNode.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/ReleaseSequencingNode.tsx index 0304cf2a..a08d9d74 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/ReleaseSequencingNode.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/ReleaseSequencingNode.tsx @@ -1,28 +1,34 @@ import type { EnvironmentCondition, JobCondition, - ReleaseCondition, + ReleaseCondition as JobReleaseCondition, StatusCondition, } from "@ctrlplane/validators/jobs"; +import type { ReleaseCondition } from "@ctrlplane/validators/releases"; import type { NodeProps } from "reactflow"; -import { IconCheck, IconLoader2 } from "@tabler/icons-react"; +import { IconCheck, IconLoader2, IconMinus, IconX } from "@tabler/icons-react"; +import _ from "lodash"; import { Handle, Position } from "reactflow"; import colors from "tailwindcss/colors"; import { cn } from "@ctrlplane/ui"; +import { Button } from "@ctrlplane/ui/button"; import { ColumnOperator, ComparisonOperator, FilterType, } from "@ctrlplane/validators/conditions"; import { JobFilterType, JobStatus } from "@ctrlplane/validators/jobs"; +import { ReleaseFilterType } from "@ctrlplane/validators/releases"; +import { useReleaseChannelDrawer } from "~/app/[workspaceSlug]/_components/release-channel-drawer/useReleaseChannelDrawer"; import { api } from "~/trpc/react"; type ReleaseSequencingNodeProps = NodeProps<{ workspaceId: string; policyType?: "cancel" | "wait"; releaseId: string; + releaseVersion: string; deploymentId: string; environmentId: string; }>; @@ -33,6 +39,12 @@ const Passing: React.FC = () => ( ); +const Failing: React.FC = () => ( +
+ +
+); + const Waiting: React.FC = () => (
@@ -45,6 +57,12 @@ const Loading: React.FC = () => (
); +const Cancelled: React.FC = () => ( +
+ +
+); + const WaitingOnActiveCheck: React.FC = ({ workspaceId, releaseId, @@ -68,7 +86,7 @@ const WaitingOnActiveCheck: React.FC = ({ value: JobStatus.InProgress, }; - const isSameRelease: ReleaseCondition = { + const isSameRelease: JobReleaseCondition = { type: JobFilterType.Release, operator: ColumnOperator.Equals, value: releaseId, @@ -138,6 +156,93 @@ const WaitingOnActiveCheck: React.FC = ({ ); }; +const ReleaseChannelCheck: React.FC = ({ + deploymentId, + environmentId, + releaseVersion, +}) => { + const { setReleaseChannelId } = useReleaseChannelDrawer(); + const environment = api.environment.byId.useQuery(environmentId); + + const envReleaseChannel = environment.data?.releaseChannels.find( + (rc) => rc.deploymentId === deploymentId, + ); + + const policyReleaseChannel = environment.data?.policy?.releaseChannels.find( + (prc) => prc.deploymentId === deploymentId, + ); + + const rcId = envReleaseChannel?.id ?? policyReleaseChannel?.id ?? null; + + const { filter } = envReleaseChannel ?? + policyReleaseChannel ?? { filter: null }; + + const versionFilter: ReleaseCondition = { + type: ReleaseFilterType.Version, + operator: ColumnOperator.Equals, + value: releaseVersion, + }; + + const releaseFilter: ReleaseCondition = { + type: FilterType.Comparison, + operator: ComparisonOperator.And, + conditions: _.compact([versionFilter, filter]), + }; + + const releasesQ = api.release.list.useQuery( + { deploymentId, filter: releaseFilter, limit: 0 }, + { enabled: filter != null }, + ); + + const hasReleaseChannel = rcId != null; + const isPassingReleaseChannel = + filter == null || + (releasesQ.data?.total != null && releasesQ.data.total > 0); + + const loading = environment.isLoading || releasesQ.isLoading; + + return ( +
+ {loading && } + {!loading && !hasReleaseChannel && ( + <> + No release channel + + )} + {!loading && hasReleaseChannel && !isPassingReleaseChannel && ( + <> + + + Blocked by{" "} + + + + )} + {!loading && hasReleaseChannel && isPassingReleaseChannel && ( + <> + + + Passing{" "} + + + + )} +
+ ); +}; + export const ReleaseSequencingNode: React.FC = ({ data, }) => { @@ -149,6 +254,7 @@ export const ReleaseSequencingNode: React.FC = ({ )} > +