Skip to content

Commit

Permalink
fix(release-plan): update release plan form, add status and release p…
Browse files Browse the repository at this point in the history
…lan addmision column
  • Loading branch information
sahil143 committed Mar 6, 2024
1 parent 440184a commit 2062fa6
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import { InputField, RadioGroupField, TextAreaField } from '../../../../shared';
import { useWorkspaceInfo } from '../../../../utils/workspace-context-utils';
import { ReleasePipelineLocation } from './form-utils';

const GitOptions: React.FC = () => {
const GitOptions: React.FC<{ required?: boolean }> = ({ required = false }) => {
const [expanded, setExpanded] = React.useState(true);
return (
<>
<InputField
name="git.url"
label="GitHub URL"
label="GitHub URL for the release pipeline"
placeholder="Example, https://github.com/tektoncd/catalog"
helpText="The GitHub repository that contains the YAML definition of the pipeline run for your release service."
required
required={required}
/>
<ExpandableSection
toggleText="Git options"
toggleText="Git options for the release pipeline"
isExpanded={expanded}
onToggle={(_, e) => setExpanded(e)}
isIndented
Expand All @@ -29,15 +29,15 @@ const GitOptions: React.FC = () => {
name="git.revision"
label="Revision"
helpText="A Git revision commit SHA, branch, or tag to get a file from."
required
required={required}
/>
</FormSection>
<FormSection>
<InputField
name="git.path"
label="Path in repository"
helpText="How can we find the file in your repository?"
required
required={required}
/>
</FormSection>
</ExpandableSection>
Expand All @@ -58,15 +58,15 @@ export const RunReleasePipelineSection: React.FC = () => {
options={[
{
value: ReleasePipelineLocation.current,
label: `In the current workspace: ${workspace}`,
label: `In this workspace: ${workspace}`,
},
{ value: ReleasePipelineLocation.target, label: 'In a target workspace' },
]}
required
/>
{pipelineLocation === ReleasePipelineLocation.current && (
<>
<GitOptions />
<GitOptions required />
<InputField
name="serviceAccount"
label="Service account"
Expand All @@ -81,22 +81,28 @@ export const RunReleasePipelineSection: React.FC = () => {
/>
<FormikParamsField
fieldName="params"
heading=<>
Parameters{' '}
<HelpPopover
headerContent="Parameters"
bodyContent=<>
Add any of the following types of parameters:
<List>
<ListItem>url: The URL of the repo to fetch and clone anonymously.</ListItem>
<ListItem>repo: The repository to find the resource in.</ListItem>
<ListItem>org: The organization to find the repository in.</ListItem>
<ListItem>revision: Git revision to checkout a file from.</ListItem>
<ListItem>pathInRepo: Where to find the file in the repository.</ListItem>
</List>
</>
/>
</>
heading={
<>
Parameters{' '}
<HelpPopover
headerContent="Parameters"
bodyContent={
<>
Add any of the following types of parameters:
<List>
<ListItem>
url: The URL of the repo to fetch and clone anonymously.
</ListItem>
<ListItem>repo: The repository to find the resource in.</ListItem>
<ListItem>org: The organization to find the repository in.</ListItem>
<ListItem>revision: Git revision to checkout a file from.</ListItem>
<ListItem>pathInRepo: Where to find the file in the repository.</ListItem>
</List>
</>
}
/>
</>
}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('ReleasePlanForm', () => {
expect(result.getByRole('heading', { name: 'Create release plan' })).toBeVisible();
expect(result.getByRole('button', { name: 'Create' })).toBeVisible();
expect(result.getByRole('button', { name: 'Create' })).toBeVisible();
expect(result.getByRole('radio', { name: 'In the current workspace: test-ws' })).toBeVisible();
expect(result.getByRole('radio', { name: 'In this workspace: test-ws' })).toBeVisible();
expect(result.getByRole('radio', { name: 'In a target workspace' })).toBeVisible();
expect(result.getByRole('checkbox', { name: 'Auto release' })).toBeVisible();
expect(result.getByRole('checkbox', { name: 'Standing attribution' })).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,51 @@ describe('RunReleasePipelineSection', () => {
it('should not show target fields if location is not selected', () => {
const values = {};
const result = formikRenderer(<RunReleasePipelineSection />, values);
expect(result.queryByRole('button', { name: 'Git options' })).toBeNull();
expect(result.queryByRole('textbox', { name: 'GitHub URL' })).toBeNull();
expect(
result.queryByRole('button', { name: 'Git options for the release pipeline' }),
).toBeNull();
expect(
result.queryByRole('textbox', { name: 'GitHub URL for the release pipeline' }),
).toBeNull();
expect(result.queryByRole('textbox', { name: 'Revision' })).toBeNull();
expect(result.queryByRole('textbox', { name: 'Path in repository' })).toBeNull();
expect(result.queryByRole('region', { name: 'Git options' })).toBeNull();
expect(
result.queryByRole('region', { name: 'Git options for the release pipeline' }),
).toBeNull();
expect(result.queryByRole('textbox', { name: 'Service account' })).toBeNull();
});

it('should show current ws fields if current location is selected', () => {
const values = { releasePipelineLocation: ReleasePipelineLocation.current };
const result = formikRenderer(<RunReleasePipelineSection />, values);
expect(result.getByRole('button', { name: 'Git options' })).toBeVisible();
expect(result.getByRole('textbox', { name: 'GitHub URL' })).toBeVisible();
expect(
result.getByRole('button', { name: 'Git options for the release pipeline' }),
).toBeVisible();
expect(
result.getByRole('textbox', { name: 'GitHub URL for the release pipeline' }),
).toBeVisible();
expect(result.getByRole('textbox', { name: 'Revision' })).toBeVisible();
expect(result.getByRole('textbox', { name: 'Path in repository' })).toBeVisible();
expect(result.getByRole('region', { name: 'Git options' })).toBeVisible();
expect(
result.getByRole('region', { name: 'Git options for the release pipeline' }),
).toBeVisible();
expect(result.getByRole('textbox', { name: 'Service account' })).toBeVisible();
});

it('should show target select fields if target location is selected', () => {
const values = { releasePipelineLocation: ReleasePipelineLocation.target };
const result = formikRenderer(<RunReleasePipelineSection />, values);
expect(result.getByRole('button', { name: 'Git options' })).toBeVisible();
expect(result.getByRole('textbox', { name: 'GitHub URL' })).toBeVisible();
expect(
result.getByRole('button', { name: 'Git options for the release pipeline' }),
).toBeVisible();
expect(
result.getByRole('textbox', { name: 'GitHub URL for the release pipeline' }),
).toBeVisible();
expect(result.getByRole('textbox', { name: 'Revision' })).toBeVisible();
expect(result.getByRole('textbox', { name: 'Path in repository' })).toBeVisible();
expect(result.getByRole('region', { name: 'Git options' })).toBeVisible();
expect(
result.getByRole('region', { name: 'Git options for the release pipeline' }),
).toBeVisible();
expect(result.getByRole('textbox', { name: 'Target workspace' })).toBeVisible();
expect(result.getByRole('textbox', { name: 'Data' })).toBeVisible();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ describe('createReleasePlan', () => {
expect(result).toEqual(
expect.objectContaining({
metadata: {
labels: {},
labels: {
'release.appstudio.openshift.io/auto-release': 'false',
'release.appstudio.openshift.io/standing-attribution': 'false',
},
name: 'test-plan',
namespace: 'test-ns',
},
Expand All @@ -66,7 +69,7 @@ describe('createReleasePlan', () => {
],
resolver: 'git',
},
target: 'test-ws',
target: 'test-ws-tenant',
},
}),
);
Expand Down Expand Up @@ -111,7 +114,7 @@ describe('createReleasePlan', () => {
],
resolver: 'git',
},
target: 'target-ws',
target: 'target-ws-tenant',
},
}),
);
Expand Down Expand Up @@ -161,6 +164,7 @@ describe('createReleasePlan', () => {
);
expect(result.metadata.labels).toEqual({
'release.appstudio.openshift.io/auto-release': 'true',
'release.appstudio.openshift.io/standing-attribution': 'false',
});
});
});
Expand All @@ -186,7 +190,7 @@ describe('editReleasePlan', () => {
'my-ws',
);

expect(result.spec.target).toBe('my-ws');
expect(result.spec.target).toBe('my-ws-tenant');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum ReleasePipelineLocation {
target,
}

const WORKSPACE_SUFFIX = 'tenant';

export type ReleasePlanFormValues = {
name: string;
application: string;
Expand All @@ -46,10 +48,18 @@ export const releasePlanFormSchema = yup.object({
.max(MAX_RESOURCE_NAME_LENGTH, RESOURCE_NAME_LENGTH_ERROR_MSG)
.required('Required'),
application: yup.string().required('Required'),
git: yup.object({
url: yup.string().matches(gitUrlRegex).required('Required'),
revision: yup.string().required('Required'),
path: yup.string().required('Required'),
git: yup.object().when('releasePipelineLocation', {
is: ReleasePipelineLocation.current,
then: yup.object({
url: yup.string().matches(gitUrlRegex).required('Required'),
revision: yup.string().required('Required'),
path: yup.string().required('Required'),
}),
otherwise: yup.object({
url: yup.string().matches(gitUrlRegex),
revision: yup.string(),
path: yup.string(),
}),
}),
serviceAccount: yup.string().when('releasePipelineLocation', {
is: ReleasePipelineLocation.current,
Expand Down Expand Up @@ -100,15 +110,17 @@ export const createReleasePlan = async (
namespace,
labels: {
...labels,
...(autoRelease ? { [ReleasePlanLabel.AUTO_RELEASE]: 'true' } : {}),
...(standingAttribution ? { [ReleasePlanLabel.STANDING_ATTRIBUTION]: 'true' } : {}),
...{
[ReleasePlanLabel.AUTO_RELEASE]: String(Boolean(autoRelease)),
[ReleasePlanLabel.STANDING_ATTRIBUTION]: String(Boolean(standingAttribution)),
},
},
},
spec: {
application,
...(data ? { data } : {}),
serviceAccount,
target: targetWs,
target: `${targetWs}-${WORKSPACE_SUFFIX}`,
pipelineRef: {
resolver: ResolverType.GIT,
params: [
Expand Down Expand Up @@ -161,16 +173,18 @@ export const editReleasePlan = async (
...releasePlan.metadata,
labels: {
...labels,
...(autoRelease ? { [ReleasePlanLabel.AUTO_RELEASE]: 'true' } : {}),
...(standingAttribution ? { [ReleasePlanLabel.STANDING_ATTRIBUTION]: 'true' } : {}),
...{
[ReleasePlanLabel.AUTO_RELEASE]: String(Boolean(autoRelease)),
[ReleasePlanLabel.STANDING_ATTRIBUTION]: String(Boolean(standingAttribution)),
},
},
},
spec: {
...releasePlan.spec,
application,
...(data ? { data } : {}),
serviceAccount,
target: targetWs,
target: `${targetWs}-${WORKSPACE_SUFFIX}`,
pipelineRef: {
resolver: ResolverType.GIT,
params: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const releasesPlanTableColumnClasses = {
name: 'pf-m-width-25 wrap-column',
name: 'pf-m-width-20 wrap-column',
application: 'pf-m-width-15',
target: 'pf-m-width-20',
autoRelease: 'pf-m-hidden pf-m-width-15 pf-m-visible-on-xl',
target: 'pf-m-width-15',
autoRelease: 'pf-m-hidden pf-m-width-10 pf-m-visible-on-xl',
standingAttribution: 'pf-m-hidden pf-m-width-15 pf-m-visible-on-xl',
status: 'pf-m-hidden pf-m-width-15 pf-m-visible-on-xl',
rpa: 'pf-m-hidden pf-m-width-15 pf-m-visible-on-xl',
kebab: 'pf-v5-c-table__action',
};

Expand All @@ -29,6 +31,14 @@ const ReleasePlanListHeader = () => {
title: 'Standing attribution',
props: { className: releasesPlanTableColumnClasses.standingAttribution },
},
{
title: 'Status',
props: { className: releasesPlanTableColumnClasses.status },
},
{
title: 'Release plan admission',
props: { className: releasesPlanTableColumnClasses.status },
},
{
title: ' ',
props: {
Expand Down
18 changes: 17 additions & 1 deletion src/components/ReleaseService/ReleasePlan/ReleasePlanListRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { Link } from 'react-router-dom';
import { capitalize } from '@patternfly/react-core';
import { Label, capitalize } from '@patternfly/react-core';
import { CheckCircleIcon } from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
import { RowFunctionArgs, TableData } from '../../../shared';
import ActionMenu from '../../../shared/components/action-menu/ActionMenu';
import { ReleasePlanKind, ReleasePlanLabel } from '../../../types/coreBuildService';
Expand Down Expand Up @@ -31,6 +33,20 @@ const ReleasePlanListRow: React.FC<React.PropsWithChildren<RowFunctionArgs<Relea
<TableData className={releasesPlanTableColumnClasses.standingAttribution}>
{capitalize(obj.metadata.labels?.[ReleasePlanLabel.STANDING_ATTRIBUTION] ?? 'false')}
</TableData>
<TableData className={releasesPlanTableColumnClasses.status}>
{obj.status?.releasePlanAdmission ? (
<Label variant="outline" color="green" icon={<CheckCircleIcon />}>

Check warning on line 38 in src/components/ReleaseService/ReleasePlan/ReleasePlanListRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/ReleaseService/ReleasePlan/ReleasePlanListRow.tsx#L38

Added line #L38 was not covered by tests
Matched
</Label>
) : (
<Label variant="outline" color="red" icon={<ExclamationCircleIcon />}>
Not Matched
</Label>
)}
</TableData>
<TableData className={releasesPlanTableColumnClasses.rpa}>
{obj.status?.releasePlanAdmission?.name ?? '-'}
</TableData>
<TableData className={releasesPlanTableColumnClasses.kebab}>
<ActionMenu actions={actions} />
</TableData>
Expand Down
9 changes: 9 additions & 0 deletions src/types/coreBuildService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type ReleaseStatus = {

export type ReleasePlanKind = K8sResourceCommon & {
spec: ReleasePlanSpec;
status?: ReleasePlanStatus;
};

export type ReleasePlanSpec = {
Expand All @@ -105,6 +106,14 @@ export type ReleasePlanSpec = {
serviceAccount?: string;
};

export type ReleasePlanStatus = {
releasePlanAdmission?: {
name: string;
active: boolean;
};
conditions?: Condition[];
};

export const ReleasePlanLabel = {
AUTO_RELEASE: 'release.appstudio.openshift.io/auto-release',
STANDING_ATTRIBUTION: 'release.appstudio.openshift.io/standing-attribution',
Expand Down

0 comments on commit 2062fa6

Please sign in to comment.