18123: Display full name of group members in group edit
[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, 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, currentLabel)
295         ) : (
296                 <Typography noWrap color="default">
297                     {item.tailUuid}
298                 </Typography>
299             )}
300     </div>);
301 };
302
303 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
304     <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
305         {label}: {uuid}
306     </Typography>;
307
308 export const ResourceLinkTail = connect(
309     (state: RootState, props: { uuid: string }) => {
310         const resource = getResource<LinkResource>(props.uuid)(state.resources);
311         return {
312             item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
313         };
314     })((props: { item: any } & DispatchProp<any>) =>
315         renderLinkTail(props.dispatch, props.item));
316
317 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
318     renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
319
320 export const ResourceLinkHead = connect(
321     (state: RootState, props: { uuid: string }) => {
322         const resource = getResource<LinkResource>(props.uuid)(state.resources);
323         return {
324             item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
325         };
326     })((props: { item: any } & DispatchProp<any>) =>
327         renderLinkHead(props.dispatch, props.item));
328
329 export const ResourceLinkUuid = connect(
330     (state: RootState, props: { uuid: string }) => {
331         const resource = getResource<LinkResource>(props.uuid)(state.resources);
332         return resource || { uuid: '' };
333     })(renderUuid);
334
335 // Process Resources
336 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
337     return (
338         <div>
339             {uuid &&
340                 <Tooltip title="Run process">
341                     <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
342                         <ProcessIcon />
343                     </IconButton>
344                 </Tooltip>}
345         </div>
346     );
347 };
348
349 export const ResourceRunProcess = connect(
350     (state: RootState, props: { uuid: string }) => {
351         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
352         return {
353             uuid: resource ? resource.uuid : ''
354         };
355     })((props: { uuid: string } & DispatchProp<any>) =>
356         resourceRunProcess(props.dispatch, props.uuid));
357
358 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
359     if (ownerUuid === getPublicUuid(uuidPrefix)) {
360         return renderStatus(WorkflowStatus.PUBLIC);
361     } else {
362         return renderStatus(WorkflowStatus.PRIVATE);
363     }
364 };
365
366 const renderStatus = (status: string) =>
367     <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
368
369 export const ResourceWorkflowStatus = connect(
370     (state: RootState, props: { uuid: string }) => {
371         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
372         const uuidPrefix = getUuidPrefix(state);
373         return {
374             ownerUuid: resource ? resource.ownerUuid : '',
375             uuidPrefix
376         };
377     })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
378
379 export const ResourceLastModifiedDate = connect(
380     (state: RootState, props: { uuid: string }) => {
381         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
382         return { date: resource ? resource.modifiedAt : '' };
383     })((props: { date: string }) => renderDate(props.date));
384
385 export const ResourceCreatedAtDate = connect(
386     (state: RootState, props: { uuid: string }) => {
387         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
388         return { date: resource ? resource.createdAt : '' };
389     })((props: { date: string }) => renderDate(props.date));
390
391 export const ResourceTrashDate = connect(
392     (state: RootState, props: { uuid: string }) => {
393         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
394         return { date: resource ? resource.trashAt : '' };
395     })((props: { date: string }) => renderDate(props.date));
396
397 export const ResourceDeleteDate = connect(
398     (state: RootState, props: { uuid: string }) => {
399         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
400         return { date: resource ? resource.deleteAt : '' };
401     })((props: { date: string }) => renderDate(props.date));
402
403 export const renderFileSize = (fileSize?: number) =>
404     <Typography noWrap style={{ minWidth: '45px' }}>
405         {formatFileSize(fileSize)}
406     </Typography>;
407
408 export const ResourceFileSize = connect(
409     (state: RootState, props: { uuid: string }) => {
410         const resource = getResource<CollectionResource>(props.uuid)(state.resources);
411
412         if (resource && resource.kind !== ResourceKind.COLLECTION) {
413             return { fileSize: '' };
414         }
415
416         return { fileSize: resource ? resource.fileSizeTotal : 0 };
417     })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
418
419 const renderOwner = (owner: string) =>
420     <Typography noWrap>
421         {owner}
422     </Typography>;
423
424 export const ResourceOwner = connect(
425     (state: RootState, props: { uuid: string }) => {
426         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
427         return { owner: resource ? resource.ownerUuid : '' };
428     })((props: { owner: string }) => renderOwner(props.owner));
429
430 export const ResourceOwnerName = connect(
431     (state: RootState, props: { uuid: string }) => {
432         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
433         const ownerNameState = state.ownerName;
434         const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
435         return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
436     })((props: { owner: string }) => renderOwner(props.owner));
437
438 const userFromID =
439     connect(
440         (state: RootState, props: { uuid: string }) => {
441             let userFullname = '';
442             const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
443
444             if (resource) {
445                 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
446             }
447
448             return { uuid: props.uuid, userFullname };
449         });
450
451 export const ResourceOwnerWithName =
452     compose(
453         userFromID,
454         withStyles({}, { withTheme: true }))
455         ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
456             const { uuid, userFullname, dispatch, theme } = props;
457
458             if (userFullname === '') {
459                 dispatch<any>(loadResource(uuid, false));
460                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
461                     {uuid}
462                 </Typography>;
463             }
464
465             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
466                 {userFullname} ({uuid})
467             </Typography>;
468         });
469
470 export const UserNameFromID =
471     compose(userFromID)(
472         (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
473             const { uuid, userFullname, dispatch } = props;
474
475             if (userFullname === '') {
476                 dispatch<any>(loadResource(uuid, false));
477             }
478             return <span>
479                 {userFullname ? userFullname : uuid}
480             </span>;
481         });
482
483 export const ResponsiblePerson =
484     compose(
485         connect(
486             (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
487                 let responsiblePersonName: string = '';
488                 let responsiblePersonUUID: string = '';
489                 let responsiblePersonProperty: string = '';
490
491                 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
492                     let index = 0;
493                     const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
494
495                     while (!responsiblePersonProperty && keys[index]) {
496                         const key = keys[index];
497                         if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
498                             responsiblePersonProperty = key;
499                         }
500                         index++;
501                     }
502                 }
503
504                 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
505
506                 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
507                     responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
508                     resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
509                 }
510
511                 if (resource && resource.kind === ResourceKind.USER) {
512                     responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
513                 }
514
515                 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
516             }),
517         withStyles({}, { withTheme: true }))
518         ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
519             const { uuid, responsiblePersonName, parentRef, theme } = props;
520
521             if (!uuid && parentRef) {
522                 parentRef.style.display = 'none';
523                 return null;
524             } else if (parentRef) {
525                 parentRef.style.display = 'block';
526             }
527
528             if (!responsiblePersonName) {
529                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
530                     {uuid}
531                 </Typography>;
532             }
533
534             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
535                 {responsiblePersonName} ({uuid})
536                 </Typography>;
537         });
538
539 const renderType = (type: string, subtype: string) =>
540     <Typography noWrap>
541         {resourceLabel(type, subtype)}
542     </Typography>;
543
544 export const ResourceType = connect(
545     (state: RootState, props: { uuid: string }) => {
546         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
547         return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
548     })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
549
550 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
551     return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
552 })((props: { resource: GroupContentsResource }) =>
553     (props.resource && props.resource.kind === ResourceKind.COLLECTION)
554         ? <CollectionStatus uuid={props.resource.uuid} />
555         : <ProcessStatus uuid={props.resource.uuid} />
556 );
557
558 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
559     return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
560 })((props: { collection: CollectionResource }) =>
561     (props.collection.uuid !== props.collection.currentVersionUuid)
562         ? <Typography>version {props.collection.version}</Typography>
563         : <Typography>head version</Typography>
564 );
565
566 export const ProcessStatus = compose(
567     connect((state: RootState, props: { uuid: string }) => {
568         return { process: getProcess(props.uuid)(state.resources) };
569     }),
570     withStyles({}, { withTheme: true }))
571     ((props: { process?: Process, theme: ArvadosTheme }) => {
572         const status = props.process ? getProcessStatus(props.process) : "-";
573         return <Typography
574             noWrap
575             style={{ color: getProcessStatusColor(status, props.theme) }} >
576             {status}
577         </Typography>;
578     });
579
580 export const ProcessStartDate = connect(
581     (state: RootState, props: { uuid: string }) => {
582         const process = getProcess(props.uuid)(state.resources);
583         return { date: (process && process.container) ? process.container.startedAt : '' };
584     })((props: { date: string }) => renderDate(props.date));
585
586 export const renderRunTime = (time: number) =>
587     <Typography noWrap style={{ minWidth: '45px' }}>
588         {formatTime(time, true)}
589     </Typography>;
590
591 interface ContainerRunTimeProps {
592     process: Process;
593 }
594
595 interface ContainerRunTimeState {
596     runtime: number;
597 }
598
599 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
600     return { process: getProcess(props.uuid)(state.resources) };
601 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
602     private timer: any;
603
604     constructor(props: ContainerRunTimeProps) {
605         super(props);
606         this.state = { runtime: this.getRuntime() };
607     }
608
609     getRuntime() {
610         return this.props.process ? getProcessRuntime(this.props.process) : 0;
611     }
612
613     updateRuntime() {
614         this.setState({ runtime: this.getRuntime() });
615     }
616
617     componentDidMount() {
618         this.timer = setInterval(this.updateRuntime.bind(this), 5000);
619     }
620
621     componentWillUnmount() {
622         clearInterval(this.timer);
623     }
624
625     render() {
626         return renderRunTime(this.state.runtime);
627     }
628 });