Merge branch '14120-rich-text-editor'
[arvados-workbench2.git] / src / views-components / current-token-dialog / current-token-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { Dialog, DialogActions, DialogTitle, DialogContent, WithStyles, withStyles, StyleRulesCallback, Button, Typography, Paper } from '@material-ui/core';
7 import { ArvadosTheme } from '~/common/custom-theme';
8 import { withDialog } from '~/store/dialog/with-dialog';
9 import { WithDialogProps } from '~/store/dialog/with-dialog';
10 import { compose } from 'redux';
11 import { connect } from 'react-redux';
12 import { CurrentTokenDialogData, getCurrentTokenDialogData } from '~/store/current-token-dialog/current-token-dialog-actions';
13 import { RootState } from '~/store/store';
14 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
15
16 type CssRules = 'link' | 'paper' | 'button';
17
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19     link: {
20         color: theme.palette.primary.main,
21         textDecoration: 'none',
22         margin: '0px 4px'
23     },
24     paper: {
25         padding: theme.spacing.unit,
26         marginBottom: theme.spacing.unit * 2,
27         backgroundColor: theme.palette.grey["200"],
28         border: `1px solid ${theme.palette.grey["300"]}`
29     },
30     button: {
31         fontSize: '0.8125rem',
32         fontWeight: 600
33     }
34 });
35
36 type CurrentTokenProps = CurrentTokenDialogData & WithDialogProps<{}> & WithStyles<CssRules>;
37
38 export const CurrentTokenDialog = compose(
39     withStyles(styles),
40     connect(getCurrentTokenDialogData),
41     withDialog('currentTokenDialog')
42 )(class extends React.Component<CurrentTokenProps> {
43     render() {
44         const { classes, open, closeDialog, ...data } = this.props;
45         return <Dialog
46             open={open}
47             onClose={closeDialog}
48             fullWidth={true}
49             maxWidth='md'>
50             <DialogTitle>Current Token</DialogTitle>
51             <DialogContent>
52                 <Typography variant='body1' paragraph={true}>
53                     The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados with the proper permissions.
54                             <Typography component='p'>
55                         For more information see
56                                 <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>
57                             Getting an API token.
58                                 </a>
59                     </Typography>
60                 </Typography>
61                 <Typography variant='body1' paragraph={true}>
62                     Paste the following lines at a shell prompt to set up the necessary environment for Arvados SDKs to authenticate to your klingenc account.
63                         </Typography>
64                 <DefaultCodeSnippet lines={[getSnippet(data)]} />
65                 <Typography variant='body1'>
66                     Arvados
67                             <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>virtual machines</a>
68                     do this for you automatically. This setup is needed only when you use the API remotely (e.g., from your own workstation).
69                         </Typography>
70             </DialogContent>
71             <DialogActions>
72                 <Button onClick={closeDialog} className={classes.button} color="primary">CLOSE</Button>
73             </DialogActions>
74         </Dialog>;
75     }
76 }
77 );
78
79 const getSnippet = ({ apiHost, currentToken }: CurrentTokenDialogData) =>
80 `HISTIGNORE=$HISTIGNORE:'export ARVADOS_API_TOKEN=*'
81 export ARVADOS_API_TOKEN=${currentToken}
82 export ARVADOS_API_HOST=${apiHost}
83 unset ARVADOS_API_HOST_INSECURE`;