-
Notifications
You must be signed in to change notification settings - Fork 642
Create/Edit source secret #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create/Edit source secret #150
Conversation
We might call it "Git Source Secret" to make it more obvious what it's used for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the placement of the dropdown menu doesn't look correct - @beanh66 did you have a mock for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small comments!
} | ||
|
||
const determineDefaultSecretType = (typeAbstraction) => { | ||
if (typeAbstraction === 'source'){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a style consistency nit:
return typeAbstraction === 'source' ? SecretType.basicAut : SecretType.opaque;
const { saveButtonText } = this.props; | ||
|
||
const explanation = 'Webhook secrets allow you to authenticate a webhook trigger.'; | ||
const subform = <WebHookSecretSubform onChange={this.onDataChanged.bind(this)} stringData={this.state.stringData} />; | ||
let explanation = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can const
and separate the logic on these, I would:
const isWebhook = this.state.secretTypeAbstraction === 'webhook';
const explanation = isWebhook
? 'Webhook secrets allow you to authenticate a webhook trigger.'
: 'Source secrets allow you to authenticate against the SCM server.';
const subform = isWebhook
? <WebHookSecretSubform onChange={this.onDataChanged.bind(this)} stringData={this.state.stringData} />
: <SourceSecretSubform onChange={this.onDataChanged.bind(this)} stringData={this.state.stringData} />;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are going to be a bunch more subforms, so this won't scale. We'll eventually have a switch statement for several types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats fine. A switch
or an object
lookup works for me.
}, () => this.props.onChange(this.state)); | ||
} | ||
render () { | ||
return <div className="form-group"> | ||
<label className="control-label" htmlFor="webhook-secret-key">Webhook Secret Key</label> | ||
<div className="input-group"> | ||
<input className="form-control" id="webhook-secret-key" type="text" name="webhookSecretKey" onChange={this.changeWebHookSecretkey} value={this.state.WebHookSecretKey} required/> | ||
<input className="form-control" id="webhook-secret-key" type="text" name="webhookSecretKey" onChange={this.changeWebHookSecretkey} value={this.state.stringData.WebHookSecretKey} required/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to worry about ensuring id
attribs are always unique, with something like _.uniqueId('webhook-secret-key-')
? We ran into this error a lot in the old console, where a component initially only appeared on the page once... then later would get reused & we would have id
conflicts. I'd suggest we just always ensure its unique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry about it here. Presumably we won't show the form more than once on the page
}, () => this.props.onChange(this.state)); | ||
} | ||
render () { | ||
const basicAuthSubform = <React.Fragment> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need to live inside render
? I'd prob rather favor smaller components & just pull them out as separate functions:
const basicAuthSubform: React.SFC = ({props}) => <React.Fragment> ... </React.Fragment>
I hesitate to risk render
bloating over time.
<input type="text" className="form-control" readOnly disabled/> | ||
<span className="input-group-btn"> | ||
<span className="btn btn-default btn-file"> | ||
Browse… |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Browse…
correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</select> | ||
</div> | ||
</div> | ||
{ this.state.authenticationType === 'kubernetes.io/basic-auth' ? basicAuthSubform : sshAuthSubform } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per above comment, then:
{ this.state.authenticationType === 'kubernetes.io/basic-auth'
? <BasicAuthSubform {...theseProps} />
: <SSHAuthSubform {...otherProps}> }
@benjaminapetersen thanks ! The PR is in a early stage, doing the refact ATM, will try to use the HOC for this. Wanted to have a "working version" asap so the UX folks can take a look on it. |
@serenamarie125 Yes, agreed the dropdown is not aligned correctly, but I think that is a known issue and @jhadvig was addressing in another PR. Correct me if I'm wrong @jhadvig! |
Yeah its a known issue, I've described it here. Will open an issue for that, so we can track it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the clarifications
Jenkins push |
@spadgett @benjaminapetersen I've refactored and updated the PR and the Refactoring includes:
The overall component hierarchy looks like:
Also added:
Had created support for drag'n'drop, but since this PR already has a lot of changes, so I will submit the PR after this is merged. Had done a lot of manual testing where I was creating and then editing the secrets. The UX design stayed without any changes. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jhadvig. I think the HOC works well
Some comments
@@ -0,0 +1,29 @@ | |||
.btn-file { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me why we need special styles for the button if we're already using Bootstrap .input-group-btn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export enum SecretType { | ||
basicAuth = 'kubernetes.io/basic-auth', | ||
sshAuth = 'kubernetes.io/ssh-auth', | ||
opaque = 'Opaque' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider reusing values from the enum when we define the secret list filters
} | ||
|
||
const secretFormExplanation = { | ||
source: 'Source secrets allow you to authenticate against the SCM server.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
const secretFormExplanation = {
[SecretTypeAbstraction.source]: 'Source secrets allow you to authenticate against the SCM server.',
[SecretTypeAbstraction.webhook]: 'Webhook secrets allow you to authenticate a webhook trigger.',
};
|
||
const determineDefaultSecretType = (typeAbstraction) => { | ||
return typeAbstraction === 'source' ? SecretType.basicAuth : SecretType.opaque; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const determineDefaultSecretType = (typeAbstraction: SecretTypeAbstraction) => {
return typeAbstraction === SecretTypeAbstraction.source ? SecretType.basicAuth : SecretType.opaque;
};
const existingObj = _.pick(props.obj, ['metadata', 'type']); | ||
const existingData = _.get(props.obj, 'data'); | ||
const secret = _.defaultsDeep({}, props.fixed, existingObj, { | ||
const inputObj = _.get(props.obj, 'data'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props.obj.data
is the secret object and not just the secret data? That's confusing :/
So there is going to be a props.obj.data.data
property? Usually when you repeat property names like that, something isn't named well.
return <div className="form-group"> | ||
<label className="control-label" htmlFor="ssh-privatekey">SSH Private Key</label> | ||
<div className="modal-body__field"> | ||
<FileInput onChange={this.onFileChange.bind(this)}/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to bind in constructor.
nit: space before /
in self-closing tags since that's the style used throughout the existing code
name="privateKey" | ||
onChange={this.changeData} | ||
value={this.state['ssh-privatekey']} | ||
required> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: self-closing tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-describedby would be good here
onChange: Function; | ||
stringData: {[WebHookSecretKey: string]: string}; | ||
stringData: {[WebHookSecretKey: string]: string}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this only previous review, but this should be
stringData: {
WebHookSecretKey: string,
}
@@ -0,0 +1,50 @@ | |||
import * as React from 'react'; | |||
|
|||
export class FileInput extends React.Component<fileInputProps, fileInputState> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice to see this added with so little code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, even the drag&Drop is pretty small 👍
}; | ||
|
||
// withSecretForm returns SubformComponent which is a Higher Order Component for all the types of secret forms. | ||
const withSecretForm = (SubformComponent) => class SecretFormComponent extends React.Component<BaseEditSecretProps_, BaseEditSecretState_> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can take "Component" out of the name. I'd call this class SecretForm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make even more sense ! :)
@jhadvig This PR is big enough that it would be good to address feedback in separate commits, then we can squash before merge. Then it's easier to review just what's been updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jhadvig. Still looking, but here are a few comments on the CSS
@@ -0,0 +1,31 @@ | |||
.co-create-secret-form { | |||
.btn-file { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file picker is generic and will eventually be used outside the secret form. We shouldn't scope the styles to the secret form.
Please use co-
prefix for new styles.
@@ -0,0 +1,31 @@ | |||
.co-create-secret-form { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BEM discourages nesting, and we should give the classes appropriate names for BEM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style properties should be alphabetized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw nesting in our code-base so thought it's ok, but will try to avoid it ! Thanks :)
} | ||
|
||
.help-block { | ||
margin-bottom: 10px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to override the default margin for help-block?
@spadgett comments addressed. Thanks and PTAL :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please squash.
Thanks @jhadvig !
outline: none; | ||
background: white; | ||
cursor: inherit; | ||
display: block; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alphabetize
@spadgett comment addressed and squashed. Lets merge this baby 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
/lgtm
/refresh |
/retest |
Adding subform for creating source secret types:
kubernetes.io/basic-auth
kubernetes.io/ssh-auth
Screens:



@openshift/team-ux-review PTAL
Going to do additional code refactoring