21702: Merge branch 'main' into 21702-keep-web-replace_files
[arvados.git] / services / workbench2 / src / views-components / repository-attributes-dialog / repository-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 "@mui/material";
7 import { WithDialogProps } from "store/dialog/with-dialog";
8 import { withDialog } from 'store/dialog/with-dialog';
9 import { REPOSITORY_ATTRIBUTES_DIALOG } from "store/repositories/repositories-actions";
10 import { CustomStyleRulesCallback } from 'common/custom-theme';
11 import { WithStyles } from '@mui/styles';
12 import withStyles from '@mui/styles/withStyles';
13 import { ArvadosTheme } from 'common/custom-theme';
14 import { compose } from "redux";
15 import { RepositoryResource } from "models/repositories";
16
17 type CssRules = 'rightContainer' | 'leftContainer' | 'spacing';
18
19 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20     rightContainer: {
21         textAlign: 'right',
22         paddingRight: theme.spacing(2),
23         color: theme.palette.grey["500"]
24     },
25     leftContainer: {
26         textAlign: 'left',
27         paddingLeft: theme.spacing(2)
28     },
29     spacing: {
30         paddingTop: theme.spacing(2)
31     },
32 });
33
34 interface RepositoryAttributesDataProps {
35     repositoryData: RepositoryResource;
36 }
37
38 type RepositoryAttributesProps = RepositoryAttributesDataProps & WithStyles<CssRules>;
39
40 export const RepositoryAttributesDialog = compose(
41     withDialog(REPOSITORY_ATTRIBUTES_DIALOG),
42     withStyles(styles))(
43         (props: WithDialogProps<RepositoryAttributesProps> & RepositoryAttributesProps) =>
44             <Dialog open={props.open}
45                 onClose={props.closeDialog}
46                 fullWidth
47                 maxWidth="sm">
48                 <DialogTitle>Attributes</DialogTitle>
49                 <DialogContent>
50                     <Typography variant='body1' className={props.classes.spacing}>
51                         {props.data.repositoryData && attributes(props.data.repositoryData, props.classes)}
52                     </Typography>
53                 </DialogContent>
54                 <DialogActions>
55                     <Button
56                         variant='text'
57                         color='primary'
58                         onClick={props.closeDialog}>
59                         Close
60                 </Button>
61                 </DialogActions>
62             </Dialog>
63     );
64
65 const attributes = (repositoryData: RepositoryResource, classes: any) => {
66     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByUserUuid, name } = repositoryData;
67     return (
68         <span>
69             <Grid container direction="row">
70                 <Grid item xs={5} className={classes.rightContainer}>
71                     <Grid item>Name</Grid>
72                     <Grid item>Owner uuid</Grid>
73                     <Grid item>Created at</Grid>
74                     <Grid item>Modified at</Grid>
75                     <Grid item>Modified by user uuid</Grid>
76                     <Grid item>uuid</Grid>
77                 </Grid>
78                 <Grid item xs={7} className={classes.leftContainer}>
79                     <Grid item>{name}</Grid>
80                     <Grid item>{ownerUuid}</Grid>
81                     <Grid item>{createdAt}</Grid>
82                     <Grid item>{modifiedAt}</Grid>
83                     <Grid item>{modifiedByUserUuid}</Grid>
84                     <Grid item>{uuid}</Grid>
85                 </Grid>
86             </Grid>
87         </span>
88     );
89 };