17782: Fixes absolute import paths from '~/somedir/...' to 'somedir/...'
[arvados-workbench2.git] / src / views-components / data-explorer / renderers.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { Grid, Typography, withStyles, 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 // Compute Node Resources
236 const renderNodeInfo = (data: string) => {
237     return <Typography>{JSON.stringify(data, null, 4)}</Typography>;
238 };
239
240 const clusterColors = [
241     ['#f44336', '#fff'],
242     ['#2196f3', '#fff'],
243     ['#009688', '#fff'],
244     ['#cddc39', '#fff'],
245     ['#ff9800', '#fff']
246 ];
247
248 export const ResourceCluster = (props: { uuid: string }) => {
249     const CLUSTER_ID_LENGTH = 5;
250     const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
251     const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
252     const ci = pos >= CLUSTER_ID_LENGTH ? (((((
253         (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
254         + props.uuid.charCodeAt(2))
255         * props.uuid.charCodeAt(3))
256         + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
257     return <span style={{
258         backgroundColor: clusterColors[ci][0],
259         color: clusterColors[ci][1],
260         padding: "2px 7px",
261         borderRadius: 3
262     }}>{clusterId}</span>;
263 };
264
265 export const ComputeNodeInfo = withResourceData('info', renderNodeInfo);
266
267 export const ComputeNodeDomain = withResourceData('domain', renderCommonData);
268
269 export const ComputeNodeFirstPingAt = withResourceData('firstPingAt', renderCommonDate);
270
271 export const ComputeNodeHostname = withResourceData('hostname', renderCommonData);
272
273 export const ComputeNodeIpAddress = withResourceData('ipAddress', renderCommonData);
274
275 export const ComputeNodeJobUuid = withResourceData('jobUuid', renderCommonData);
276
277 export const ComputeNodeLastPingAt = withResourceData('lastPingAt', renderCommonDate);
278
279 // Links Resources
280 const renderLinkName = (item: { name: string }) =>
281     <Typography noWrap>{item.name || '(none)'}</Typography>;
282
283 export const ResourceLinkName = connect(
284     (state: RootState, props: { uuid: string }) => {
285         const resource = getResource<LinkResource>(props.uuid)(state.resources);
286         return resource || { name: '' };
287     })(renderLinkName);
288
289 const renderLinkClass = (item: { linkClass: string }) =>
290     <Typography noWrap>{item.linkClass}</Typography>;
291
292 export const ResourceLinkClass = connect(
293     (state: RootState, props: { uuid: string }) => {
294         const resource = getResource<LinkResource>(props.uuid)(state.resources);
295         return resource || { linkClass: '' };
296     })(renderLinkClass);
297
298 const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
299     const currentLabel = resourceLabel(item.tailKind);
300     const isUnknow = currentLabel === "Unknown";
301     return (<div>
302         {!isUnknow ? (
303             renderLink(dispatch, item.tailUuid, currentLabel)
304         ) : (
305                 <Typography noWrap color="default">
306                     {item.tailUuid}
307                 </Typography>
308             )}
309     </div>);
310 };
311
312 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
313     <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
314         {label}: {uuid}
315     </Typography>;
316
317 export const ResourceLinkTail = connect(
318     (state: RootState, props: { uuid: string }) => {
319         const resource = getResource<LinkResource>(props.uuid)(state.resources);
320         return {
321             item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
322         };
323     })((props: { item: any } & DispatchProp<any>) =>
324         renderLinkTail(props.dispatch, props.item));
325
326 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
327     renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
328
329 export const ResourceLinkHead = connect(
330     (state: RootState, props: { uuid: string }) => {
331         const resource = getResource<LinkResource>(props.uuid)(state.resources);
332         return {
333             item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
334         };
335     })((props: { item: any } & DispatchProp<any>) =>
336         renderLinkHead(props.dispatch, props.item));
337
338 export const ResourceLinkUuid = connect(
339     (state: RootState, props: { uuid: string }) => {
340         const resource = getResource<LinkResource>(props.uuid)(state.resources);
341         return resource || { uuid: '' };
342     })(renderUuid);
343
344 // Process Resources
345 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
346     return (
347         <div>
348             {uuid &&
349                 <Tooltip title="Run process">
350                     <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
351                         <ProcessIcon />
352                     </IconButton>
353                 </Tooltip>}
354         </div>
355     );
356 };
357
358 export const ResourceRunProcess = connect(
359     (state: RootState, props: { uuid: string }) => {
360         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
361         return {
362             uuid: resource ? resource.uuid : ''
363         };
364     })((props: { uuid: string } & DispatchProp<any>) =>
365         resourceRunProcess(props.dispatch, props.uuid));
366
367 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
368     if (ownerUuid === getPublicUuid(uuidPrefix)) {
369         return renderStatus(WorkflowStatus.PUBLIC);
370     } else {
371         return renderStatus(WorkflowStatus.PRIVATE);
372     }
373 };
374
375 const renderStatus = (status: string) =>
376     <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
377
378 export const ResourceWorkflowStatus = connect(
379     (state: RootState, props: { uuid: string }) => {
380         const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
381         const uuidPrefix = getUuidPrefix(state);
382         return {
383             ownerUuid: resource ? resource.ownerUuid : '',
384             uuidPrefix
385         };
386     })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
387
388 export const ResourceLastModifiedDate = connect(
389     (state: RootState, props: { uuid: string }) => {
390         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
391         return { date: resource ? resource.modifiedAt : '' };
392     })((props: { date: string }) => renderDate(props.date));
393
394 export const ResourceCreatedAtDate = connect(
395     (state: RootState, props: { uuid: string }) => {
396         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
397         return { date: resource ? resource.createdAt : '' };
398     })((props: { date: string }) => renderDate(props.date));
399
400 export const ResourceTrashDate = connect(
401     (state: RootState, props: { uuid: string }) => {
402         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
403         return { date: resource ? resource.trashAt : '' };
404     })((props: { date: string }) => renderDate(props.date));
405
406 export const ResourceDeleteDate = connect(
407     (state: RootState, props: { uuid: string }) => {
408         const resource = getResource<TrashableResource>(props.uuid)(state.resources);
409         return { date: resource ? resource.deleteAt : '' };
410     })((props: { date: string }) => renderDate(props.date));
411
412 export const renderFileSize = (fileSize?: number) =>
413     <Typography noWrap style={{ minWidth: '45px' }}>
414         {formatFileSize(fileSize)}
415     </Typography>;
416
417 export const ResourceFileSize = connect(
418     (state: RootState, props: { uuid: string }) => {
419         const resource = getResource<CollectionResource>(props.uuid)(state.resources);
420
421         if (resource && resource.kind !== ResourceKind.COLLECTION) {
422             return { fileSize: '' };
423         }
424
425         return { fileSize: resource ? resource.fileSizeTotal : 0 };
426     })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
427
428 const renderOwner = (owner: string) =>
429     <Typography noWrap>
430         {owner}
431     </Typography>;
432
433 export const ResourceOwner = connect(
434     (state: RootState, props: { uuid: string }) => {
435         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
436         return { owner: resource ? resource.ownerUuid : '' };
437     })((props: { owner: string }) => renderOwner(props.owner));
438
439 export const ResourceOwnerName = connect(
440     (state: RootState, props: { uuid: string }) => {
441         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
442         const ownerNameState = state.ownerName;
443         const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
444         return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
445     })((props: { owner: string }) => renderOwner(props.owner));
446
447 export const ResourceOwnerWithName =
448     compose(
449         connect(
450             (state: RootState, props: { uuid: string }) => {
451                 let ownerName = '';
452                 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
453
454                 if (resource) {
455                     ownerName = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
456                 }
457
458                 return { uuid: props.uuid, ownerName };
459             }),
460         withStyles({}, { withTheme: true }))
461         ((props: { uuid: string, ownerName: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
462             const { uuid, ownerName, dispatch, theme } = props;
463
464             if (ownerName === '') {
465                 dispatch<any>(loadResource(uuid, false));
466                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
467                     {uuid}
468                 </Typography>;
469             }
470
471             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
472                 {ownerName} ({uuid})
473             </Typography>;
474         });
475
476 export const ResponsiblePerson =
477     compose(
478         connect(
479             (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
480                 let responsiblePersonName = null;
481                 let responsiblePersonUUID = null;
482                 let responsiblePersonProperty = null;
483
484                 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
485                     let index = 0;
486                     const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
487
488                     while (!responsiblePersonProperty && keys[index]) {
489                         const key = keys[index];
490                         if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
491                             responsiblePersonProperty = key;
492                         }
493                         index++;
494                     }
495                 }
496
497                 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
498
499                 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
500                     responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
501                     resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
502                 }
503
504                 if (resource && resource.kind === ResourceKind.USER) {
505                     responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
506                 }
507
508                 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
509             }),
510         withStyles({}, { withTheme: true }))
511         ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
512             const { uuid, responsiblePersonName, parentRef, theme } = props;
513
514             if (!uuid && parentRef) {
515                 parentRef.style.display = 'none';
516                 return null;
517             } else if (parentRef) {
518                 parentRef.style.display = 'block';
519             }
520
521             if (!responsiblePersonName) {
522                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
523                     {uuid}
524                 </Typography>;
525             }
526
527             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
528                 {responsiblePersonName} ({uuid})
529                 </Typography>;
530         });
531
532 const renderType = (type: string, subtype: string) =>
533     <Typography noWrap>
534         {resourceLabel(type, subtype)}
535     </Typography>;
536
537 export const ResourceType = connect(
538     (state: RootState, props: { uuid: string }) => {
539         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
540         return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
541     })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
542
543 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
544     return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
545 })((props: { resource: GroupContentsResource }) =>
546     (props.resource && props.resource.kind === ResourceKind.COLLECTION)
547         ? <CollectionStatus uuid={props.resource.uuid} />
548         : <ProcessStatus uuid={props.resource.uuid} />
549 );
550
551 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
552     return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
553 })((props: { collection: CollectionResource }) =>
554     (props.collection.uuid !== props.collection.currentVersionUuid)
555         ? <Typography>version {props.collection.version}</Typography>
556         : <Typography>head version</Typography>
557 );
558
559 export const ProcessStatus = compose(
560     connect((state: RootState, props: { uuid: string }) => {
561         return { process: getProcess(props.uuid)(state.resources) };
562     }),
563     withStyles({}, { withTheme: true }))
564     ((props: { process?: Process, theme: ArvadosTheme }) => {
565         const status = props.process ? getProcessStatus(props.process) : "-";
566         return <Typography
567             noWrap
568             style={{ color: getProcessStatusColor(status, props.theme) }} >
569             {status}
570         </Typography>;
571     });
572
573 export const ProcessStartDate = connect(
574     (state: RootState, props: { uuid: string }) => {
575         const process = getProcess(props.uuid)(state.resources);
576         return { date: (process && process.container) ? process.container.startedAt : '' };
577     })((props: { date: string }) => renderDate(props.date));
578
579 export const renderRunTime = (time: number) =>
580     <Typography noWrap style={{ minWidth: '45px' }}>
581         {formatTime(time, true)}
582     </Typography>;
583
584 interface ContainerRunTimeProps {
585     process: Process;
586 }
587
588 interface ContainerRunTimeState {
589     runtime: number;
590 }
591
592 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
593     return { process: getProcess(props.uuid)(state.resources) };
594 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
595     private timer: any;
596
597     constructor(props: ContainerRunTimeProps) {
598         super(props);
599         this.state = { runtime: this.getRuntime() };
600     }
601
602     getRuntime() {
603         return this.props.process ? getProcessRuntime(this.props.process) : 0;
604     }
605
606     updateRuntime() {
607         this.setState({ runtime: this.getRuntime() });
608     }
609
610     componentDidMount() {
611         this.timer = setInterval(this.updateRuntime.bind(this), 5000);
612     }
613
614     componentWillUnmount() {
615         clearInterval(this.timer);
616     }
617
618     render() {
619         return renderRunTime(this.state.runtime);
620     }
621 });