Skip to content

Commit

Permalink
feat(secrets): remove deployments from add secrets form
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandan13jan committed Apr 30, 2024
1 parent 88647a6 commit 9d775a5
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 202 deletions.
11 changes: 1 addition & 10 deletions src/components/Secrets/SecretsForm/AddSecretForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { OpenDrawerRightIcon } from '@patternfly/react-icons/dist/esm/icons/open
import { Formik } from 'formik';
import { isEmpty } from 'lodash-es';
import FormFooter from '../../../shared/components/form-components/FormFooter';
import {
AddSecretFormValues,
SecretFor,
SecretTypeDropdownLabel,
TargetDropdownDefaults,
} from '../../../types';
import { AddSecretFormValues, SecretFor, SecretTypeDropdownLabel } from '../../../types';
import { addSecret } from '../../../utils/create-utils';
import { useWorkspaceInfo } from '../../../utils/workspace-context-utils';
import { HelpTopicLink } from '../../HelpTopicLink/HelpTopicLink';
Expand All @@ -26,10 +21,6 @@ const AddSecretForm = () => {
type: SecretTypeDropdownLabel.opaque,
name: '',
secretFor: SecretFor.Build,
targets: {
application: '',
component: TargetDropdownDefaults.ALL_COMPONENTS,
},
opaque: {
keyValues: [{ key: '', value: '' }],
},
Expand Down
36 changes: 2 additions & 34 deletions src/components/Secrets/SecretsForm/SecretTypeSubForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { SelectVariant } from '@patternfly/react-core/deprecated';
import { useFormikContext } from 'formik';
import { DropdownItemObject, InputField, RadioGroupField, SelectInputField } from '../../../shared';
import { DropdownItemObject, InputField, SelectInputField } from '../../../shared';
import KeyValueField from '../../../shared/components/formik-fields/key-value-input-field/KeyValueInputField';
import { AddSecretFormValues, SecretFor, SecretTypeDropdownLabel } from '../../../types';
import SecretTypeSelector from '../SecretTypeSelector';
Expand All @@ -11,8 +11,6 @@ import {
isPartnerTask,
isPartnerTaskAvailable,
} from '../utils/secret-utils';
import { ApplicationDropdown } from './ApplicationDropdown';
import { ComponentDropdown } from './ComponentDropdown';
import { ImagePullSecretForm } from './ImagePullSecretForm';
import { KeyValueSecretForm } from './KeyValueSecretForm';
import { SourceSecretForm } from './SourceSecretForm';
Expand Down Expand Up @@ -94,23 +92,6 @@ export const SecretTypeSubForm: React.FC<React.PropsWithChildren<unknown>> = ()

return (
<>
<RadioGroupField
name="secretFor"
label="Secret for"
options={[
{ label: 'Build', value: SecretFor.Build },
{ label: 'Deployment', value: SecretFor.Deployment },
]}
onChange={(type) => {
setFieldValue('secretFor', type);
setFieldValue('type', availableTypes[0]);
if (type === SecretFor.Deployment) {
name && isPartnerTask(name) && setFieldValue('name', '');
clearKeyValues();
}
}}
required
/>
<SecretTypeSelector
key={secretFor}
dropdownItems={dropdownItems}
Expand All @@ -127,7 +108,7 @@ export const SecretTypeSubForm: React.FC<React.PropsWithChildren<unknown>> = ()
}
}}
/>
{secretFor === SecretFor.Build && isPartnerTaskAvailable(currentTypeRef.current) ? (
{isPartnerTaskAvailable(currentTypeRef.current) ? (
<SelectInputField
name="name"
label="Secret name"
Expand Down Expand Up @@ -165,19 +146,6 @@ export const SecretTypeSubForm: React.FC<React.PropsWithChildren<unknown>> = ()
/>
)}

{secretFor === SecretFor.Deployment && (
<>
<ApplicationDropdown
name="targets.application"
helpText="The secret key and its value will be associated with the selected target"
required
/>
<ComponentDropdown
name="targets.component"
helpText="The secret key and its value will be associated with the selected target"
/>
</>
)}
{selectedForm && selectedForm.component}
<KeyValueField
name="labels"
Expand Down
15 changes: 5 additions & 10 deletions src/components/Secrets/SecretsListView/SecretsListHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export const secretsTableColumnClasses = {
secretFor: 'pf-m-width-25 pf-m-width-20-on-lg pf-m-width-15-on-xl',
secretType: 'pf-m-width-25 pf-m-width-20-on-lg pf-m-width-15-on-xl',
name: 'pf-m-width-25 pf-m-width-20-on-lg pf-m-width-20-on-xl wrap-column',
target: 'pf-m-hidden pf-m-visible-on-lg pf-m-width-15 pf-m-width-15-on-xl',
labels: 'pf-m-hidden pf-m-visible-on-xl pf-m-width-20 pf-m-width-15-on-xl',
status: 'pf-m-hidden pf-m-visible-on-lg pf-m-width-20 pf-m-width-20-on-xl wrap-column',
secretFor: 'pf-m-width-25 pf-m-width-20-on-xl',
secretType: 'pf-m-width-25 pf-m-width-20-on-xl',
name: 'pf-m-width-25 pf-m-width-20-on-xl wrap-column',
labels: 'pf-m-hidden pf-m-visible-on-xl pf-m-width-15',
status: 'pf-m-hidden pf-m-visible-on-lg pf-m-width-20 pf-m-width-15-on-xl wrap-column',
kebab: 'pf-c-table__action',
};

Expand All @@ -22,10 +21,6 @@ const SecretsListHeader = () => {
title: 'Name',
props: { className: secretsTableColumnClasses.name },
},
{
title: 'Target',
props: { className: secretsTableColumnClasses.target },
},
{
title: 'Labels',
props: { className: secretsTableColumnClasses.labels },
Expand Down
17 changes: 3 additions & 14 deletions src/components/Secrets/SecretsListView/SecretsListRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Label, Skeleton } from '@patternfly/react-core';
import { Label } from '@patternfly/react-core';
import { RowFunctionArgs, TableData } from '../../../shared';
import ActionMenu from '../../../shared/components/action-menu/ActionMenu';
import { RemoteSecretKind } from '../../../types/secret';
Expand All @@ -14,31 +14,20 @@ export enum RemoteSecretStatus {
Failed = 'Failed',
}

const SecretsListRow: React.FC<React.PropsWithChildren<SecretsListRowProps>> = ({
obj,
customData = {},
}) => {
const { environmentsLoaded = true } = customData;
const SecretsListRow: React.FC<React.PropsWithChildren<SecretsListRowProps>> = ({ obj }) => {
const actions = useSecretActions(obj);

const { secretName, secretFor, secretTarget, secretLabels, secretType, secretStatus } =
getSecretRowData(obj);
const { secretName, secretFor, secretLabels, secretType, secretStatus } = getSecretRowData(obj);
const labels =
secretLabels !== '-'
? secretLabels.split(', ').map((s) => <Label key={s}>{s}</Label>)
: secretLabels;
const environmentsTarget = environmentsLoaded ? (
secretTarget
) : (
<Skeleton screenreaderText="Loading Environments" />
);

return (
<>
<TableData className={secretsTableColumnClasses.secretFor}>{secretFor}</TableData>
<TableData className={secretsTableColumnClasses.secretType}>{secretType}</TableData>
<TableData className={secretsTableColumnClasses.name}> {secretName} </TableData>
<TableData className={secretsTableColumnClasses.target}>{environmentsTarget}</TableData>
<TableData className={secretsTableColumnClasses.labels}>{labels}</TableData>
<TableData className={secretsTableColumnClasses.status}>{secretStatus}</TableData>
<TableData className={secretsTableColumnClasses.kebab}>
Expand Down
1 change: 0 additions & 1 deletion src/components/Secrets/__tests___/AddSecretForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ describe('AddSecretForm', () => {
render(<AddSecretForm />);

await waitFor(() => {
screen.getByText('Secret for');
screen.getByText('Secret type');
screen.getByText('Secret name');
screen.getByText('Labels');
Expand Down
23 changes: 0 additions & 23 deletions src/components/Secrets/__tests___/SecretTypeSubForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,11 @@ describe('SecretTypeSubForm', () => {
});

it('should render Secret type sub form and fields', () => {
expect(screen.getByText('Secret for')).toBeVisible();
expect(screen.getByText('Secret type')).toBeVisible();
expect(screen.getByText('Secret name')).toBeVisible();
});

it('should render subforms correctly for specified targets', async () => {
await fireEvent.click(screen.getByRole('radio', { name: 'Deployment' }));
await waitFor(() => {
expect(screen.getByRole('button', { name: 'Key/value secret' })).toBeDisabled();
expect(screen.getByText('Key value sub form')).toBeVisible();
});

await fireEvent.click(screen.getByRole('radio', { name: 'Build' }));
await waitFor(() => {
expect(screen.getByRole('button', { name: 'Key/value secret' })).toBeEnabled();
});
Expand All @@ -67,25 +59,10 @@ describe('SecretTypeSubForm', () => {
});

it('should render correct variant of name field', async () => {
await fireEvent.click(screen.getByRole('radio', { name: 'Deployment' }));
await waitFor(() => {
expect(screen.getByRole('textbox', { name: 'Secret name' })).toBeVisible();
});

await fireEvent.click(screen.getByRole('radio', { name: 'Build' }));
await waitFor(async () => {
expect(screen.getByRole('button', { name: 'Secret name' })).toBeVisible();
await fireEvent.click(screen.getByRole('button', { name: 'Secret name' }));
expect(screen.getByText('snyk-secret')).toBeVisible();
});
});

it('should render target fields for Deployment secret', async () => {
await fireEvent.click(screen.getByRole('radio', { name: 'Deployment' }));

await waitFor(() => {
expect(screen.getByRole('button', { name: 'Select application' })).toBeVisible();
expect(screen.getByRole('button', { name: 'All components' })).toBeVisible();
});
});
});
1 change: 0 additions & 1 deletion src/components/Secrets/__tests___/SecretsListView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe('Secrets List', () => {

screen.getByText('test-secret-one');
screen.getByText('AwaitingData');
screen.getByText('Deployment');
screen.getByText('Image pull');
});

Expand Down
48 changes: 0 additions & 48 deletions src/components/Secrets/__tests___/secret-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
SecretType,
SecretTypeDropdownLabel,
SourceSecretType,
TargetDropdownDefaults,
} from '../../../types';
import {
createRemoteSecretResource,
Expand Down Expand Up @@ -155,7 +154,6 @@ describe('getSecretRowData', () => {
secretLabels: '-',
secretName: 'test-secret-two',
secretStatus: 'Injected',
secretTarget: '-',
secretType: 'Key/value (1)',
});
});
Expand All @@ -173,7 +171,6 @@ describe('getSecretRowData', () => {
secretLabels: '-',
secretName: 'test-secret-two',
secretStatus: '-',
secretTarget: '-',
secretType: 'Key/value',
});
});
Expand Down Expand Up @@ -251,10 +248,6 @@ const formValues: AddSecretFormValues = {
type: 'Key/value secret',
name: 'test',
secretFor: SecretFor.Build,
targets: {
application: 'test-application',
component: TargetDropdownDefaults.ALL_COMPONENTS,
},
opaque: {
keyValues: [
{
Expand Down Expand Up @@ -384,57 +377,17 @@ describe('getTargetLabelsForRemoteSecret', () => {
expect(
getTargetLabelsForRemoteSecret({
...formValues,
targets: { application: null, component: null },
}),
).toEqual({
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return application target labels for remote secret', () => {
expect(getTargetLabelsForRemoteSecret(formValues)).toEqual({
'appstudio.redhat.com/application': 'test-application',
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return application and component target labels for remote secret', () => {
const fValues = {
...formValues,
targets: {
...formValues.targets,
component: 'test-component',
},
};
expect(getTargetLabelsForRemoteSecret(fValues)).toEqual({
'appstudio.redhat.com/application': 'test-application',
'appstudio.openshift.io/component': 'test-component',
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return application, component and environment target labels for remote secret', () => {
const fValues = {
...formValues,
targets: {
...formValues.targets,
component: 'test-component',
environment: 'test-environment',
},
};
expect(getTargetLabelsForRemoteSecret(fValues)).toEqual({
'appstudio.redhat.com/application': 'test-application',
'appstudio.openshift.io/component': 'test-component',
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return correct label for build secret', () => {
expect(
getTargetLabelsForRemoteSecret({
...formValues,
secretFor: SecretFor.Build,
targets: { application: null, component: null },
}),
).toEqual({
'ui.appstudio.redhat.com/secret-for': 'Build',
Expand All @@ -446,7 +399,6 @@ describe('getTargetLabelsForRemoteSecret', () => {
getTargetLabelsForRemoteSecret({
...formValues,
secretFor: SecretFor.Deployment,
targets: { application: null, component: null },
}),
).toEqual({
'ui.appstudio.redhat.com/secret-for': 'Deployment',
Expand Down
19 changes: 1 addition & 18 deletions src/components/Secrets/__tests___/secret-validation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
ImagePullSecretType,
SecretFor,
SecretTypeDropdownLabel,
SourceSecretType,
} from '../../../types';
import { ImagePullSecretType, SecretTypeDropdownLabel, SourceSecretType } from '../../../types';
import { secretFormValidationSchema } from '../utils/secret-validation';

describe('validation-utils', () => {
Expand Down Expand Up @@ -89,16 +84,4 @@ describe('validation-utils', () => {
}),
).rejects.toThrow('Required');
});

it('should validate targets field', async () => {
await expect(() =>
secretFormValidationSchema.validate({
secretFor: SecretFor.Deployment,
name: 'test-resource',
targets: {
application: '',
},
}),
).rejects.toThrow('Required');
});
});
Loading

0 comments on commit 9d775a5

Please sign in to comment.