1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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, RemoveIcon, RenameIcon } 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, navigateToGroupDetails } 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 import { openRemoveGroupMemberDialog, openEditPermissionLevelDialog } from 'store/group-details-panel/group-details-panel-actions';
33 import { formatPermissionLevel } from 'views-components/sharing-dialog/permission-select';
34 import { PermissionLevel } from 'models/permission';
36 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
38 const navFunc = ("groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo);
39 return <Grid container alignItems="center" wrap="nowrap" spacing={16}>
44 <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} onClick={() => dispatch<any>(navFunc(item.uuid))}>
45 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
46 ? <IllegalNamingWarning name={item.name} />
52 <Typography variant="caption">
53 <FavoriteStar resourceUuid={item.uuid} />
54 <PublicFavoriteStar resourceUuid={item.uuid} />
60 export const ResourceName = connect(
61 (state: RootState, props: { uuid: string }) => {
62 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
64 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
66 const renderIcon = (item: GroupContentsResource) => {
68 case ResourceKind.PROJECT:
69 if (item.groupClass === GroupClass.FILTER) {
70 return <FilterGroupIcon />;
72 return <ProjectIcon />;
73 case ResourceKind.COLLECTION:
74 if (item.uuid === item.currentVersionUuid) {
75 return <CollectionIcon />;
77 return <CollectionOldVersionIcon />;
78 case ResourceKind.PROCESS:
79 return <ProcessIcon />;
80 case ResourceKind.WORKFLOW:
81 return <WorkflowIcon />;
83 return <DefaultIcon />;
87 const renderDate = (date?: string) => {
88 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
91 const renderWorkflowName = (item: WorkflowResource) =>
92 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
97 <Typography color="primary" style={{ width: '100px' }}>
103 export const ResourceWorkflowName = connect(
104 (state: RootState, props: { uuid: string }) => {
105 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
107 })(renderWorkflowName);
109 const getPublicUuid = (uuidPrefix: string) => {
110 return `${uuidPrefix}-tpzed-anonymouspublic`;
113 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
114 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
117 {!isPublic && uuid &&
118 <Tooltip title="Share">
119 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
128 export const ResourceShare = connect(
129 (state: RootState, props: { uuid: string }) => {
130 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
131 const uuidPrefix = getUuidPrefix(state);
133 uuid: resource ? resource.uuid : '',
134 ownerUuid: resource ? resource.ownerUuid : '',
137 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
138 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
141 const renderFirstName = (item: { firstName: string }) => {
142 return <Typography noWrap>{item.firstName}</Typography>;
145 export const ResourceFirstName = connect(
146 (state: RootState, props: { uuid: string }) => {
147 const resource = getResource<UserResource>(props.uuid)(state.resources);
148 return resource || { firstName: '' };
151 const renderLastName = (item: { lastName: string }) =>
152 <Typography noWrap>{item.lastName}</Typography>;
154 export const ResourceLastName = connect(
155 (state: RootState, props: { uuid: string }) => {
156 const resource = getResource<UserResource>(props.uuid)(state.resources);
157 return resource || { lastName: '' };
160 const renderFullName = (item: { firstName: string, lastName: string }) =>
161 <Typography noWrap>{(item.firstName + " " + item.lastName).trim()}</Typography>;
163 export const ResourceFullName = connect(
164 (state: RootState, props: { uuid: string }) => {
165 const resource = getResource<UserResource>(props.uuid)(state.resources);
166 return resource || { firstName: '', lastName: '' };
170 const renderUuid = (item: { uuid: string }) =>
171 <Typography noWrap>{item.uuid}</Typography>;
173 export const ResourceUuid = connect(
174 (state: RootState, props: { uuid: string }) => {
175 const resource = getResource<UserResource>(props.uuid)(state.resources);
176 return resource || { uuid: '' };
179 const renderEmail = (item: { email: string }) =>
180 <Typography noWrap>{item.email}</Typography>;
182 export const ResourceEmail = connect(
183 (state: RootState, props: { uuid: string }) => {
184 const resource = getResource<UserResource>(props.uuid)(state.resources);
185 return resource || { email: '' };
188 const renderIsActive = (props: { uuid: string, kind: ResourceKind, isActive: boolean, toggleIsActive: (uuid: string) => void }) => {
189 if (props.kind === ResourceKind.USER) {
192 checked={props.isActive}
193 onClick={() => props.toggleIsActive(props.uuid)} />;
195 return <Typography />;
199 export const ResourceIsActive = connect(
200 (state: RootState, props: { uuid: string }) => {
201 const resource = getResource<UserResource>(props.uuid)(state.resources);
202 return resource || { isActive: false, kind: ResourceKind.NONE };
203 }, { toggleIsActive }
206 export const ResourceLinkTailIsActive = connect(
207 (state: RootState, props: { uuid: string }) => {
208 const link = getResource<LinkResource>(props.uuid)(state.resources);
209 const tailResource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
211 return tailResource || { isActive: false, kind: ResourceKind.NONE };
212 }, { toggleIsActive }
215 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
218 checked={props.isAdmin}
219 onClick={() => props.toggleIsAdmin(props.uuid)} />;
221 export const ResourceIsAdmin = connect(
222 (state: RootState, props: { uuid: string }) => {
223 const resource = getResource<UserResource>(props.uuid)(state.resources);
224 return resource || { isAdmin: false };
228 const renderUsername = (item: { username: string }) =>
229 <Typography noWrap>{item.username}</Typography>;
231 export const ResourceUsername = connect(
232 (state: RootState, props: { uuid: string }) => {
233 const resource = getResource<UserResource>(props.uuid)(state.resources);
234 return resource || { username: '' };
238 const renderCommonData = (data: string) =>
239 <Typography noWrap>{data}</Typography>;
241 const renderCommonDate = (date: string) =>
242 <Typography noWrap>{formatDate(date)}</Typography>;
244 export const CommonUuid = withResourceData('uuid', renderCommonData);
246 // Api Client Authorizations
247 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
249 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
251 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
253 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
255 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
257 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
259 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
261 export const TokenScopes = withResourceData('scopes', renderCommonData);
263 export const TokenUserId = withResourceData('userId', renderCommonData);
265 const clusterColors = [
273 export const ResourceCluster = (props: { uuid: string }) => {
274 const CLUSTER_ID_LENGTH = 5;
275 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
276 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
277 const ci = pos >= CLUSTER_ID_LENGTH ? (((((
278 (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
279 + props.uuid.charCodeAt(2))
280 * props.uuid.charCodeAt(3))
281 + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
282 return <span style={{
283 backgroundColor: clusterColors[ci][0],
284 color: clusterColors[ci][1],
287 }}>{clusterId}</span>;
291 const renderLinkName = (item: { name: string }) =>
292 <Typography noWrap>{item.name || '(none)'}</Typography>;
294 export const ResourceLinkName = connect(
295 (state: RootState, props: { uuid: string }) => {
296 const resource = getResource<LinkResource>(props.uuid)(state.resources);
297 return resource || { name: '' };
300 const renderLinkClass = (item: { linkClass: string }) =>
301 <Typography noWrap>{item.linkClass}</Typography>;
303 export const ResourceLinkClass = connect(
304 (state: RootState, props: { uuid: string }) => {
305 const resource = getResource<LinkResource>(props.uuid)(state.resources);
306 return resource || { linkClass: '' };
309 const getResourceDisplayName = (resource: Resource): string => {
310 if ((resource as UserResource).kind === ResourceKind.USER
311 && typeof (resource as UserResource).firstName !== 'undefined') {
312 // We can be sure the resource is UserResource
313 return getUserDisplayName(resource as UserResource);
315 return (resource as GroupContentsResource).name;
319 const renderResourceLink = (dispatch: Dispatch, item: Resource) => {
320 var displayName = getResourceDisplayName(item);
322 return <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
323 {resourceLabel(item.kind)}: {displayName || item.uuid}
327 const renderResource = (dispatch: Dispatch, item: Resource) => {
328 var displayName = getResourceDisplayName(item);
330 return <Typography variant='body2'>
331 {resourceLabel(item.kind)}: {displayName || item.uuid}
335 export const ResourceLinkTail = connect(
336 (state: RootState, props: { uuid: string }) => {
337 const resource = getResource<LinkResource>(props.uuid)(state.resources);
338 const tailResource = getResource<Resource>(resource?.tailUuid || '')(state.resources);
341 item: tailResource || { uuid: resource?.tailUuid || '', kind: resource?.tailKind || ResourceKind.NONE }
343 })((props: { item: Resource } & DispatchProp<any>) =>
344 renderResourceLink(props.dispatch, props.item));
346 export const ResourceLinkHead = connect(
347 (state: RootState, props: { uuid: string }) => {
348 const resource = getResource<LinkResource>(props.uuid)(state.resources);
349 const headResource = getResource<Resource>(resource?.headUuid || '')(state.resources);
352 item: headResource || { uuid: resource?.headUuid || '', kind: resource?.headKind || ResourceKind.NONE }
354 })((props: { item: Resource } & DispatchProp<any>) =>
355 renderResourceLink(props.dispatch, props.item));
357 export const ResourceLinkUuid = connect(
358 (state: RootState, props: { uuid: string }) => {
359 const resource = getResource<LinkResource>(props.uuid)(state.resources);
360 return resource || { uuid: '' };
363 export const ResourceLinkHeadUuid = connect(
364 (state: RootState, props: { uuid: string }) => {
365 const link = getResource<LinkResource>(props.uuid)(state.resources);
366 const headResource = getResource<Resource>(link?.headUuid || '')(state.resources);
368 return headResource || { uuid: '' };
371 export const ResourceLinkTailUuid = connect(
372 (state: RootState, props: { uuid: string }) => {
373 const link = getResource<LinkResource>(props.uuid)(state.resources);
374 const tailResource = getResource<Resource>(link?.tailUuid || '')(state.resources);
376 return tailResource || { uuid: '' };
379 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource) => {
381 return <Typography noWrap>
382 <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
387 return <Typography noWrap></Typography>;
391 export const ResourceLinkDelete = connect(
392 (state: RootState, props: { uuid: string }) => {
393 const link = getResource<LinkResource>(props.uuid)(state.resources);
395 item: link || { uuid: '', kind: ResourceKind.NONE }
397 })((props: { item: LinkResource } & DispatchProp<any>) =>
398 renderLinkDelete(props.dispatch, props.item));
400 export const ResourceLinkTailEmail = connect(
401 (state: RootState, props: { uuid: string }) => {
402 const link = getResource<LinkResource>(props.uuid)(state.resources);
403 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
405 return resource || { email: '' };
408 export const ResourceLinkTailUsername = connect(
409 (state: RootState, props: { uuid: string }) => {
410 const link = getResource<LinkResource>(props.uuid)(state.resources);
411 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
413 return resource || { username: '' };
416 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, resource: Resource) => {
417 return <Typography noWrap>
418 {formatPermissionLevel(link.name as PermissionLevel)}
419 <IconButton onClick={() => dispatch<any>(openEditPermissionLevelDialog(link.uuid, resource.uuid))}>
425 export const ResourceLinkHeadPermissionLevel = connect(
426 (state: RootState, props: { uuid: string }) => {
427 const link = getResource<LinkResource>(props.uuid)(state.resources);
428 const resource = getResource<Resource>(link?.headUuid || '')(state.resources);
431 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
432 resource: resource || { uuid: '', kind: ResourceKind.NONE }
434 })((props: { link: LinkResource, resource: Resource } & DispatchProp<any>) =>
435 renderPermissionLevel(props.dispatch, props.link, props.resource));
437 export const ResourceLinkTailPermissionLevel = connect(
438 (state: RootState, props: { uuid: string }) => {
439 const link = getResource<LinkResource>(props.uuid)(state.resources);
440 const resource = getResource<Resource>(link?.tailUuid || '')(state.resources);
443 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
444 resource: resource || { uuid: '', kind: ResourceKind.NONE }
446 })((props: { link: LinkResource, resource: Resource } & DispatchProp<any>) =>
447 renderPermissionLevel(props.dispatch, props.link, props.resource));
449 // Displays resource type and display name without link
450 export const ResourceLabel = connect(
451 (state: RootState, props: { uuid: string }) => {
452 const resource = getResource<Resource>(props.uuid)(state.resources);
454 item: resource || { uuid: '', kind: ResourceKind.NONE }
456 })((props: { item: Resource } & DispatchProp<any>) =>
457 renderResource(props.dispatch, props.item));
460 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
464 <Tooltip title="Run process">
465 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
473 export const ResourceRunProcess = connect(
474 (state: RootState, props: { uuid: string }) => {
475 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
477 uuid: resource ? resource.uuid : ''
479 })((props: { uuid: string } & DispatchProp<any>) =>
480 resourceRunProcess(props.dispatch, props.uuid));
482 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
483 if (ownerUuid === getPublicUuid(uuidPrefix)) {
484 return renderStatus(WorkflowStatus.PUBLIC);
486 return renderStatus(WorkflowStatus.PRIVATE);
490 const renderStatus = (status: string) =>
491 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
493 export const ResourceWorkflowStatus = connect(
494 (state: RootState, props: { uuid: string }) => {
495 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
496 const uuidPrefix = getUuidPrefix(state);
498 ownerUuid: resource ? resource.ownerUuid : '',
501 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
503 export const ResourceLastModifiedDate = connect(
504 (state: RootState, props: { uuid: string }) => {
505 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
506 return { date: resource ? resource.modifiedAt : '' };
507 })((props: { date: string }) => renderDate(props.date));
509 export const ResourceCreatedAtDate = connect(
510 (state: RootState, props: { uuid: string }) => {
511 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
512 return { date: resource ? resource.createdAt : '' };
513 })((props: { date: string }) => renderDate(props.date));
515 export const ResourceTrashDate = connect(
516 (state: RootState, props: { uuid: string }) => {
517 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
518 return { date: resource ? resource.trashAt : '' };
519 })((props: { date: string }) => renderDate(props.date));
521 export const ResourceDeleteDate = connect(
522 (state: RootState, props: { uuid: string }) => {
523 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
524 return { date: resource ? resource.deleteAt : '' };
525 })((props: { date: string }) => renderDate(props.date));
527 export const renderFileSize = (fileSize?: number) =>
528 <Typography noWrap style={{ minWidth: '45px' }}>
529 {formatFileSize(fileSize)}
532 export const ResourceFileSize = connect(
533 (state: RootState, props: { uuid: string }) => {
534 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
536 if (resource && resource.kind !== ResourceKind.COLLECTION) {
537 return { fileSize: '' };
540 return { fileSize: resource ? resource.fileSizeTotal : 0 };
541 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
543 const renderOwner = (owner: string) =>
548 export const ResourceOwner = connect(
549 (state: RootState, props: { uuid: string }) => {
550 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
551 return { owner: resource ? resource.ownerUuid : '' };
552 })((props: { owner: string }) => renderOwner(props.owner));
554 export const ResourceOwnerName = connect(
555 (state: RootState, props: { uuid: string }) => {
556 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
557 const ownerNameState = state.ownerName;
558 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
559 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
560 })((props: { owner: string }) => renderOwner(props.owner));
564 (state: RootState, props: { uuid: string }) => {
565 let userFullname = '';
566 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
569 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
572 return { uuid: props.uuid, userFullname };
575 export const ResourceOwnerWithName =
578 withStyles({}, { withTheme: true }))
579 ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
580 const { uuid, userFullname, dispatch, theme } = props;
582 if (userFullname === '') {
583 dispatch<any>(loadResource(uuid, false));
584 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
589 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
590 {userFullname} ({uuid})
594 export const UserNameFromID =
596 (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
597 const { uuid, userFullname, dispatch } = props;
599 if (userFullname === '') {
600 dispatch<any>(loadResource(uuid, false));
603 {userFullname ? userFullname : uuid}
607 export const ResponsiblePerson =
610 (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
611 let responsiblePersonName: string = '';
612 let responsiblePersonUUID: string = '';
613 let responsiblePersonProperty: string = '';
615 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
617 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
619 while (!responsiblePersonProperty && keys[index]) {
620 const key = keys[index];
621 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
622 responsiblePersonProperty = key;
628 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
630 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
631 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
632 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
635 if (resource && resource.kind === ResourceKind.USER) {
636 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
639 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
641 withStyles({}, { withTheme: true }))
642 ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
643 const { uuid, responsiblePersonName, parentRef, theme } = props;
645 if (!uuid && parentRef) {
646 parentRef.style.display = 'none';
648 } else if (parentRef) {
649 parentRef.style.display = 'block';
652 if (!responsiblePersonName) {
653 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
658 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
659 {responsiblePersonName} ({uuid})
663 const renderType = (type: string, subtype: string) =>
665 {resourceLabel(type, subtype)}
668 export const ResourceType = connect(
669 (state: RootState, props: { uuid: string }) => {
670 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
671 return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
672 })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
674 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
675 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
676 })((props: { resource: GroupContentsResource }) =>
677 (props.resource && props.resource.kind === ResourceKind.COLLECTION)
678 ? <CollectionStatus uuid={props.resource.uuid} />
679 : <ProcessStatus uuid={props.resource.uuid} />
682 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
683 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
684 })((props: { collection: CollectionResource }) =>
685 (props.collection.uuid !== props.collection.currentVersionUuid)
686 ? <Typography>version {props.collection.version}</Typography>
687 : <Typography>head version</Typography>
690 export const ProcessStatus = compose(
691 connect((state: RootState, props: { uuid: string }) => {
692 return { process: getProcess(props.uuid)(state.resources) };
694 withStyles({}, { withTheme: true }))
695 ((props: { process?: Process, theme: ArvadosTheme }) => {
696 const status = props.process ? getProcessStatus(props.process) : "-";
699 style={{ color: getProcessStatusColor(status, props.theme) }} >
704 export const ProcessStartDate = connect(
705 (state: RootState, props: { uuid: string }) => {
706 const process = getProcess(props.uuid)(state.resources);
707 return { date: (process && process.container) ? process.container.startedAt : '' };
708 })((props: { date: string }) => renderDate(props.date));
710 export const renderRunTime = (time: number) =>
711 <Typography noWrap style={{ minWidth: '45px' }}>
712 {formatTime(time, true)}
715 interface ContainerRunTimeProps {
719 interface ContainerRunTimeState {
723 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
724 return { process: getProcess(props.uuid)(state.resources) };
725 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
728 constructor(props: ContainerRunTimeProps) {
730 this.state = { runtime: this.getRuntime() };
734 return this.props.process ? getProcessRuntime(this.props.process) : 0;
738 this.setState({ runtime: this.getRuntime() });
741 componentDidMount() {
742 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
745 componentWillUnmount() {
746 clearInterval(this.timer);
750 return renderRunTime(this.state.runtime);