fixed-workflow-view-layout
[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, withStyles } from '@material-ui/core';
7 import { FavoriteStar } from '../favorite-star/favorite-star';
8 import { ResourceKind, TrashableResource } from '~/models/resource';
9 import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, WorkflowIcon } from '~/components/icon/icon';
10 import { formatDate, formatFileSize } from '~/common/formatters';
11 import { resourceLabel } from '~/common/labels';
12 import { connect } from 'react-redux';
13 import { RootState } from '~/store/store';
14 import { getResource } from '~/store/resources/resources';
15 import { GroupContentsResource } from '~/services/groups-service/groups-service';
16 import { getProcess, Process, getProcessStatus, getProcessStatusColor } from '~/store/processes/process';
17 import { ArvadosTheme } from '~/common/custom-theme';
18 import { compose } from 'redux';
19 import { WorkflowResource } from '~/models/workflow';
20
21 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
22     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
23         <Grid item>
24             {renderIcon(item)}
25         </Grid>
26         <Grid item>
27             <Typography color="primary" style={{ width: '450px' }}>
28                 {item.name}
29             </Typography>
30         </Grid>
31         <Grid item>
32             <Typography variant="caption">
33                 <FavoriteStar resourceUuid={item.uuid} />
34             </Typography>
35         </Grid>
36     </Grid>;
37
38 export const ResourceName = connect(
39     (state: RootState, props: { uuid: string }) => {
40         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
41         return resource || { name: '', uuid: '', kind: '' };
42     })(renderName);
43
44 export const renderIcon = (item: { kind: string }) => {
45     switch (item.kind) {
46         case ResourceKind.PROJECT:
47             return <ProjectIcon />;
48         case ResourceKind.COLLECTION:
49             return <CollectionIcon />;
50         case ResourceKind.PROCESS:
51             return <ProcessIcon />;
52         case ResourceKind.WORKFLOW:
53             return <WorkflowIcon />;
54         default:
55             return <DefaultIcon />;
56     }
57 };
58
59 export const renderWorkflowName = (item: { name: string; uuid: string, kind: string }) =>
60     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
61         <Grid item>
62             {renderIcon(item)}
63         </Grid>
64         <Grid item>
65             <Typography color="primary" style={{ width: '100px' }}>
66                 {item.name}
67             </Typography>
68         </Grid>
69     </Grid>;
70
71 export const RosurceWorkflowName = connect(
72     (state: RootState, props: { uuid: string }) => {
73         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
74         return resource || { name: '', uuid: '', kind: '' };
75     })(renderWorkflowName);
76
77 export const renderDate = (date?: string) => {
78     return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
79 };
80
81 export const renderWorkflowStatus = () => {
82     return <Typography noWrap style={{ width: '60px' }}>{"Public"}</Typography>;
83 };
84
85 export const ResourceWorkflowStatus = connect(
86     (state: RootState, props: { uuid: string }) => {
87         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
88         return {};
89     })((props: { status?: string }) => renderWorkflowStatus());
90
91 export const ResourceLastModifiedDate = connect(
92     (state: RootState, props: { uuid: string }) => {
93         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
94         return { date: resource ? resource.modifiedAt : '' };
95     })((props: { date: string }) => renderDate(props.date));
96
97 export const ResourceTrashDate = connect(
98     (state: RootState, props: { uuid: string }) => {
99         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
100         return { date: resource ? resource.trashAt : '' };
101     })((props: { date: string }) => renderDate(props.date));
102
103 export const ResourceDeleteDate = connect(
104     (state: RootState, props: { uuid: string }) => {
105         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
106         return { date: resource ? resource.deleteAt : '' };
107     })((props: { date: string }) => renderDate(props.date));
108
109 export const renderFileSize = (fileSize?: number) =>
110     <Typography noWrap style={{ minWidth: '45px' }}>
111         {formatFileSize(fileSize)}
112     </Typography>;
113
114 export const ResourceFileSize = connect(
115     (state: RootState, props: { uuid: string }) => {
116         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
117         return {};
118     })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
119
120 export const renderOwner = (owner: string) =>
121     <Typography noWrap color="primary" >
122         {owner}
123     </Typography>;
124
125 export const ResourceOwner = connect(
126     (state: RootState, props: { uuid: string }) => {
127         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
128         return { owner: resource ? resource.ownerUuid : '' };
129     })((props: { owner: string }) => renderOwner(props.owner));
130
131 export const renderType = (type: string) =>
132     <Typography noWrap>
133         {resourceLabel(type)}
134     </Typography>;
135
136 export const ResourceType = connect(
137     (state: RootState, props: { uuid: string }) => {
138         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
139         return { type: resource ? resource.kind : '' };
140     })((props: { type: string }) => renderType(props.type));
141
142 export const ProcessStatus = compose(
143     connect((state: RootState, props: { uuid: string }) => {
144         return { process: getProcess(props.uuid)(state.resources) };
145     }),
146     withStyles({}, { withTheme: true }))
147     ((props: { process?: Process, theme: ArvadosTheme }) => {
148         const status = props.process ? getProcessStatus(props.process) : "-";
149         return <Typography
150             noWrap
151             align="center"
152             style={{ color: getProcessStatusColor(status, props.theme) }} >
153             {status}
154         </Typography>;
155     });