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