Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
removed CreateSourceSecret.tsx file
  • Loading branch information
debsmita1 committed Jul 2, 2019
1 parent 70826cf commit 52dd8a2
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const GitImport: React.FC<GitImportProps> = ({ namespace, imageStreams }) => {
ref: '',
dir: '/',
showGitType: false,
secret: {
isNewSecret: false,
selectedKey: '',
},
secret: '',
},
image: {
selected: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export const mockFormData: GitImportFormData = {
ref: '',
dir: '',
showGitType: false,
secret: {
isNewSecret: false,
selectedKey: '',
},
secret: '',
},
image: {
selected: 'nodejs',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import {
withSecretForm,
SourceSecretForm,
SecretTypeAbstraction,
} from '@console/internal/components/secrets/create-secret';
import { createModalLauncher } from '@console/internal/components/factory/modal';

interface CreateSourceSecretModalProps {
cancel: (e: MouseEvent) => void;
close: () => void;
onSave?: (name: string) => void;
namespace: string;
}

const CreateSourceSecretModal: React.FC<CreateSourceSecretModalProps> = ({
close,
namespace,
onSave,
}) => {
const CreateSourceSecretForm = withSecretForm(SourceSecretForm, true);
const onClose = () => {
close();
return null;
};

const handleSave = (name: string) => {
close();
onSave(name);
};
return (
<CreateSourceSecretForm
onCancel={onClose}
onSave={handleSave}
fixed={{ metadata: { namespace } }}
secretTypeAbstraction={SecretTypeAbstraction.source}
explanation="Source secrets let you authenticate against a Git server."
titleVerb="Create"
isCreate
/>
);
};

export const sourceSecretModalLauncher = createModalLauncher<CreateSourceSecretModalProps>(
CreateSourceSecretModal,
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useFormikContext, FormikValues } from 'formik';
import { ExpandCollapse, HelpBlock, Alert } from 'patternfly-react';
import { ExpandCollapse } from 'patternfly-react';
import { InputField, DropdownField } from '../../formik-fields';
import FormSection from '../section/FormSection';
import SourceSecretSelector from './SourceSecretSelector';
Expand Down Expand Up @@ -31,55 +31,47 @@ const GitSection: React.FC<GitSectionProps> = ({ project }) => {
};

return (
<React.Fragment>
{values.git.secret.isNewSecret && (
<Alert
style={{ left: '800px', position: 'absolute', top: '20px', fontWeight: 'bold' }}
type="success"
>
Secret {values.git.secret.selectedKey} is created and linked with service account builder.
</Alert>
<FormSection title="Git" divider>
<InputField
type="text"
name="git.url"
label="Git Repo URL"
onBlur={handleGitUrlBlur}
required
/>
{values.git.showGitType && (
<DropdownField
name="git.type"
label="Git Type"
items={GitTypes}
selectedKey={values.git.type}
title={GitTypes[values.git.type]}
fullWidth
required
/>
)}
<FormSection title="Git" divider>
<ExpandCollapse
textExpanded="Hide Advanced Git Options"
textCollapsed="Show Advanced Git Options"
>
<InputField
type="text"
name="git.url"
label="Git Repo URL"
onBlur={handleGitUrlBlur}
required
name="git.ref"
label="Git Reference"
helpText="Optional branch, tag, or commit."
/>
<InputField
type="text"
name="git.dir"
label="Context Dir"
helpText="Optional subdirectory for the application source code, used as a context directory for build."
/>
<SourceSecretSelector
namespace={project.name}
helpText="Secret with credentials for pulling your source code."
/>
{values.git.showGitType && (
<DropdownField
name="git.type"
label="Git Type"
items={GitTypes}
selectedKey={values.git.type}
title={GitTypes[values.git.type]}
fullWidth
required
/>
)}
<ExpandCollapse
textExpanded="Hide Advanced Git Options"
textCollapsed="Show Advanced Git Options"
>
<InputField
type="text"
name="git.ref"
label="Git Reference"
helpText="Optional branch, tag, or commit."
/>
<InputField
type="text"
name="git.dir"
label="Context Dir"
helpText="Optional subdirectory for the application source code, used as a context directory for build."
/>
<SourceSecretSelector namespace={project.name} />
<HelpBlock>Secret with credentials for pulling your source code.</HelpBlock>
</ExpandCollapse>
</FormSection>
</React.Fragment>
</ExpandCollapse>
</FormSection>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,85 +1,30 @@
/* eslint-disable no-unused-vars, no-undef */
import * as React from 'react';
import { FormGroup, ControlLabel } from 'patternfly-react';
import { FormGroup, ControlLabel, HelpBlock } from 'patternfly-react';
import { useFormikContext, FormikValues, useField } from 'formik';
import { createModalLauncher } from '../../../../../../public/components/factory/modal';
import SourceSecretDropdown from '../../dropdown/SourceSecretDropdown';
import {
withSecretForm,
SourceSecretForm,
SecretTypeAbstraction,
} from '../../../../../../public/components/secrets/create-secret';
import { sourceSecretModalLauncher } from './CreateSourceSecretModal';

const CREATE_SOURCE_SECRET = 'create-source-secret';

interface SourceSecretSelectorProps {
namespace: string;
helpText: string;
}

interface CreateSourceSecretModalProps {
cancel: (e: Event) => void;
close: () => void;
onSave?: (name: string) => void;
onCancel: () => void;
namespace: string;
}

const CreateSourceSecretModal: React.FC<CreateSourceSecretModalProps> = ({
close,
namespace,
onSave,
onCancel,
}) => {
const CreateSourceSecretForm = withSecretForm(SourceSecretForm, true);
const onClose = () => {
close();
onCancel();
return null;
};

return (
<CreateSourceSecretForm
onCancel={onClose}
onSave={onSave}
fixed={{ metadata: { namespace } }}
secretTypeAbstraction={SecretTypeAbstraction.source}
explanation="Source secrets let you authenticate against a Git server."
titleVerb="Create"
isCreate
/>
);
};

const sourceSecretModalLauncher = createModalLauncher<CreateSourceSecretModalProps>(
CreateSourceSecretModal,
);

const SourceSecretSelector: React.FC<SourceSecretSelectorProps> = ({ namespace }) => {
const [selectedKey] = useField('git.secret.selectedKey');
const SourceSecretSelector: React.FC<SourceSecretSelectorProps> = ({ namespace, helpText }) => {
const [secret] = useField('git.secret');
const { setFieldValue } = useFormikContext<FormikValues>();
let secretName: string;

const onSave = (name: string) => {
secretName = name;
};

const onCancel = () => {
secretName = '';
const handleSave = (name: string) => {
setFieldValue('git.secret', name);
};

const onDropdownChange = async (key: string) => {
const handleDropdownChange = (key: string) => {
if (key === CREATE_SOURCE_SECRET) {
setFieldValue('git.secret.isNewSecret', false);
setFieldValue('git.secret.selectedKey', key);
await sourceSecretModalLauncher({ namespace, onSave, onCancel }).result.then(() => {
setFieldValue('git.secret.selectedKey', secretName);
if (secretName) {
setFieldValue('git.secret.isNewSecret', true);
}
});
setFieldValue('git.secret', secret.value);
sourceSecretModalLauncher({ namespace, onSave: handleSave });
} else {
setFieldValue('git.secret.selectedKey', key);
setFieldValue('git.secret.isNewSecret', false);
setFieldValue('git.secret', key);
}
};
return (
Expand All @@ -94,12 +39,11 @@ const SourceSecretSelector: React.FC<SourceSecretSelectorProps> = ({ namespace }
actionTitle: 'Create New Secret',
actionKey: CREATE_SOURCE_SECRET,
}}
selectedKey={selectedKey.value}
title={
selectedKey.value === 'create-source-secret' ? 'Create New Secret' : selectedKey.value
}
onChange={onDropdownChange}
selectedKey={secret.value}
title={secret.value}
onChange={handleDropdownChange}
/>
<HelpBlock>{helpText}</HelpBlock>
</FormGroup>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export interface GitData {
ref: string;
dir: string;
showGitType: boolean;
secret: {
isNewSecret: boolean;
selectedKey: string;
};
secret: string;
}

export interface RouteData {
Expand Down
Loading

0 comments on commit 52dd8a2

Please sign in to comment.