17532: Move collection details history modified by to its own row
[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 const renderFirstName = (item: { firstName: string }) => {
135     return <Typography noWrap>{item.firstName}</Typography>;
136 };
137
138 // User Resources
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 renderUuid = (item: { uuid: string }) =>
155     <Typography noWrap>{item.uuid}</Typography>;
156
157 export const ResourceUuid = connect(
158     (state: RootState, props: { uuid: string }) => {
159         const resource = getResource<UserResource>(props.uuid)(state.resources);
160         return resource || { uuid: '' };
161     })(renderUuid);
162
163 const renderEmail = (item: { email: string }) =>
164     <Typography noWrap>{item.email}</Typography>;
165
166 export const ResourceEmail = connect(
167     (state: RootState, props: { uuid: string }) => {
168         const resource = getResource<UserResource>(props.uuid)(state.resources);
169         return resource || { email: '' };
170     })(renderEmail);
171
172 const renderIsActive = (props: { uuid: string, isActive: boolean, toggleIsActive: (uuid: string) => void }) =>
173     <Checkbox
174         color="primary"
175         checked={props.isActive}
176         onClick={() => props.toggleIsActive(props.uuid)} />;
177
178 export const ResourceIsActive = connect(
179     (state: RootState, props: { uuid: string }) => {
180         const resource = getResource<UserResource>(props.uuid)(state.resources);
181         return resource || { isActive: false };
182     }, { toggleIsActive }
183 )(renderIsActive);
184
185 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
186     <Checkbox
187         color="primary"
188         checked={props.isAdmin}
189         onClick={() => props.toggleIsAdmin(props.uuid)} />;
190
191 export const ResourceIsAdmin = connect(
192     (state: RootState, props: { uuid: string }) => {
193         const resource = getResource<UserResource>(props.uuid)(state.resources);
194         return resource || { isAdmin: false };
195     }, { toggleIsAdmin }
196 )(renderIsAdmin);
197
198 const renderUsername = (item: { username: string }) =>
199     <Typography noWrap>{item.username}</Typography>;
200
201 export const ResourceUsername = connect(
202     (state: RootState, props: { uuid: string }) => {
203         const resource = getResource<UserResource>(props.uuid)(state.resources);
204         return resource || { username: '' };
205     })(renderUsername);
206
207 // Common methods
208 const renderCommonData = (data: string) =>
209     <Typography noWrap>{data}</Typography>;
210
211 const renderCommonDate = (date: string) =>
212     <Typography noWrap>{formatDate(date)}</Typography>;
213
214 export const CommonUuid = withResourceData('uuid', renderCommonData);
215
216 // Api Client Authorizations
217 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
218
219 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
220
221 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
222
223 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
224
225 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
226
227 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
228
229 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
230
231 export const TokenScopes = withResourceData('scopes', renderCommonData);
232
233 export const TokenUserId = withResourceData('userId', renderCommonData);
234
235 const clusterColors = [
236     ['#f44336', '#fff'],
237     ['#2196f3', '#fff'],
238     ['#009688', '#fff'],
239     ['#cddc39', '#fff'],
240     ['#ff9800', '#fff']
241 ];
242
243 export const ResourceCluster = (props: { uuid: string }) => {
244     const CLUSTER_ID_LENGTH = 5;
245     const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
246     const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
247     const ci = pos >= CLUSTER_ID_LENGTH ? (((((
248         (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
249         + props.uuid.charCodeAt(2))
250         * props.uuid.charCodeAt(3))
251         + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
252     return <span style={{
253         backgroundColor: clusterColors[ci][0],
254         color: clusterColors[ci][1],
255         padding: "2px 7px",
256         borderRadius: 3
257     }}>{clusterId}</span>;
258 };
259
260 // Links Resources
261 const renderLinkName = (item: { name: string }) =>
262     <Typography noWrap>{item.name || '(none)'}</Typography>;
263
264 export const ResourceLinkName = connect(
265     (state: RootState, props: { uuid: string }) => {
266         const resource = getResource<LinkResource>(props.uuid)(state.resources);
267         return resource || { name: '' };
268     })(renderLinkName);
269
270 const renderLinkClass = (item: { linkClass: string }) =>
271     <Typography noWrap>{item.linkClass}</Typography>;
272
273 export const ResourceLinkClass = connect(
274     (state: RootState, props: { uuid: string }) => {
275         const resource = getResource<LinkResource>(props.uuid)(state.resources);
276         return resource || { linkClass: '' };
277     })(renderLinkClass);
278
279 const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
280     const currentLabel = resourceLabel(item.tailKind);
281     const isUnknow = currentLabel === "Unknown";
282     return (<div>
283         {!isUnknow ? (
284             renderLink(dispatch, item.tailUuid, currentLabel)
285         ) : (
286                 <Typography noWrap color="default">
287                     {item.tailUuid}
288                 </Typography>
289             )}
290     </div>);
291 };
292
293 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
294     <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
295         {label}: {uuid}
296     </Typography>;
297
298 export const ResourceLinkTail = connect(
299     (state: RootState, props: { uuid: string }) => {
300         const resource = getResource<LinkResource>(props.uuid)(state.resources);
301         return {
302             item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
303         };
304     })((props: { item: any } & DispatchProp<any>) =>
305         renderLinkTail(props.dispatch, props.item));
306
307 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
308     renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
309
310 export const ResourceLinkHead = connect(
311     (state: RootState, props: { uuid: string }) => {
312         const resource = getResource<LinkResource>(props.uuid)(state.resources);
313         return {
314             item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
315         };
316     })((props: { item: any } & DispatchProp<any>) =>
317         renderLinkHead(props.dispatch, props.item));
318
319 export const ResourceLinkUuid = connect(
320     (state: RootState, props: { uuid: string }) => {
321         const resource = getResource<LinkResource>(props.uuid)(state.resources);
322         return resource || { uuid: '' };
323     })(renderUuid);
324
325 // Process Resources
326 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
327     return (
328         <div>
329             {uuid &&
330                 <Tooltip title="Run process">
331                     <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
332                         <ProcessIcon />
333                     </IconButton>
334                 </Tooltip>}
335         </div>
336     );
337 };
338
339 export const ResourceRunProcess = connect(
340     (state: RootState, props: { uuid: string }) => {
341         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
342         return {
343             uuid: resource ? resource.uuid : ''
344         };
345     })((props: { uuid: string } & DispatchProp<any>) =>
346         resourceRunProcess(props.dispatch, props.uuid));
347
348 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
349     if (ownerUuid === getPublicUuid(uuidPrefix)) {
350         return renderStatus(WorkflowStatus.PUBLIC);
351     } else {
352         return renderStatus(WorkflowStatus.PRIVATE);
353     }
354 };
355
356 const renderStatus = (status: string) =>
357     <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
358
359 export const ResourceWorkflowStatus = connect(
360     (state: RootState, props: { uuid: string }) => {
361         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
362         const uuidPrefix = getUuidPrefix(state);
363         return {
364             ownerUuid: resource ? resource.ownerUuid : '',
365             uuidPrefix
366         };
367     })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
368
369 export const ResourceLastModifiedDate = connect(
370     (state: RootState, props: { uuid: string }) => {
371         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
372         return { date: resource ? resource.modifiedAt : '' };
373     })((props: { date: string }) => renderDate(props.date));
374
375 export const ResourceCreatedAtDate = connect(
376     (state: RootState, props: { uuid: string }) => {
377         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
378         return { date: resource ? resource.createdAt : '' };
379     })((props: { date: string }) => renderDate(props.date));
380
381 export const ResourceTrashDate = connect(
382     (state: RootState, props: { uuid: string }) => {
383         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
384         return { date: resource ? resource.trashAt : '' };
385     })((props: { date: string }) => renderDate(props.date));
386
387 export const ResourceDeleteDate = connect(
388     (state: RootState, props: { uuid: string }) => {
389         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
390         return { date: resource ? resource.deleteAt : '' };
391     })((props: { date: string }) => renderDate(props.date));
392
393 export const renderFileSize = (fileSize?: number) =>
394     <Typography noWrap style={{ minWidth: '45px' }}>
395         {formatFileSize(fileSize)}
396     </Typography>;
397
398 export const ResourceFileSize = connect(
399     (state: RootState, props: { uuid: string }) => {
400         const resource = getResource<CollectionResource>(props.uuid)(state.resources);
401
402         if (resource && resource.kind !== ResourceKind.COLLECTION) {
403             return { fileSize: '' };
404         }
405
406         return { fileSize: resource ? resource.fileSizeTotal : 0 };
407     })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
408
409 const renderOwner = (owner: string) =>
410     <Typography noWrap>
411         {owner}
412     </Typography>;
413
414 export const ResourceOwner = connect(
415     (state: RootState, props: { uuid: string }) => {
416         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
417         return { owner: resource ? resource.ownerUuid : '' };
418     })((props: { owner: string }) => renderOwner(props.owner));
419
420 export const ResourceOwnerName = connect(
421     (state: RootState, props: { uuid: string }) => {
422         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
423         const ownerNameState = state.ownerName;
424         const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
425         return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
426     })((props: { owner: string }) => renderOwner(props.owner));
427
428 const userFromID =
429     connect(
430         (state: RootState, props: { uuid: string }) => {
431             let userFullname = '';
432             const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
433
434             if (resource) {
435                 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
436             }
437
438             return { uuid: props.uuid, userFullname };
439         });
440
441 export const ResourceOwnerWithName =
442     compose(
443         userFromID,
444         withStyles({}, { withTheme: true }))
445         ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
446             const { uuid, userFullname, dispatch, theme } = props;
447
448             if (userFullname === '') {
449                 dispatch<any>(loadResource(uuid, false));
450                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
451                     {uuid}
452                 </Typography>;
453             }
454
455             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
456                 {userFullname} ({uuid})
457             </Typography>;
458         });
459
460 export const UserNameFromID =
461     compose(userFromID)(
462         (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
463             const { uuid, userFullname, dispatch } = props;
464
465             if (userFullname === '') {
466                 dispatch<any>(loadResource(uuid, false));
467             }
468             return <span>
469                 {userFullname ? userFullname : uuid}
470             </span>;
471         });
472
473 export const ResponsiblePerson =
474     compose(
475         connect(
476             (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
477                 let responsiblePersonName: string = '';
478                 let responsiblePersonUUID: string = '';
479                 let responsiblePersonProperty: string = '';
480
481                 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
482                     let index = 0;
483                     const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
484
485                     while (!responsiblePersonProperty && keys[index]) {
486                         const key = keys[index];
487                         if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
488                             responsiblePersonProperty = key;
489                         }
490                         index++;
491                     }
492                 }
493
494                 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
495
496                 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
497                     responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
498                     resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
499                 }
500
501                 if (resource && resource.kind === ResourceKind.USER) {
502                     responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
503                 }
504
505                 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
506             }),
507         withStyles({}, { withTheme: true }))
508         ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
509             const { uuid, responsiblePersonName, parentRef, theme } = props;
510
511             if (!uuid && parentRef) {
512                 parentRef.style.display = 'none';
513                 return null;
514             } else if (parentRef) {
515                 parentRef.style.display = 'block';
516             }
517
518             if (!responsiblePersonName) {
519                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
520                     {uuid}
521                 </Typography>;
522             }
523
524             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
525                 {responsiblePersonName} ({uuid})
526                 </Typography>;
527         });
528
529 const renderType = (type: string, subtype: string) =>
530     <Typography noWrap>
531         {resourceLabel(type, subtype)}
532     </Typography>;
533
534 export const ResourceType = connect(
535     (state: RootState, props: { uuid: string }) => {
536         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
537         return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
538     })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
539
540 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
541     return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
542 })((props: { resource: GroupContentsResource }) =>
543     (props.resource && props.resource.kind === ResourceKind.COLLECTION)
544         ? <CollectionStatus uuid={props.resource.uuid} />
545         : <ProcessStatus uuid={props.resource.uuid} />
546 );
547
548 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
549     return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
550 })((props: { collection: CollectionResource }) =>
551     (props.collection.uuid !== props.collection.currentVersionUuid)
552         ? <Typography>version {props.collection.version}</Typography>
553         : <Typography>head version</Typography>
554 );
555
556 export const ProcessStatus = compose(
557     connect((state: RootState, props: { uuid: string }) => {
558         return { process: getProcess(props.uuid)(state.resources) };
559     }),
560     withStyles({}, { withTheme: true }))
561     ((props: { process?: Process, theme: ArvadosTheme }) => {
562         const status = props.process ? getProcessStatus(props.process) : "-";
563         return <Typography
564             noWrap
565             style={{ color: getProcessStatusColor(status, props.theme) }} >
566             {status}
567         </Typography>;
568     });
569
570 export const ProcessStartDate = connect(
571     (state: RootState, props: { uuid: string }) => {
572         const process = getProcess(props.uuid)(state.resources);
573         return { date: (process && process.container) ? process.container.startedAt : '' };
574     })((props: { date: string }) => renderDate(props.date));
575
576 export const renderRunTime = (time: number) =>
577     <Typography noWrap style={{ minWidth: '45px' }}>
578         {formatTime(time, true)}
579     </Typography>;
580
581 interface ContainerRunTimeProps {
582     process: Process;
583 }
584
585 interface ContainerRunTimeState {
586     runtime: number;
587 }
588
589 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
590     return { process: getProcess(props.uuid)(state.resources) };
591 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
592     private timer: any;
593
594     constructor(props: ContainerRunTimeProps) {
595         super(props);
596         this.state = { runtime: this.getRuntime() };
597     }
598
599     getRuntime() {
600         return this.props.process ? getProcessRuntime(this.props.process) : 0;
601     }
602
603     updateRuntime() {
604         this.setState({ runtime: this.getRuntime() });
605     }
606
607     componentDidMount() {
608         this.timer = setInterval(this.updateRuntime.bind(this), 5000);
609     }
610
611     componentWillUnmount() {
612         clearInterval(this.timer);
613     }
614
615     render() {
616         return renderRunTime(this.state.runtime);
617     }
618 });