21720: replaced theme.spacing.unit * x with theme.spacing(x) everywhere
[arvados.git] / services / workbench2 / src / views-components / user-dialog / attributes-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Typography, Grid } from "@material-ui/core";
7 import { WithDialogProps } from "store/dialog/with-dialog";
8 import { withDialog } from 'store/dialog/with-dialog';
9 import { WithStyles, withStyles } from '@material-ui/core/styles';
10 import { ArvadosTheme } from 'common/custom-theme';
11 import { compose } from "redux";
12 import { USER_ATTRIBUTES_DIALOG } from "store/users/users-actions";
13 import { UserResource } from "models/user";
14
15 type CssRules = 'rightContainer' | 'leftContainer' | 'spacing';
16
17 const styles = withStyles<CssRules>((theme: ArvadosTheme) => ({
18     rightContainer: {
19         textAlign: 'right',
20         paddingRight: theme.spacing(2),
21         color: theme.palette.grey["500"]
22     },
23     leftContainer: {
24         textAlign: 'left',
25         paddingLeft: theme.spacing(2)
26     },
27     spacing: {
28         paddingTop: theme.spacing(2)
29     },
30 }));
31
32 interface UserAttributesDataProps {
33     data: UserResource;
34 }
35
36 type UserAttributesProps = UserAttributesDataProps & WithStyles<CssRules>;
37
38 export const UserAttributesDialog = compose(
39     withDialog(USER_ATTRIBUTES_DIALOG),
40     styles)(
41         (props: WithDialogProps<UserAttributesProps> & UserAttributesProps) =>
42             <Dialog open={props.open}
43                 onClose={props.closeDialog}
44                 fullWidth
45                 maxWidth="sm">
46                 <DialogTitle>Attributes</DialogTitle>
47                 <DialogContent>
48                     <Typography variant='body1' className={props.classes.spacing}>
49                         {props.data && attributes(props.data, props.classes)}
50                     </Typography>
51                 </DialogContent>
52                 <DialogActions>
53                     <Button
54                         variant='text'
55                         color='primary'
56                         onClick={props.closeDialog}>
57                         Close
58                 </Button>
59                 </DialogActions>
60             </Dialog>
61     );
62
63 const attributes = (user: UserResource, classes: any) => {
64     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid,
65         firstName, lastName, username, email, isActive, isAdmin } = user;
66     return (
67         <span>
68             <Grid container direction="row">
69                 <Grid item xs={5} className={classes.rightContainer}>
70                     {uuid && <Grid item>Uuid</Grid>}
71                     {firstName && <Grid item>First name</Grid>}
72                     {lastName && <Grid item>Last name</Grid>}
73                     {email && <Grid item>Email</Grid>}
74                     {username && <Grid item>Username</Grid>}
75                     {isActive && <Grid item>Is active</Grid>}
76                     {isAdmin && <Grid item>Is admin</Grid>}
77                     {createdAt && <Grid item>Created at</Grid>}
78                     {modifiedAt && <Grid item>Modified at</Grid>}
79                     {ownerUuid && <Grid item>Owner uuid</Grid>}
80                     {modifiedByUserUuid && <Grid item>Modified by user uuid</Grid>}
81                     {modifiedByClientUuid && <Grid item>Modified by client uuid</Grid>}
82                 </Grid>
83                 <Grid item xs={7} className={classes.leftContainer}>
84                     <Grid item>{uuid}</Grid>
85                     <Grid item>{firstName}</Grid>
86                     <Grid item>{lastName}</Grid>
87                     <Grid item>{email}</Grid>
88                     <Grid item>{username}</Grid>
89                     <Grid item>{isActive}</Grid>
90                     <Grid item>{isAdmin}</Grid>
91                     <Grid item>{createdAt}</Grid>
92                     <Grid item>{modifiedAt}</Grid>
93                     <Grid item>{ownerUuid}</Grid>
94                     <Grid item>{modifiedByUserUuid}</Grid>
95                     <Grid item>{modifiedByClientUuid}</Grid>
96                 </Grid>
97             </Grid>
98         </span>
99     );
100 };