Skip to content

Commit

Permalink
Merge pull request #561 from Zlendy/master
Browse files Browse the repository at this point in the history
Add copy app token button in web gui
  • Loading branch information
jmattheis committed May 9, 2023
2 parents a18970e + 8cfd827 commit 62a1c99
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ui/src/application/Applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import React, {ChangeEvent, Component, SFC} from 'react';
import ConfirmDialog from '../common/ConfirmDialog';
import DefaultPage from '../common/DefaultPage';
import Button from '@material-ui/core/Button';
import ToggleVisibility from '../common/ToggleVisibility';
import CopyableSecret from '../common/CopyableSecret';
import AddApplicationDialog from './AddApplicationDialog';
import {observer} from 'mobx-react';
import {observable} from 'mobx';
Expand Down Expand Up @@ -166,7 +166,7 @@ const Row: SFC<IRowProps> = observer(
</TableCell>
<TableCell>{name}</TableCell>
<TableCell>
<ToggleVisibility value={value} style={{display: 'flex', alignItems: 'center'}} />
<CopyableSecret value={value} style={{display: 'flex', alignItems: 'center'}} />
</TableCell>
<TableCell>{description}</TableCell>
<TableCell align="right" padding="none">
Expand Down
4 changes: 2 additions & 2 deletions ui/src/client/Clients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import React, {Component, SFC} from 'react';
import ConfirmDialog from '../common/ConfirmDialog';
import DefaultPage from '../common/DefaultPage';
import Button from '@material-ui/core/Button';
import ToggleVisibility from '../common/ToggleVisibility';
import AddClientDialog from './AddClientDialog';
import UpdateDialog from './UpdateClientDialog';
import {observer} from 'mobx-react';
import {observable} from 'mobx';
import {inject, Stores} from '../inject';
import {IClient} from '../types';
import CopyableSecret from '../common/CopyableSecret';

@observer
class Clients extends Component<Stores<'clientStore'>> {
Expand Down Expand Up @@ -114,7 +114,7 @@ const Row: SFC<IRowProps> = ({name, value, fEdit, fDelete}) => (
<TableRow>
<TableCell>{name}</TableCell>
<TableCell>
<ToggleVisibility
<CopyableSecret
value={value}
style={{display: 'flex', alignItems: 'center', width: 200}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import Visibility from '@material-ui/icons/Visibility';
import Copy from '@material-ui/icons/FileCopyOutlined';
import VisibilityOff from '@material-ui/icons/VisibilityOff';
import React, {Component, CSSProperties} from 'react';
import {Stores, inject} from '../inject';

interface IProps {
value: string;
Expand All @@ -13,14 +15,17 @@ interface IState {
visible: boolean;
}

class ToggleVisibility extends Component<IProps, IState> {
class CopyableSecret extends Component<IProps & Stores<'snackManager'>, IState> {
public state = {visible: false};

public render() {
const {value, style} = this.props;
const text = this.state.visible ? value : '•••••••••••••••';
return (
<div style={style}>
<IconButton onClick={this.copyToClipboard} title="Copy to clipboard">
<Copy />
</IconButton>
<IconButton onClick={this.toggleVisibility} className="toggle-visibility">
{this.state.visible ? <VisibilityOff /> : <Visibility />}
</IconButton>
Expand All @@ -30,6 +35,16 @@ class ToggleVisibility extends Component<IProps, IState> {
}

private toggleVisibility = () => this.setState({visible: !this.state.visible});
private copyToClipboard = async () => {
const {snackManager, value} = this.props;
try {
await navigator.clipboard.writeText(value);
snackManager.snack('Copied to clipboard');
} catch (error) {
console.error('Failed to copy to clipboard:', error);
snackManager.snack('Failed to copy to clipboard');
}
};
}

export default ToggleVisibility;
export default inject('snackManager')(CopyableSecret);
4 changes: 2 additions & 2 deletions ui/src/plugin/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TableRow from '@material-ui/core/TableRow';
import Settings from '@material-ui/icons/Settings';
import {Switch, Button} from '@material-ui/core';
import DefaultPage from '../common/DefaultPage';
import ToggleVisibility from '../common/ToggleVisibility';
import CopyableSecret from '../common/CopyableSecret';
import {observer} from 'mobx-react';
import {inject, Stores} from '../inject';
import {IPlugin} from '../types';
Expand Down Expand Up @@ -84,7 +84,7 @@ const Row: SFC<IRowProps> = observer(({name, id, token, enabled, fToggleStatus})
</TableCell>
<TableCell>{name}</TableCell>
<TableCell>
<ToggleVisibility value={token} style={{display: 'flex', alignItems: 'center'}} />
<CopyableSecret value={token} style={{display: 'flex', alignItems: 'center'}} />
</TableCell>
<TableCell align="right" padding="none">
<Link to={'/plugins/' + id}>
Expand Down

0 comments on commit 62a1c99

Please sign in to comment.