Skip to content

Commit fbcd8cd

Browse files
committed
comments #1
1 parent 0a265d6 commit fbcd8cd

File tree

2 files changed

+80
-65
lines changed

2 files changed

+80
-65
lines changed
Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
.btn-file {
2-
position: relative;
3-
overflow: hidden;
4-
}
1+
.co-create-secret-form {
2+
.btn-file {
3+
position: relative;
4+
overflow: hidden;
5+
}
56

6-
.btn-file input[type=file] {
7-
position: absolute;
8-
top: 0;
9-
right: 0;
10-
min-width: 100%;
11-
min-height: 100%;
12-
font-size: 100px;
13-
text-align: right;
14-
filter: alpha(opacity=0);
15-
opacity: 0;
16-
outline: none;
17-
background: white;
18-
cursor: inherit;
19-
display: block;
20-
}
7+
.btn-file input[type=file] {
8+
position: absolute;
9+
top: 0;
10+
right: 0;
11+
min-width: 100%;
12+
min-height: 100%;
13+
font-size: 100px;
14+
text-align: right;
15+
filter: alpha(opacity=0);
16+
opacity: 0;
17+
outline: none;
18+
background: white;
19+
cursor: inherit;
20+
display: block;
21+
}
2122

22-
.form-textarea {
23-
min-height: 300px;
24-
width: 100%;
25-
}
23+
.form-textarea {
24+
min-height: 300px;
25+
width: 100%;
26+
}
2627

27-
.create-secret-form .help-block {
28-
margin-bottom: 10px;
28+
.help-block {
29+
margin-bottom: 10px;
30+
}
2931
}

frontend/public/components/secrets/create-secret.tsx

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ export enum SecretType {
2222
}
2323

2424
const secretFormExplanation = {
25-
source: 'Source secrets allow you to authenticate against the SCM server.',
26-
webhook: 'Webhook secrets allow you to authenticate a webhook trigger.',
25+
[SecretTypeAbstraction.source]: 'Source secrets allow you to authenticate against the SCM server.',
26+
[SecretTypeAbstraction.webhook]: 'Webhook secrets allow you to authenticate a webhook trigger.',
2727
};
2828

29-
const determineDefaultSecretType = (typeAbstraction) => {
30-
return typeAbstraction === 'source' ? SecretType.basicAuth : SecretType.opaque;
29+
const determineDefaultSecretType = (typeAbstraction: SecretTypeAbstraction) => {
30+
return typeAbstraction === SecretTypeAbstraction.source ? SecretType.basicAuth : SecretType.opaque;
3131
};
3232

33+
3334
const determineSecretTypeAbstraction = (data) => {
3435
return _.has(data, WebHookSecretKey) ? SecretTypeAbstraction.webhook : SecretTypeAbstraction.source;
3536
};
@@ -40,12 +41,11 @@ const generateSecret = () => {
4041
return s4() + s4() + s4() + s4();
4142
};
4243

43-
// withSecretForm returns SubformComponent which is a Higher Order Component for all the types of secret forms.
44-
const withSecretForm = (SubformComponent) => class SecretFormComponent extends React.Component<BaseEditSecretProps_, BaseEditSecretState_> {
44+
// withSecretForm returns SubForm which is a Higher Order Component for all the types of secret forms.
45+
const withSecretForm = (SubForm) => class SecretFormComponent extends React.Component<BaseEditSecretProps_, BaseEditSecretState_> {
4546
constructor (props) {
4647
super(props);
47-
const inputObj = _.get(props.obj, 'data');
48-
const existingSecret = _.pick(inputObj, ['metadata', 'type']);
48+
const existingSecret = _.pick(props.obj, ['metadata', 'type']);
4949
const defaultSecretType = determineDefaultSecretType(this.props.secretTypeAbstraction);
5050
const secret = _.defaultsDeep({}, props.fixed, existingSecret, {
5151
apiVersion: 'v1',
@@ -62,7 +62,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
6262
secret: secret,
6363
inProgress: false,
6464
type: defaultSecretType,
65-
stringData: _.mapValues(_.get(inputObj, 'data'), window.atob),
65+
stringData: _.mapValues(_.get(props.obj, 'data'), window.atob),
6666
};
6767
this.onDataChanged = this.onDataChanged.bind(this);
6868
this.onNameChanged = this.onNameChanged.bind(this);
@@ -71,7 +71,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
7171
onDataChanged (secretsData) {
7272
this.setState({
7373
stringData: {...secretsData.stringData},
74-
type: secretsData.authenticationType,
74+
type: secretsData.type,
7575
});
7676
}
7777
onNameChanged (event) {
@@ -100,7 +100,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
100100
<Helmet>
101101
<title>{title}</title>
102102
</Helmet>
103-
<form className="co-m-pane__body-group create-secret-form" onSubmit={this.save}>
103+
<form className="co-m-pane__body-group co-create-secret-form" onSubmit={this.save}>
104104
<h1 className="co-m-pane__heading">{title}</h1>
105105
<p className="co-m-pane__explanation">{this.props.explanation}</p>
106106

@@ -119,7 +119,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
119119
</div>
120120
</div>
121121
</fieldset>
122-
<SubformComponent
122+
<SubForm
123123
onChange={this.onDataChanged.bind(this)}
124124
stringData={this.state.stringData}
125125
secretType={this.state.secret.type}
@@ -178,14 +178,15 @@ class SourceSecretForm extends React.Component<SourceSecretFormProps, SourceSecr
178178
constructor (props) {
179179
super(props);
180180
this.state = {
181-
authenticationType: this.props.secretType,
181+
type: this.props.secretType,
182182
stringData: this.props.stringData || {},
183183
};
184184
this.changeAuthenticationType = this.changeAuthenticationType.bind(this);
185+
this.onDataChanged = this.onDataChanged.bind(this);
185186
}
186187
changeAuthenticationType(event) {
187188
this.setState({
188-
authenticationType: event.target.value
189+
type: event.target.value
189190
}, () => this.props.onChange(this.state));
190191
}
191192
onDataChanged (secretsData) {
@@ -197,26 +198,26 @@ class SourceSecretForm extends React.Component<SourceSecretFormProps, SourceSecr
197198
return <React.Fragment>
198199
{this.props.isCreate
199200
? <div className="form-group">
200-
<label className="control-label">Authentication Type</label>
201-
<div className="modal-body__field">
202-
<select onChange={this.changeAuthenticationType} value={this.state.authenticationType} className="form-control">
203-
<option key="kubernetes.io/basic-auth" value="kubernetes.io/basic-auth">Basic Authentication</option>
204-
<option key="kubernetes.io/ssh-auth" value="kubernetes.io/ssh-auth">SSH Key</option>
201+
<label className="control-label" htmlFor="secret-type" >Authentication Type</label>
202+
<div>
203+
<select onChange={this.changeAuthenticationType} value={this.state.type} className="form-control" id="secret-type">
204+
<option value="kubernetes.io/basic-auth">Basic Authentication</option>
205+
<option value="kubernetes.io/ssh-auth">SSH Key</option>
205206
</select>
206207
</div>
207208
</div>
208209
: null
209210
}
210-
{ this.state.authenticationType === 'kubernetes.io/basic-auth'
211-
? <BasicAuthSubform onChange={this.onDataChanged.bind(this)} stringData={this.state.stringData}/>
212-
: <SSHAuthSubform onChange={this.onDataChanged.bind(this)} stringData={this.state.stringData}/>
211+
{ this.state.type === 'kubernetes.io/basic-auth'
212+
? <BasicAuthSubform onChange={this.onDataChanged} stringData={this.state.stringData} />
213+
: <SSHAuthSubform onChange={this.onDataChanged} stringData={this.state.stringData} />
213214
}
214215
</React.Fragment>;
215216
}
216217
}
217218

218219
const secretFormFactory = secretType => {
219-
return secretType === 'webhook' ? withSecretForm(WebHookSecretForm) : withSecretForm(SourceSecretForm);
220+
return secretType === SecretTypeAbstraction.webhook ? withSecretForm(WebHookSecretForm) : withSecretForm(SourceSecretForm);
220221
};
221222

222223
class BasicAuthSubform extends React.Component<BasicAuthSubformProps, BasicAuthSubformState> {
@@ -237,7 +238,7 @@ class BasicAuthSubform extends React.Component<BasicAuthSubformProps, BasicAuthS
237238
return <React.Fragment>
238239
<div className="form-group">
239240
<label className="control-label" htmlFor="username">Username</label>
240-
<div className="modal-body__field">
241+
<div>
241242
<input className="form-control"
242243
id="username"
243244
aria-describedby="username-help"
@@ -251,7 +252,7 @@ class BasicAuthSubform extends React.Component<BasicAuthSubformProps, BasicAuthS
251252
</div>
252253
<div className="form-group">
253254
<label className="control-label" htmlFor="password">Password or Token</label>
254-
<div className="modal-body__field">
255+
<div>
255256
<input className="form-control"
256257
id="password"
257258
aria-describedby="password-help"
@@ -274,6 +275,7 @@ class SSHAuthSubform extends React.Component<SSHAuthSubformProps, SSHAuthSubform
274275
'ssh-privatekey': this.props.stringData['ssh-privatekey'] || '',
275276
};
276277
this.changeData = this.changeData.bind(this);
278+
this.onFileChange = this.onFileChange.bind(this);
277279
}
278280
changeData(event) {
279281
this.setState({
@@ -288,17 +290,17 @@ class SSHAuthSubform extends React.Component<SSHAuthSubformProps, SSHAuthSubform
288290
render() {
289291
return <div className="form-group">
290292
<label className="control-label" htmlFor="ssh-privatekey">SSH Private Key</label>
291-
<div className="modal-body__field">
292-
<FileInput onChange={this.onFileChange.bind(this)}/>
293+
<div>
294+
<FileInput onChange={this.onFileChange} />
293295
<p className="help-block">Upload your private SSH key file.</p>
294296
<textarea className="form-control form-textarea"
295297
id="ssh-privatekey"
296298
name="privateKey"
297299
onChange={this.changeData}
298300
value={this.state['ssh-privatekey']}
299-
required>
300-
</textarea>
301-
<p className="help-block">Private SSH key file for Git authentication.</p>
301+
aria-describedby="ssh-privatekey-help"
302+
required />
303+
<p className="help-block" id="ssh-privatekey-help">Private SSH key file for Git authentication.</p>
302304
</div>
303305
</div>;
304306
}
@@ -309,12 +311,11 @@ const SecretLoadingWrapper = props => {
309311
const SecretFormComponent = secretFormFactory(secretTypeAbstraction);
310312
const fixed = _.reduce(props.fixedKeys, (acc, k) => ({...acc, k: _.get(props.obj.data, k)}), {});
311313
return <StatusBox {...props.obj}>
312-
<SecretFormComponent
314+
<SecretFormComponent {...props}
313315
secretTypeAbstraction={secretTypeAbstraction}
314316
obj={props.obj.data}
315317
fixed={fixed}
316318
explanation={secretFormExplanation[secretTypeAbstraction]}
317-
{...props}
318319
/>
319320
</StatusBox>;
320321
};
@@ -338,7 +339,7 @@ export type BaseEditSecretState_ = {
338339
secretTypeAbstraction?: SecretTypeAbstraction,
339340
secret: K8sResourceKind,
340341
inProgress: boolean,
341-
type: string,
342+
type: SecretType,
342343
stringData: {[key: string]: string},
343344
error?: any,
344345
};
@@ -355,13 +356,17 @@ export type BaseEditSecretProps_ = {
355356
};
356357

357358
export type SourceSecretFormState = {
358-
authenticationType: SecretType,
359-
stringData: {[key: string]: string},
359+
type: SecretType,
360+
stringData: {
361+
[key: string]: string
362+
},
360363
};
361364

362365
export type SourceSecretFormProps = {
363366
onChange: Function;
364-
stringData: {[key: string]: string},
367+
stringData: {
368+
[key: string]: string
369+
},
365370
secretType: SecretType,
366371
isCreate: boolean,
367372
};
@@ -373,7 +378,9 @@ export type BasicAuthSubformState = {
373378

374379
export type BasicAuthSubformProps = {
375380
onChange: Function,
376-
stringData: {[key: string]: string},
381+
stringData: {
382+
[key: string]: string
383+
},
377384
};
378385

379386
export type SSHAuthSubformState = {
@@ -382,15 +389,21 @@ export type SSHAuthSubformState = {
382389

383390
export type SSHAuthSubformProps = {
384391
onChange: Function;
385-
stringData: {[key: string]: string},
392+
stringData: {
393+
[key: string]: string
394+
},
386395
};
387396

388397
export type WebHookSecretFormState = {
389-
stringData: {[key: string]: string},
398+
stringData: {
399+
[key: string]: string
400+
},
390401
};
391402

392403
export type WebHookSecretFormProps = {
393404
onChange: Function;
394-
stringData: {[WebHookSecretKey: string]: string},
405+
stringData: {
406+
WebHookSecretKey: string
407+
},
395408
};
396409
/* eslint-enable no-undef */

0 commit comments

Comments
 (0)