Skip to content

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

Merged
merged 1 commit into from
Jun 26, 2018

Conversation

jhadvig
Copy link
Member

@jhadvig jhadvig commented Jun 21, 2018

Adding subform for creating source secret types:

  • kubernetes.io/basic-auth
  • kubernetes.io/ssh-auth

Screens:
3
1
2

@openshift/team-ux-review PTAL

Going to do additional code refactoring

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 21, 2018
@spadgett
Copy link
Member

We might call it "Git Source Secret" to make it more obvious what it's used for.

Copy link
Contributor

@serenamarie125 serenamarie125 left a 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

Copy link
Contributor

@benjaminapetersen benjaminapetersen left a 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'){
Copy link
Contributor

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;
Copy link
Contributor

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} />;

Copy link
Member

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.

Copy link
Contributor

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/>
Copy link
Contributor

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.

Copy link
Member

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>
Copy link
Contributor

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&hellip;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Browse&hellip; correct?

Copy link
Member Author

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 }
Copy link
Contributor

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}> }

@jhadvig
Copy link
Member Author

jhadvig commented Jun 21, 2018

@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.

@beanh66
Copy link

beanh66 commented Jun 21, 2018

@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!

@jhadvig
Copy link
Member Author

jhadvig commented Jun 22, 2018

Yeah its a known issue, I've described it here. Will open an issue for that, so we can track it.
@serenamarie125 @beanh66 any other suggestions ? Thanks ! :)

Copy link
Contributor

@serenamarie125 serenamarie125 left a 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

@robszumski
Copy link
Contributor

Jenkins push

@jhadvig
Copy link
Member Author

jhadvig commented Jun 25, 2018

@spadgett @benjaminapetersen I've refactored and updated the PR and the create-secret.tsx file.

Refactoring includes:

  • Properly naming class and function componnets
  • Adding a Higher Order Component - withSecretForm - which is responsible or constructing different secret forms (source, webhook) and returns SecretFormComponent that represents particular form

The overall component hierarchy looks like:

SecretFormComponent --  WebHookSecretForm
                    \
                     \  SourceSecretForm  --  BasicAuthSubform
                                          \
                                           \  SSHAuthSubform  -- FileInput

Also added:

  • FileInput component that is responsible for uploading files

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

@jhadvig jhadvig changed the title [WIP] Create/Edit source secret Create/Edit source secret Jun 25, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 25, 2018
Copy link

@beanh66 beanh66 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@spadgett spadgett left a 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 {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in case we want the input field with Browse btn for picking file, we need additional styling since the Bootstrap does not offer this styling by default.
Check origin-web-console styling and usage. Also was browsing similar use-cases and more less this approach is pretty common.

export enum SecretType {
basicAuth = 'kubernetes.io/basic-auth',
sshAuth = 'kubernetes.io/ssh-auth',
opaque = 'Opaque'
Copy link
Member

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.',
Copy link
Member

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;
};
Copy link
Member

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');
Copy link
Member

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)}/>
Copy link
Member

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: self-closing tag?

Copy link
Member

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},
Copy link
Member

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> {
Copy link
Member

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

Copy link
Member Author

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_> {
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make even more sense ! :)

@spadgett
Copy link
Member

@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.

@jhadvig
Copy link
Member Author

jhadvig commented Jun 26, 2018

@spadgett comments addressed in a separate commit and also commented back on two of the comments:

PTAL

Copy link
Member

@spadgett spadgett left a 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 {
Copy link
Member

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 {
Copy link
Member

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.

http://getbem.com/

Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

@jhadvig
Copy link
Member Author

jhadvig commented Jun 26, 2018

@spadgett comments addressed. Thanks and PTAL :)

Copy link
Member

@spadgett spadgett left a 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: alphabetize

@jhadvig
Copy link
Member Author

jhadvig commented Jun 26, 2018

@spadgett comment addressed and squashed. Lets merge this baby 👍

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 26, 2018
@spadgett spadgett dismissed benjaminapetersen’s stale review June 26, 2018 16:40

Comments addressed

@spadgett
Copy link
Member

/refresh

@stevekuznetsov
Copy link

/retest

@openshift-merge-robot openshift-merge-robot merged commit c79042d into openshift:master Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants