Skip to content

Commit

Permalink
chore(ui): remove promo mechanisms
Browse files Browse the repository at this point in the history
Signed-off-by: Mayursinh Sarvaiya <[email protected]>
  • Loading branch information
Marvin9 authored and krancour committed Oct 8, 2024
1 parent 303ad1b commit 6788e0e
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 735 deletions.
15 changes: 6 additions & 9 deletions ui/src/features/project/pipelines/nodes/stage-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { generatePath, useNavigate } from 'react-router-dom';
import { paths } from '@ui/config/paths';
import { HealthStatusIcon } from '@ui/features/common/health-status/health-status-icon';
import { PromotionStatusIcon } from '@ui/features/common/promotion-status/promotion-status-icon';
import { willStagePromotionOpenPR } from '@ui/features/promotion-directives/utils';
import { Freight, Stage } from '@ui/gen/v1alpha1/generated_pb';
import { useLocalStorage } from '@ui/utils/use-local-storage';

import { FreightTimelineAction, NodeDimensions } from '../types';
import { isStageControlFlow } from '../utils/util';

import { FreightIndicators } from './freight-indicators';
import { FreightLabel } from './freight-label';
Expand Down Expand Up @@ -96,10 +98,8 @@ export const StageNode = ({
<h3>
<div className='truncate pb-1 mr-auto'>{stage.metadata?.name}</div>
<div className='flex gap-1'>
{(stage?.spec?.promotionMechanisms?.gitRepoUpdates || []).some(
(g) => g.pullRequest
) && (
<Tooltip title='PR Promotion Enabled'>
{willStagePromotionOpenPR(stage) && (
<Tooltip title='contains git-open-pr'>
<FontAwesomeIcon icon={faCodePullRequest} />
</Tooltip>
)}
Expand Down Expand Up @@ -161,9 +161,7 @@ export const StageNode = ({
}
/>
}
disabled={
stage?.spec?.promotionMechanisms === undefined || !stage.spec?.promotionTemplate
}
disabled={isStageControlFlow(stage)}
className='uppercase'
>
{action === FreightTimelineAction.ManualApproval ? 'Approve' : 'Promote'}
Expand All @@ -185,8 +183,7 @@ export const StageNode = ({
{action !== FreightTimelineAction.ManualApproval &&
action !== FreightTimelineAction.PromoteFreight && (
<>
{(stage.spec?.promotionMechanisms ||
!!stage.spec?.promotionTemplate?.spec?.steps?.length) && (
{!isStageControlFlow(stage) && (
<Nodule
begin={true}
nodeHeight={height}
Expand Down
23 changes: 12 additions & 11 deletions ui/src/features/project/pipelines/utils/stage-yaml-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ spec:
name: kargo-demo
sources:
direct: true
promotionMechanisms:
gitRepoUpdates:
- repoURL: https://github.com/akuity/kargo-demo.git
writeBranch: main
kustomize:
images:
- image: public.ecr.aws/nginx/nginx
path: stages/prod
argoCDAppUpdates:
- appName: kargo-demo-prod
appNamespace: argocd`;
promotionTemplate:
spec:
steps:
- uses: git-clone
config:
repoURL: https://github.com/akuity/kargo-advanced
checkout:
- branch: main
path: ./src
- branch: stage/uat
create: true
path: ./out`;
4 changes: 4 additions & 0 deletions ui/src/features/project/pipelines/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { ConnectError } from '@connectrpc/connect';
import { message } from 'antd';

import { Time } from '@ui/gen/k8s.io/apimachinery/pkg/apis/meta/v1/generated_pb';
import { Stage } from '@ui/gen/v1alpha1/generated_pb';

export const getSeconds = (ts?: Time): number => Number(ts?.seconds) || 0;

export const onError = (err: ConnectError) => {
message.error(err?.toString());
};

export const isStageControlFlow = (stage: Stage) =>
(stage?.spec?.promotionTemplate?.spec?.steps?.length || 0) <= 0;
34 changes: 34 additions & 0 deletions ui/src/features/promotion-directives/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Stage } from '@ui/gen/v1alpha1/generated_pb';
import { decodeRawData } from '@ui/utils/decode-raw-data';

// context to bridge directives and pipelines UI

export const willStagePromotionOpenPR = (stage: Stage) =>
(stage?.spec?.promotionTemplate?.spec?.steps || []).some((g) =>
// TODO(Marvin9): find better way than to hardcode
g?.uses?.includes('git-open-pr')
);

export const getPromotionArgoCDApps = (stage: Stage): string[] => {
let apps: string[] = [];
const config = stage?.spec?.promotionTemplate?.spec?.steps?.find((step) =>
step?.uses?.includes('argocd-update')
)?.config?.raw; /* now type is detached with dynamic config */

if (config) {
try {
const data = JSON.parse(
decodeRawData({ result: { case: 'raw', value: config } })
) as /* from docs */ {
apps?: Array<{
name?: string;
}>;
};
apps = data?.apps?.map((app) => app?.name || '').filter(Boolean) || [];
} catch {
// explicitly ignore, no need to crash or anything, this is UI addon
}
}

return apps;
};
7 changes: 1 addition & 6 deletions ui/src/features/stage/create-stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import { zodValidators } from '@ui/utils/validators';
import { promoStepsExample } from '../project/pipelines/utils/promotion-steps-example';
import { getStageYAMLExample } from '../project/pipelines/utils/stage-yaml-example';

import { requestedFreightSchema } from './git-update-editor/schemas';
import { RequestedFreight } from './requested-freight';
import { RequestedFreightEditor } from './requested-freight-editor';
import { requestedFreightSchema } from './schemas';
import { ColorMapHex } from './utils';

const formSchema = z.object({
Expand All @@ -38,7 +38,6 @@ const formSchema = z.object({
const wizardSchema = z.object({
name: zodValidators.requiredString,
requestedFreight: z.array(requestedFreightSchema),
promotionMechanisms: z.string().optional(),
color: z.string().optional(),
// next step is to wizardify this
promotionTemplateSteps: z.string().optional()
Expand All @@ -60,9 +59,6 @@ const stageFormToYAML = (data: z.infer<typeof wizardSchema>, namespace: string)
},
spec: {
requestedFreight: data.requestedFreight,
...(data.promotionMechanisms && {
promotionMechanisms: yaml.parse(data.promotionMechanisms)
}),
...(data.promotionTemplateSteps && {
promotionTemplate: { spec: { steps: yaml.parse(data.promotionTemplateSteps) } }
})
Expand Down Expand Up @@ -104,7 +100,6 @@ export const CreateStage = ({
defaultValues: {
name: '',
requestedFreight: [],
promotionMechanisms: '',
color: undefined,
promotionTemplateSteps: ''
},
Expand Down

This file was deleted.

129 changes: 0 additions & 129 deletions ui/src/features/stage/git-update-editor/helm-charts.tsx

This file was deleted.

Loading

0 comments on commit 6788e0e

Please sign in to comment.