Add typescript paths to top level folders
[arvados-workbench2.git] / src / views-components / data-explorer / renderers.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 { Grid, Typography } from '@material-ui/core';
7 import { FavoriteStar } from '../favorite-star/favorite-star';
8 import { ResourceKind } from '~/models/resource';
9 import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '~/components/icon/icon';
10 import { formatDate, formatFileSize } from '~/common/formatters';
11 import { resourceLabel } from '~/common/labels';
12
13
14 export const renderName = (item: {name: string; uuid: string, kind: string}) =>
15     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
16         <Grid item>
17             {renderIcon(item)}
18         </Grid>
19         <Grid item>
20             <Typography color="primary">
21                 {item.name}
22             </Typography>
23         </Grid>
24         <Grid item>
25             <Typography variant="caption">
26                 <FavoriteStar resourceUuid={item.uuid} />
27             </Typography>
28         </Grid>
29     </Grid>;
30
31
32 export const renderIcon = (item: {kind: string}) => {
33     switch (item.kind) {
34         case ResourceKind.PROJECT:
35             return <ProjectIcon />;
36         case ResourceKind.COLLECTION:
37             return <CollectionIcon />;
38         case ResourceKind.PROCESS:
39             return <ProcessIcon />;
40         default:
41             return <DefaultIcon />;
42     }
43 };
44
45 export const renderDate = (date: string) => {
46     return <Typography noWrap>{formatDate(date)}</Typography>;
47 };
48
49 export const renderFileSize = (fileSize?: number) =>
50     <Typography noWrap>
51         {formatFileSize(fileSize)}
52     </Typography>;
53
54 export const renderOwner = (owner: string) =>
55     <Typography noWrap color="primary" >
56         {owner}
57     </Typography>;
58
59 export const renderType = (type: string) =>
60     <Typography noWrap>
61         {resourceLabel(type)}
62     </Typography>;
63
64 export const renderStatus = (item: {status?: string}) =>
65     <Typography noWrap align="center" >
66         {item.status || "-"}
67     </Typography>;