Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
feat: added a new component to handle secrets
Browse files Browse the repository at this point in the history
Added a new component that enables to 'blur' the text and show the text
content if clicked
  • Loading branch information
ziccardi authored and secondsun committed Sep 16, 2020
1 parent 0fddbd9 commit 2c544ea
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/application/ApplicationDetail/SenderAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { snippet as java_snippet } from './snippets/sender/java';
import { snippet as node_snippet } from './snippets/sender/node';
import { snippet as curl_snippet } from './snippets/sender/curl';
import { links } from '../../links';
import { Secret } from '../../common/Secret';

interface State {
refreshSecret: boolean;
Expand Down Expand Up @@ -80,7 +81,7 @@ export class SenderAPI extends Component<Props, State> {
Master Secret:
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{this.props.app.masterSecret}
<Secret text={this.props.app.masterSecret} />
</TextListItem>

<TextListItem component={TextListItemVariants.dd}>
Expand Down
3 changes: 2 additions & 1 deletion src/application/ApplicationDetail/panels/VariantDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { IOSCertVariantDetails } from './ios_cert/iOSCertVariantDetails';
import { IOSCertCodeSnippets } from './ios_cert/iOSCertCodeSnippets';
import { WebPushVariantDetails } from './web_push/WebPushVariantDetails';
import { WebPushCodeSnippets } from './web_push/WebPushCodeSnippets';
import { Secret } from '../../../common/Secret';

interface Props {
app: PushApplication;
Expand Down Expand Up @@ -138,7 +139,7 @@ export class VariantDetails extends Component<Props, State> {
Variant Secret:
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{this.props.variant.secret}
<Secret text={this.props.variant.secret} />
</TextListItem>

<TextListItem component={TextListItemVariants.dd}>
Expand Down
66 changes: 66 additions & 0 deletions src/common/Secret.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { Component } from 'react';
import { Text, TextVariants, Tooltip } from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';

interface State {
visible: boolean;
}

interface Props {
text: string;
}

const hidden = {
color: 'transparent',
textShadow: '0 0 5px rgba(0,0,0,0.5)',
};

const visible = {
color: 'black',
};

export class Secret extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
visible: false,
};
}

render = () => {
const icon = () => {
if (this.state.visible) {
return (
<EyeSlashIcon
style={{
color: 'black',
verticalAlign: 'middle',
paddingBottom: 3,
}}
onClick={() => this.setState({ visible: false })}
/>
);
} else {
return (
<EyeIcon
style={{
color: 'black',
verticalAlign: 'middle',
paddingBottom: 3,
}}
onClick={() => this.setState({ visible: true })}
/>
);
}
};

return (
<Text
style={this.state.visible ? visible : hidden}
component={TextVariants.small}
>
{this.props.text}&nbsp;{icon()}
</Text>
);
};
}

0 comments on commit 2c544ea

Please sign in to comment.