Skip to content
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

frontend: Route Details - Updated TLS Settings to allow Copy and Mask settings #87

Merged
merged 1 commit into from Jun 8, 2018

Conversation

dtaylor113
Copy link
Contributor

@dtaylor113 dtaylor113 commented Jun 1, 2018

Updated TLS Settings section of Route Details page:
image

image

@openshift/team-ux-review

Related PRs for hide/reveal secrets; lots of design conversations:
#23
#50

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 1, 2018
@spadgett
Copy link
Member

spadgett commented Jun 1, 2018

Only key is sensitive. I'm not sure I'd conceal them all (even if we do in OpenShift console)

const { showSecret } = this.state;
const dl = [];
Object.keys(data || {}).sort().forEach(k => {
const value = window.atob(data[k]);
const value = type === 'route.openshift.io' ? data[k] : window.atob(data[k]);
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather not have a special check like this. We should generalize the component if we want to reuse it.

I think it's cleaner just not to use SecretData since it's only one field we want to mask.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this is still cluttered way to make a new array...(but that's a lingering comment).

Copy link
Member

Choose a reason for hiding this comment

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

+1 for generalizing component.

@spadgett
Copy link
Member

spadgett commented Jun 1, 2018

It would be nice to still be able to copy the other certs even if we don't mask them.

@dtaylor113 dtaylor113 changed the title frontend: Route Details - Added show/hide TLS certificates, keys [WIP] frontend: Route Details - Added show/hide TLS certificates, keys Jun 1, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 1, 2018
@spadgett
Copy link
Member

spadgett commented Jun 1, 2018

Suggest moving termination type and allow insecure traffic above the certificates

@jhadvig
Copy link
Member

jhadvig commented Jun 1, 2018

It would be nice to still be able to copy the other certs even if we don't mask them.

For that either use the ConfigMapData component or extract the functionality into a separate component which would be used for both for TLSSettings and ConfigMapData.

@spadgett
Copy link
Member

spadgett commented Jun 1, 2018

Why not just use the CopyToClipboard component directly?

jhadvig
jhadvig previously requested changes Jun 1, 2018
const { showSecret } = this.state;
const dl = [];
Object.keys(data || {}).sort().forEach(k => {
const value = window.atob(data[k]);
const value = type === 'route.openshift.io' ? data[k] : window.atob(data[k]);
Copy link
Member

Choose a reason for hiding this comment

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

+1 for generalizing component.

let secrets = _.omit(props.tls, ['termination', 'insecureEdgeTerminationPolicy']);

return <React.Fragment>
<SecretData heading="TLS Settings" data={secrets} type="route.openshift.io"/>
Copy link
Member

Choose a reason for hiding this comment

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

Switching to SecretData also changes properties to alphabetical order, which is not really what we want here.

@beanh66
Copy link
Member

beanh66 commented Jun 1, 2018

LGTM @dtaylor113

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 1, 2018
@dtaylor113 dtaylor113 changed the title [WIP] frontend: Route Details - Added show/hide TLS certificates, keys [WIP] frontend: Route Details - Updated TLS Settings to allow Copy and Mask settings Jun 1, 2018
@dtaylor113
Copy link
Contributor Author

Hi @spadgett, @beanh66, just updated code and screenshots. Only major difference is now we have field level hide/reveal, not sure of the placement of the 'hide/show' link though... @openshift/team-ux-review

@spadgett
Copy link
Member

spadgett commented Jun 1, 2018

This looks really complicated for what we want and we also lose the ordering of the fields. Is it possible to create a simple show/hide component we can use for the one field we want to hide? And just use CopyToClipboard directly for the other 3 fields?

@beanh66
Copy link
Member

beanh66 commented Jun 4, 2018

Agreed @spadgett

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 4, 2018
@dtaylor113
Copy link
Contributor Author

Hi @spadgett & @beanh66, updated code and screenshots. PTAL


return <React.Fragment>
<dt>{title} {value &&
<button className="btn btn-link co-mask-data__btn" style={{paddingLeft: '24px'}} type="button" onClick={this.toggleSecret}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't get co-mask-data__btn to reflect in the browser thus the hard-coded style=....

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather add a class and we can help you test if necessary. (We should figure out what's wrong in your environment, though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rather add a class as well, but at this point I can't even change an existing scss value. Here I changed top to 10px, but when I inspect it it still says 0:
image
When I click on the link to the .scss file, it does display the updated value:
image

I've tried starting/stopping server and dev, ./build.sh, ./build-frontend.sh, yarn run build, etc.. Very frustrating, I just can't get scss changes/additions to show up in browser :-(

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.

Can you add a screenshot?

<dt>CA Certificate</dt>
<dd>{props.tls.caCertificate || '-'}</dd>
<dd>{props.tls.caCertificate ? <CopyToClipboard value={props.tls.caCertificate}/> : '-'}</dd>
{_.get(props.tls, 'termination') === 'reencrypt' && <span>
Copy link
Member

Choose a reason for hiding this comment

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

not new, but this should be a React.Fragment instead of span

const visibleValue = showSecret ? value : <MaskedData /> ;

return <React.Fragment>
<dt>{title} {value &&
Copy link
Member

Choose a reason for hiding this comment

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

Let's not have the dt/dd be part of this. Better to make this just the value so that it can be used outside of a dl element.

export const MaskedData = () => <React.Fragment>
<span className="sr-only">Value hidden</span>
<span aria-hidden="true">&bull;&bull;&bull;&bull;&bull;</span>
</React.Fragment>;
Copy link
Member

Choose a reason for hiding this comment

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

Since this is exactly the same as the one in secret data, we should be able to reuse this there instead of copying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it from secretData to the new MaskData component, seems more appropriate in the new component.


return <React.Fragment>
<dt>{title} {value &&
<button className="btn btn-link co-mask-data__btn" style={{paddingLeft: '24px'}} type="button" onClick={this.toggleSecret}>
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather add a class and we can help you test if necessary. (We should figure out what's wrong in your environment, though.)

@dtaylor113
Copy link
Contributor Author

Hi @spadgett, I think this is the format you want. Also, I think the .scss problem I was having was some issue processing scss in a .jsx file and using it in a .tsx file?...if I had to guess. Now that I've declared the component in .tsx, rather than a separate component in a .jsx, my scss changes now appear in the browser.

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 @dtaylor113. This looks a lot simpler.

}

render() {
const { showPrivateKey } = this.state;
Copy link
Member

Choose a reason for hiding this comment

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

I'd add

const { tls } = this.props;

to avoid having to repeat this.props.tls everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

<dt>Certificate</dt>
<dd>{this.props.tls.certificate ? <CopyToClipboard value={this.props.tls.certificate}/> : '-'}</dd>
<dt>Key {this.props.tls.key &&
<button className="btn btn-link co-mask-data__btn" type="button" onClick={this.toggleKey}>
Copy link
Member

Choose a reason for hiding this comment

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

Do we want the button right-aligned like the secret page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a @openshift/team-ux-review question :-) My only concern is that perhaps users would think they would have to 'Reveal' the value in order to 'Copy' it -if the buttons are close together.

<dd>{this.props.tls.key ? <CopyToClipboard value={this.props.tls.key} visibleValue={visibleKeyValue}/> : '-'}</dd>
<dt>CA Certificate</dt>
<dd>{this.props.tls.caCertificate ? <CopyToClipboard value={this.props.tls.caCertificate}/> : '-'}</dd>
{_.get(this.props.tls, 'termination') === 'reencrypt' && <React.Fragment>
Copy link
Member

Choose a reason for hiding this comment

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

We already know tls is defined from above, so you don't need to use _.get.

{this.props.tls.termination === 'reencrypt' && <React.Fragment>

import { registerTemplate } from '../yaml-templates';
// eslint-disable-next-line no-unused-vars
import {K8sResourceKind, K8sResourceKindReference} from '../module/k8s';
import {SafetyFirst} from './safety-first';
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd change this lines 10-11 to have spaces inside the curly braces to use a consistent style as above.

@dtaylor113
Copy link
Contributor Author

Hi @beanh66, any update on this? I think we're just questioning whether the 'Reveal Value' link/button should be right-aligned over the Copy button. -thanks :-)

@beanh66
Copy link
Member

beanh66 commented Jun 5, 2018

@dtaylor113 yes can you change the reveal for an individual value to be right aligned and drop the word "value" since in this case it is clear which field you will be revealing.
group 35

@dtaylor113
Copy link
Contributor Author

can you change the reveal for an individual value to be right aligned and drop the word "value" since in this case it is clear which field you will be revealing

@beanh66 updated screenshots in PR description. -thanks!

@cshinn
Copy link

cshinn commented Jun 5, 2018

@dtaylor113 Looks good to me

@dtaylor113 dtaylor113 dismissed stale reviews from jhadvig and spadgett June 5, 2018 15:27

Code has significantly changed

@dtaylor113
Copy link
Contributor Author

@spadgett PTAL when you get a moment, thanks

<button className="btn btn-link co-m-route-tls-reveal__btn" type="button" onClick={this.toggleKey}>
{
showPrivateKey
? <React.Fragment><i className="fa fa-eye-slash" aria-hidden="true"></i> Hide</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.

Does this need a <React.Fragment> wrapper? I thought that was only necessary if you were going to render sibling nodes. It looks like you are returning a single <i> node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The <React.Fragment> encapsulates the icon and the text ('Hide' or 'Reveal')

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, i see it, sorry about that :)

const visibleKeyValue = showPrivateKey ? tls.key : <MaskedData /> ;

return !tls ? 'TLS is not enabled.'
: <dl>
Copy link
Contributor

Choose a reason for hiding this comment

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

Care to indent the <dt> under the <dl>?

return !tls ?
  'TLS is not enabled' :
  <dl>
      <dt>stuff</dt>
      <dt>things</dt>
  </dl>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
</span>;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Missed on the prev PR for this, but you might consider upgrading your _.each to a _.reduce & eliminate some bookkeeping in calcTrafficPercentage:

const calcTrafficPercentage = (weight: number, route: any) => {
  return _.reduce(route.spec.alternateBackends, (result, alternate) => {
    return result += alternate.weight;
  }, 0 + route.spec.to.weight);
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @benjaminapetersen, still trying to understand this formula. When I plug it in, all percentages come back as 100%:
image
Whereas, they should equal the Origin Console Route's Traffic table:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it:
image

let totalWeight = _.reduce(route.spec.alternateBackends, (result, alternate) => {
    return result += alternate.weight;
  }, 0 + route.spec.to.weight);

  return (weight/totalWeight*100).toFixed(1);

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for oops on syntax, didn't pull your code & test, but was just pointing out an alt to .each to abstract some of bookkeeping.

@dtaylor113
Copy link
Contributor Author

jenkins rebuild

let totalWeight = _.reduce(route.spec.alternateBackends, (result, alternate) => {
return result += alternate.weight;
}, 0 + route.spec.to.weight);

return (weight/totalWeight*100).toFixed(1);
Copy link
Member

Choose a reason for hiding this comment

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

@dtaylor113 Can you confirm it's not possible to set all weights to 0? Otherwise this could be a divide by zero error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weights can be set to 0, adjusted code to handle

@spadgett
Copy link
Member

spadgett commented Jun 6, 2018

Ignore the ci/* failures. It's a CI problem we're working to fix.

_.each(route.spec.alternateBackends, alternate => totalWeight += alternate.weight);
let totalWeight = _.reduce(route.spec.alternateBackends, (result, alternate) => {
return result += alternate.weight;
}, 0 + route.spec.to.weight);
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 0 +?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, fixed

return result += alternate.weight;
}, route.spec.to.weight);

return totalWeight ? (weight/totalWeight*100).toFixed(1) : (weight*100).toFixed(1);
Copy link
Member

Choose a reason for hiding this comment

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

If totalWeight is 0, we know weight is 0, too. So we can just return 0.

const percentage = totalWeight ? ((weight / totalWeight) * 100) : 0;
// Format to one decimal place.
return percentage.toFixed(1);

But if weight is 0, we can return early without calculating since percentage will always be 0. (We might just use - in that case since the function is already returning a string and I think it displays better.)

const calcTrafficPercentage = (weight: number, route: any) => {
  if (!weight) {
    return '-';
  }

Not new, but it's a little strange that we do some formatting here, but add the % below. toFixed already converts to a string, so we can't use the result as a number. Might as well add the % here.

const percentage = (weight / totalWeight) * 100;
// Format to one decimal place.
return `${percentage.toFixed(1)}%`;

(Sorry I should have caught that on previous review.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks Sam

totalWeight += route.spec.to.weight;
_.each(route.spec.alternateBackends, alternate => totalWeight += alternate.weight);
return (weight/totalWeight*100).toFixed(1);
let totalWeight = _.reduce(route.spec.alternateBackends, (result, alternate) => {
Copy link
Member

Choose a reason for hiding this comment

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

const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 7, 2018
@dtaylor113
Copy link
Contributor Author

Hi @spadgett, PTAL when you get a moment. -thanks

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

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 8, 2018
@dtaylor113 dtaylor113 merged commit 8928128 into openshift:master Jun 8, 2018
@dtaylor113 dtaylor113 deleted the routes-show-hide-certs branch January 16, 2019 14:43
christianvogt pushed a commit to christianvogt/console that referenced this pull request May 16, 2019
* added action and reducer for storing and updating activeApplication

* created application-switcher

* show nothing in title when app switcher is disabled

* remove application specific logic from label-dropdown

* fixed bugs in label-dropdown and dropdown

* show all apps when namespace is changed

* added changes according to review comments
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.

None yet

7 participants