Merge branch '17691-relax-add-ssh-validation' into main. Closes #17691
[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 export const ResourceOwnerWithName =
429     compose(
430         connect(
431             (state: RootState, props: { uuid: string }) => {
432                 let ownerName = '';
433                 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
434
435                 if (resource) {
436                     ownerName = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
437                 }
438
439                 return { uuid: props.uuid, ownerName };
440             }),
441         withStyles({}, { withTheme: true }))
442         ((props: { uuid: string, ownerName: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
443             const { uuid, ownerName, dispatch, theme } = props;
444
445             if (ownerName === '') {
446                 dispatch<any>(loadResource(uuid, false));
447                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
448                     {uuid}
449                 </Typography>;
450             }
451
452             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
453                 {ownerName} ({uuid})
454             </Typography>;
455         });
456
457 export const ResponsiblePerson =
458     compose(
459         connect(
460             (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
461                 let responsiblePersonName: string = '';
462                 let responsiblePersonUUID: string = '';
463                 let responsiblePersonProperty: string = '';
464
465                 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
466                     let index = 0;
467                     const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
468
469                     while (!responsiblePersonProperty && keys[index]) {
470                         const key = keys[index];
471                         if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
472                             responsiblePersonProperty = key;
473                         }
474                         index++;
475                     }
476                 }
477
478                 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
479
480                 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
481                     responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
482                     resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
483                 }
484
485                 if (resource && resource.kind === ResourceKind.USER) {
486                     responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
487                 }
488
489                 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
490             }),
491         withStyles({}, { withTheme: true }))
492         ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
493             const { uuid, responsiblePersonName, parentRef, theme } = props;
494
495             if (!uuid && parentRef) {
496                 parentRef.style.display = 'none';
497                 return null;
498             } else if (parentRef) {
499                 parentRef.style.display = 'block';
500             }
501
502             if (!responsiblePersonName) {
503                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
504                     {uuid}
505                 </Typography>;
506             }
507
508             return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
509                 {responsiblePersonName} ({uuid})
510                 </Typography>;
511         });
512
513 const renderType = (type: string, subtype: string) =>
514     <Typography noWrap>
515         {resourceLabel(type, subtype)}
516     </Typography>;
517
518 export const ResourceType = connect(
519     (state: RootState, props: { uuid: string }) => {
520         const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
521         return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
522     })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
523
524 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
525     return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
526 })((props: { resource: GroupContentsResource }) =>
527     (props.resource && props.resource.kind === ResourceKind.COLLECTION)
528         ? <CollectionStatus uuid={props.resource.uuid} />
529         : <ProcessStatus uuid={props.resource.uuid} />
530 );
531
532 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
533     return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
534 })((props: { collection: CollectionResource }) =>
535     (props.collection.uuid !== props.collection.currentVersionUuid)
536         ? <Typography>version {props.collection.version}</Typography>
537         : <Typography>head version</Typography>
538 );
539
540 export const ProcessStatus = compose(
541     connect((state: RootState, props: { uuid: string }) => {
542         return { process: getProcess(props.uuid)(state.resources) };
543     }),
544     withStyles({}, { withTheme: true }))
545     ((props: { process?: Process, theme: ArvadosTheme }) => {
546         const status = props.process ? getProcessStatus(props.process) : "-";
547         return <Typography
548             noWrap
549             style={{ color: getProcessStatusColor(status, props.theme) }} >
550             {status}
551         </Typography>;
552     });
553
554 export const ProcessStartDate = connect(
555     (state: RootState, props: { uuid: string }) => {
556         const process = getProcess(props.uuid)(state.resources);
557         return { date: (process && process.container) ? process.container.startedAt : '' };
558     })((props: { date: string }) => renderDate(props.date));
559
560 export const renderRunTime = (time: number) =>
561     <Typography noWrap style={{ minWidth: '45px' }}>
562         {formatTime(time, true)}
563     </Typography>;
564
565 interface ContainerRunTimeProps {
566     process: Process;
567 }
568
569 interface ContainerRunTimeState {
570     runtime: number;
571 }
572
573 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
574     return { process: getProcess(props.uuid)(state.resources) };
575 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
576     private timer: any;
577
578     constructor(props: ContainerRunTimeProps) {
579         super(props);
580         this.state = { runtime: this.getRuntime() };
581     }
582
583     getRuntime() {
584         return this.props.process ? getProcessRuntime(this.props.process) : 0;
585     }
586
587     updateRuntime() {
588         this.setState({ runtime: this.getRuntime() });
589     }
590
591     componentDidMount() {
592         this.timer = setInterval(this.updateRuntime.bind(this), 5000);
593     }
594
595     componentWillUnmount() {
596         clearInterval(this.timer);
597     }
598
599     render() {
600         return renderRunTime(this.state.runtime);
601     }
602 });