Merge branch '13494-collection-version-browser'
[arvados.git] / src / views-components / api-client-authorizations-dialog / help-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, DialogTitle, DialogContent, DialogActions, Button } from "@material-ui/core";
7 import { WithDialogProps } from "~/store/dialog/with-dialog";
8 import { withDialog } from '~/store/dialog/with-dialog';
9 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
10 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
11 import { ArvadosTheme } from '~/common/custom-theme';
12 import { compose } from "redux";
13 import { API_CLIENT_AUTHORIZATION_HELP_DIALOG } from '~/store/api-client-authorizations/api-client-authorizations-actions';
14
15 type CssRules = 'codeSnippet';
16
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
18     codeSnippet: {
19         borderRadius: theme.spacing.unit * 0.5,
20         border: `1px solid ${theme.palette.grey["400"]}`,
21         '& pre': {
22             fontSize: '0.815rem'
23         }
24     }
25 });
26
27 interface HelpApiClientAuthorizationDataProps {
28     apiHost: string;
29     apiToken: string;
30     email: string;
31 }
32
33 export const HelpApiClientAuthorizationDialog = compose(
34     withDialog(API_CLIENT_AUTHORIZATION_HELP_DIALOG),
35     withStyles(styles))(
36         (props: WithDialogProps<HelpApiClientAuthorizationDataProps> & WithStyles<CssRules>) =>
37             <Dialog open={props.open}
38                 onClose={props.closeDialog}
39                 fullWidth
40                 maxWidth='md'>
41                 <DialogTitle>HELP:</DialogTitle>
42                 <DialogContent>
43                     <DefaultCodeSnippet
44                         className={props.classes.codeSnippet}
45                         lines={[snippetText(props.data)]} />
46                         {/* // lines={snippetText2(props.data)} /> */}
47                 </DialogContent>
48                 <DialogActions>
49                     <Button
50                         variant='text'
51                         color='primary'
52                         onClick={props.closeDialog}>
53                         Close
54                 </Button>
55                 </DialogActions>
56             </Dialog>
57     );
58
59 const snippetText = (data: HelpApiClientAuthorizationDataProps) => `### Pasting the following lines at a shell prompt will allow Arvados SDKs
60 ### to authenticate to your account, ${data.email}
61
62 read ARVADOS_API_TOKEN <<EOF
63 ${data.apiToken}
64 EOF
65 export ARVADOS_API_TOKEN ARVADOS_API_HOST=${data.apiHost}
66 unset ARVADOS_API_HOST_INSECURE`;