18123: Improve checking of group permission head type for permissions list
[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 React from 'react';
6 import { Grid, Typography, withStyles, Tooltip, IconButton, Checkbox } from '@material-ui/core';
7 import { FavoriteStar, PublicFavoriteStar } from '../favorite-star/favorite-star';
8 import { Resource, ResourceKind, TrashableResource } from 'models/resource';
9 import { ProjectIcon, FilterGroupIcon, CollectionIcon, ProcessIcon, DefaultIcon, ShareIcon, CollectionOldVersionIcon, WorkflowIcon } from 'components/icon/icon';
10 import { formatDate, formatFileSize, formatTime } from 'common/formatters';
11 import { resourceLabel } from 'common/labels';
12 import { connect, DispatchProp } 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, getProcessRuntime } from 'store/processes/process';
17 import { ArvadosTheme } from 'common/custom-theme';
18 import { compose, Dispatch } from 'redux';
19 import { WorkflowResource } from 'models/workflow';
20 import { ResourceStatus as WorkflowStatus } from 'views/workflow-panel/workflow-panel-view';
21 import { getUuidPrefix, openRunProcess } from 'store/workflow-panel/workflow-panel-actions';
22 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
23 import { getUserFullname, getUserDisplayName, User, UserResource } from 'models/user';
24 import { toggleIsActive, toggleIsAdmin } from 'store/users/users-actions';
25 import { LinkResource } from 'models/link';
26 import { navigateTo } from 'store/navigation/navigation-action';
27 import { withResourceData } from 'views-components/data-explorer/with-resources';
28 import { CollectionResource } from 'models/collection';
29 import { IllegalNamingWarning } from 'components/warning/warning';
30 import { loadResource } from 'store/resources/resources-actions';
31 import { GroupClass } from 'models/group';
32
33 const renderName = (dispatch: Dispatch, item: GroupContentsResource) =>
34     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
35         <Grid item>
36             {renderIcon(item)}
37         </Grid>
38         <Grid item>
39             <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
40                 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
41                     ? <IllegalNamingWarning name={item.name} />
42                     : null}
43                 {item.name}
44             </Typography>
45         </Grid>
46         <Grid item>
47             <Typography variant="caption">
48                 <FavoriteStar resourceUuid={item.uuid} />
49                 <PublicFavoriteStar resourceUuid={item.uuid} />
50             </Typography>
51         </Grid>
52     </Grid>;
53
54 export const ResourceName = connect(
55     (state: RootState, props: { uuid: string }) => {
56         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
57         return resource;
58     })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
59
60 const renderIcon = (item: GroupContentsResource) => {
61     switch (item.kind) {
62         case ResourceKind.PROJECT:
63             if (item.groupClass === GroupClass.FILTER) {
64                 return <FilterGroupIcon />;
65             }
66             return <ProjectIcon />;
67         case ResourceKind.COLLECTION:
68             if (item.uuid === item.currentVersionUuid) {
69                 return <CollectionIcon />;
70             }
71             return <CollectionOldVersionIcon />;
72         case ResourceKind.PROCESS:
73             return <ProcessIcon />;
74         case ResourceKind.WORKFLOW:
75             return <WorkflowIcon />;
76         default:
77             return <DefaultIcon />;
78     }
79 };
80
81 const renderDate = (date?: string) => {
82     return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
83 };
84
85 const renderWorkflowName = (item: WorkflowResource) =>
86     <Grid container alignItems="center" wrap="nowrap" spacing={16}>
87         <Grid item>
88             {renderIcon(item)}
89         </Grid>
90         <Grid item>
91             <Typography color="primary" style={{ width: '100px' }}>
92                 {item.name}
93             </Typography>
94         </Grid>
95     </Grid>;
96
97 export const ResourceWorkflowName = connect(
98     (state: RootState, props: { uuid: string }) => {
99         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
100         return resource;
101     })(renderWorkflowName);
102
103 const getPublicUuid = (uuidPrefix: string) => {
104     return `${uuidPrefix}-tpzed-anonymouspublic`;
105 };
106
107 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
108     const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
109     return (
110         <div>
111             {!isPublic && uuid &&
112                 <Tooltip title="Share">
113                     <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
114                         <ShareIcon />
115                     </IconButton>
116                 </Tooltip>
117             }
118         </div>
119     );
120 };
121
122 export const ResourceShare = connect(
123     (state: RootState, props: { uuid: string }) => {
124         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
125         const uuidPrefix = getUuidPrefix(state);
126         return {
127             uuid: resource ? resource.uuid : '',
128             ownerUuid: resource ? resource.ownerUuid : '',
129             uuidPrefix
130         };
131     })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
132         resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
133
134 // User Resources
135 const renderFirstName = (item: { firstName: string }) => {
136     return <Typography noWrap>{item.firstName}</Typography>;
137 };
138
139 export const ResourceFirstName = connect(
140     (state: RootState, props: { uuid: string }) => {
141         const resource = getResource<UserResource>(props.uuid)(state.resources);
142         return resource || { firstName: '' };
143     })(renderFirstName);
144
145 const renderLastName = (item: { lastName: string }) =>
146     <Typography noWrap>{item.lastName}</Typography>;
147
148 export const ResourceLastName = connect(
149     (state: RootState, props: { uuid: string }) => {
150         const resource = getResource<UserResource>(props.uuid)(state.resources);
151         return resource || { lastName: '' };
152     })(renderLastName);
153
154 const renderFullName = (item: { firstName: string, lastName: string }) =>
155     <Typography noWrap>{(item.firstName + " " + item.lastName).trim()}</Typography>;
156
157 export const ResourceFullName = connect(
158     (state: RootState, props: { uuid: string }) => {
159         const resource = getResource<UserResource>(props.uuid)(state.resources);
160         return resource || { firstName: '', lastName: '' };
161     })(renderFullName);
162
163
164 const renderUuid = (item: { uuid: string }) =>
165     <Typography noWrap>{item.uuid}</Typography>;
166
167 export const ResourceUuid = connect(
168     (state: RootState, props: { uuid: string }) => {
169         const resource = getResource<UserResource>(props.uuid)(state.resources);
170         return resource || { uuid: '' };
171     })(renderUuid);
172
173 const renderEmail = (item: { email: string }) =>
174     <Typography noWrap>{item.email}</Typography>;
175
176 export const ResourceEmail = connect(
177     (state: RootState, props: { uuid: string }) => {
178         const resource = getResource<UserResource>(props.uuid)(state.resources);
179         return resource || { email: '' };
180     })(renderEmail);
181
182 const renderIsActive = (props: { uuid: string, isActive: boolean, toggleIsActive: (uuid: string) => void }) =>
183     <Checkbox
184         color="primary"
185         checked={props.isActive}
186         onClick={() => props.toggleIsActive(props.uuid)} />;
187
188 export const ResourceIsActive = connect(
189     (state: RootState, props: { uuid: string }) => {
190         const resource = getResource<UserResource>(props.uuid)(state.resources);
191         return resource || { isActive: false };
192     }, { toggleIsActive }
193 )(renderIsActive);
194
195 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
196     <Checkbox
197         color="primary"
198         checked={props.isAdmin}
199         onClick={() => props.toggleIsAdmin(props.uuid)} />;
200
201 export const ResourceIsAdmin = connect(
202     (state: RootState, props: { uuid: string }) => {
203         const resource = getResource<UserResource>(props.uuid)(state.resources);
204         return resource || { isAdmin: false };
205     }, { toggleIsAdmin }
206 )(renderIsAdmin);
207
208 const renderUsername = (item: { username: string }) =>
209     <Typography noWrap>{item.username}</Typography>;
210
211 export const ResourceUsername = connect(
212     (state: RootState, props: { uuid: string }) => {
213         const resource = getResource<UserResource>(props.uuid)(state.resources);
214         return resource || { username: '' };
215     })(renderUsername);
216
217 // Common methods
218 const renderCommonData = (data: string) =>
219     <Typography noWrap>{data}</Typography>;
220
221 const renderCommonDate = (date: string) =>
222     <Typography noWrap>{formatDate(date)}</Typography>;
223
224 export const CommonUuid = withResourceData('uuid', renderCommonData);
225
226 // Api Client Authorizations
227 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
228
229 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
230
231 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
232
233 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
234
235 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
236
237 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
238
239 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
240
241 export const TokenScopes = withResourceData('scopes', renderCommonData);
242
243 export const TokenUserId = withResourceData('userId', renderCommonData);
244
245 const clusterColors = [
246     ['#f44336', '#fff'],
247     ['#2196f3', '#fff'],
248     ['#009688', '#fff'],
249     ['#cddc39', '#fff'],
250     ['#ff9800', '#fff']
251 ];
252
253 export const ResourceCluster = (props: { uuid: string }) => {
254     const CLUSTER_ID_LENGTH = 5;
255     const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
256     const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
257     const ci = pos >= CLUSTER_ID_LENGTH ? (((((
258         (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
259         + props.uuid.charCodeAt(2))
260         * props.uuid.charCodeAt(3))
261         + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
262     return <span style={{
263         backgroundColor: clusterColors[ci][0],
264         color: clusterColors[ci][1],
265         padding: "2px 7px",
266         borderRadius: 3
267     }}>{clusterId}</span>;
268 };
269
270 // Links Resources
271 const renderLinkName = (item: { name: string }) =>
272     <Typography noWrap>{item.name || '(none)'}</Typography>;
273
274 export const ResourceLinkName = connect(
275     (state: RootState, props: { uuid: string }) => {
276         const resource = getResource<LinkResource>(props.uuid)(state.resources);
277         return resource || { name: '' };
278     })(renderLinkName);
279
280 const renderLinkClass = (item: { linkClass: string }) =>
281     <Typography noWrap>{item.linkClass}</Typography>;
282
283 export const ResourceLinkClass = connect(
284     (state: RootState, props: { uuid: string }) => {
285         const resource = getResource<LinkResource>(props.uuid)(state.resources);
286         return resource || { linkClass: '' };
287     })(renderLinkClass);
288
289 // const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
290 //     const currentLabel = resourceLabel(item.tailKind);
291 //     const isUnknow = currentLabel === "Unknown";
292 //     return (<div>
293 //         {!isUnknow ? (
294 //             renderLink(dispatch, item.tailUuid, "name", currentLabel)
295 //         ) : (
296 //                 <Typography noWrap color="default">
297 //                     {item.tailUuid}
298 //                 </Typography>
299 //             )}
300 //     </div>);
301 // };
302
303 const renderLink = (dispatch: Dispatch, item: Resource) => {
304     var displayName = '';
305
306     if ((item as UserResource).kind == ResourceKind.USER
307           && typeof (item as UserResource).firstName !== 'undefined') {
308         // We can be sure the resource is UserResource
309         displayName = getUserDisplayName(item as UserResource);
310     } else {
311         displayName = (item as GroupContentsResource).name;
312     }
313
314     return <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
315         {resourceLabel(item.kind)}: {displayName || item.uuid}
316     </Typography>;
317 }
318
319 export const ResourceLinkTail = connect(
320     (state: RootState, props: { uuid: string }) => {
321         const resource = getResource<LinkResource>(props.uuid)(state.resources);
322         const tailResource = getResource<Resource>(resource?.tailUuid || '')(state.resources);
323
324         return {
325             item: tailResource || { uuid: resource?.tailUuid || '', kind: resource?.headKind || ResourceKind.NONE }
326         };
327     })((props: { item: Resource } & DispatchProp<any>) =>
328         renderLink(props.dispatch, props.item));
329
330 export const ResourceLinkHead = connect(
331     (state: RootState, props: { uuid: string }) => {
332         const resource = getResource<LinkResource>(props.uuid)(state.resources);
333         const headResource = getResource<Resource>(resource?.headUuid || '')(state.resources);
334
335         return {
336             item: headResource || { uuid: resource?.headUuid || '', kind: resource?.headKind || ResourceKind.NONE }
337         };
338     })((props: { item: Resource } & DispatchProp<any>) =>
339         renderLink(props.dispatch, props.item));
340
341 export const ResourceLinkUuid = connect(
342     (state: RootState, props: { uuid: string }) => {
343         const resource = getResource<LinkResource>(props.uuid)(state.resources);
344         return resource || { uuid: '' };
345     })(renderUuid);
346
347 // Process Resources
348 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
349     return (
350         <div>
351             {uuid &&
352                 <Tooltip title="Run process">
353                     <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
354                         <ProcessIcon />
355                     </IconButton>
356                 </Tooltip>}
357         </div>
358     );
359 };
360
361 export const ResourceRunProcess = connect(
362     (state: RootState, props: { uuid: string }) => {
363         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
364         return {
365             uuid: resource ? resource.uuid : ''
366         };
367     })((props: { uuid: string } & DispatchProp<any>) =>
368         resourceRunProcess(props.dispatch, props.uuid));
369
370 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
371     if (ownerUuid === getPublicUuid(uuidPrefix)) {
372         return renderStatus(WorkflowStatus.PUBLIC);
373     } else {
374         return renderStatus(WorkflowStatus.PRIVATE);
375     }
376 };
377
378 const renderStatus = (status: string) =>
379     <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
380
381 export const ResourceWorkflowStatus = connect(
382     (state: RootState, props: { uuid: string }) => {
383         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
384         const uuidPrefix = getUuidPrefix(state);
385         return {
386             ownerUuid: resource ? resource.ownerUuid : '',
387             uuidPrefix
388         };
389     })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
390
391 export const ResourceLastModifiedDate = connect(
392     (state: RootState, props: { uuid: string }) => {
393         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
394         return { date: resource ? resource.modifiedAt : '' };
395     })((props: { date: string }) => renderDate(props.date));
396
397 export const ResourceCreatedAtDate = connect(
398     (state: RootState, props: { uuid: string }) => {
399         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
400         return { date: resource ? resource.createdAt : '' };
401     })((props: { date: string }) => renderDate(props.date));
402
403 export const ResourceTrashDate = connect(
404     (state: RootState, props: { uuid: string }) => {
405         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
406         return { date: resource ? resource.trashAt : '' };
407     })((props: { date: string }) => renderDate(props.date));
408
409 export const ResourceDeleteDate = connect(
410     (state: RootState, props: { uuid: string }) => {
411         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
412         return { date: resource ? resource.deleteAt : '' };
413     })((props: { date: string }) => renderDate(props.date));
414
415 export const renderFileSize = (fileSize?: number) =>
416     <Typography noWrap style={{ minWidth: '45px' }}>
417         {formatFileSize(fileSize)}
418     </Typography>;
419
420 export const ResourceFileSize = connect(
421     (state: RootState, props: { uuid: string }) => {
422         const resource = getResource<CollectionResource>(props.uuid)(state.resources);
423
424         if (resource && resource.kind !== ResourceKind.COLLECTION) {
425             return { fileSize: '' };
426         }
427
428         return { fileSize: resource ? resource.fileSizeTotal : 0 };
429     })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
430
431 const renderOwner = (owner: string) =>
432     <Typography noWrap>
433         {owner}
434     </Typography>;
435
436 export const ResourceOwner = connect(
437     (state: RootState, props: { uuid: string }) => {
438         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
439         return { owner: resource ? resource.ownerUuid : '' };
440     })((props: { owner: string }) => renderOwner(props.owner));
441
442 export const ResourceOwnerName = connect(
443     (state: RootState, props: { uuid: string }) => {
444         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
445         const ownerNameState = state.ownerName;
446         const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
447         return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
448     })((props: { owner: string }) => renderOwner(props.owner));
449
450 const userFromID =
451     connect(
452         (state: RootState, props: { uuid: string }) => {
453             let userFullname = '';
454             const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
455
456             if (resource) {
457                 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
458             }
459
460             return { uuid: props.uuid, userFullname };
461         });
462
463 export const ResourceOwnerWithName =
464     compose(
465         userFromID,
466         withStyles({}, { withTheme: true }))
467         ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
468             const { uuid, userFullname, dispatch, theme } = props;
469
470             if (userFullname === '') {
471                 dispatch<any>(loadResource(uuid, false));
472                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
473                     {uuid}
474                 </Typography>;
475             }
476
477             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
478                 {userFullname} ({uuid})
479             </Typography>;
480         });
481
482 export const UserNameFromID =
483     compose(userFromID)(
484         (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
485             const { uuid, userFullname, dispatch } = props;
486
487             if (userFullname === '') {
488                 dispatch<any>(loadResource(uuid, false));
489             }
490             return <span>
491                 {userFullname ? userFullname : uuid}
492             </span>;
493         });
494
495 export const ResponsiblePerson =
496     compose(
497         connect(
498             (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
499                 let responsiblePersonName: string = '';
500                 let responsiblePersonUUID: string = '';
501                 let responsiblePersonProperty: string = '';
502
503                 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
504                     let index = 0;
505                     const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
506
507                     while (!responsiblePersonProperty && keys[index]) {
508                         const key = keys[index];
509                         if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
510                             responsiblePersonProperty = key;
511                         }
512                         index++;
513                     }
514                 }
515
516                 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
517
518                 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
519                     responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
520                     resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
521                 }
522
523                 if (resource && resource.kind === ResourceKind.USER) {
524                     responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
525                 }
526
527                 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
528             }),
529         withStyles({}, { withTheme: true }))
530         ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
531             const { uuid, responsiblePersonName, parentRef, theme } = props;
532
533             if (!uuid && parentRef) {
534                 parentRef.style.display = 'none';
535                 return null;
536             } else if (parentRef) {
537                 parentRef.style.display = 'block';
538             }
539
540             if (!responsiblePersonName) {
541                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
542                     {uuid}
543                 </Typography>;
544             }
545
546             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
547                 {responsiblePersonName} ({uuid})
548                 </Typography>;
549         });
550
551 const renderType = (type: string, subtype: string) =>
552     <Typography noWrap>
553         {resourceLabel(type, subtype)}
554     </Typography>;
555
556 export const ResourceType = connect(
557     (state: RootState, props: { uuid: string }) => {
558         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
559         return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
560     })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
561
562 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
563     return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
564 })((props: { resource: GroupContentsResource }) =>
565     (props.resource && props.resource.kind === ResourceKind.COLLECTION)
566         ? <CollectionStatus uuid={props.resource.uuid} />
567         : <ProcessStatus uuid={props.resource.uuid} />
568 );
569
570 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
571     return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
572 })((props: { collection: CollectionResource }) =>
573     (props.collection.uuid !== props.collection.currentVersionUuid)
574         ? <Typography>version {props.collection.version}</Typography>
575         : <Typography>head version</Typography>
576 );
577
578 export const ProcessStatus = compose(
579     connect((state: RootState, props: { uuid: string }) => {
580         return { process: getProcess(props.uuid)(state.resources) };
581     }),
582     withStyles({}, { withTheme: true }))
583     ((props: { process?: Process, theme: ArvadosTheme }) => {
584         const status = props.process ? getProcessStatus(props.process) : "-";
585         return <Typography
586             noWrap
587             style={{ color: getProcessStatusColor(status, props.theme) }} >
588             {status}
589         </Typography>;
590     });
591
592 export const ProcessStartDate = connect(
593     (state: RootState, props: { uuid: string }) => {
594         const process = getProcess(props.uuid)(state.resources);
595         return { date: (process && process.container) ? process.container.startedAt : '' };
596     })((props: { date: string }) => renderDate(props.date));
597
598 export const renderRunTime = (time: number) =>
599     <Typography noWrap style={{ minWidth: '45px' }}>
600         {formatTime(time, true)}
601     </Typography>;
602
603 interface ContainerRunTimeProps {
604     process: Process;
605 }
606
607 interface ContainerRunTimeState {
608     runtime: number;
609 }
610
611 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
612     return { process: getProcess(props.uuid)(state.resources) };
613 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
614     private timer: any;
615
616     constructor(props: ContainerRunTimeProps) {
617         super(props);
618         this.state = { runtime: this.getRuntime() };
619     }
620
621     getRuntime() {
622         return this.props.process ? getProcessRuntime(this.props.process) : 0;
623     }
624
625     updateRuntime() {
626         this.setState({ runtime: this.getRuntime() });
627     }
628
629     componentDidMount() {
630         this.timer = setInterval(this.updateRuntime.bind(this), 5000);
631     }
632
633     componentWillUnmount() {
634         clearInterval(this.timer);
635     }
636
637     render() {
638         return renderRunTime(this.state.runtime);
639     }
640 });