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, filterResources } 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 { LinkClass, 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, GroupResource, isBuiltinGroup } from 'models/group';
32 import { openRemoveGroupMemberDialog } from 'store/group-details-panel/group-details-panel-actions';
33 import { setMemberIsHidden } from 'store/group-details-panel/group-details-panel-actions';
34 import { formatPermissionLevel } from 'views-components/sharing-dialog/permission-select';
35 import { PermissionLevel } from 'models/permission';
36 import { openPermissionEditContextMenu } from 'store/context-menu/context-menu-actions';
37 import { getUserUuid } from 'common/getuser';
39 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
41 const navFunc = ("groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo);
42 return <Grid container alignItems="center" wrap="nowrap" spacing={16}>
47 <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} onClick={() => dispatch<any>(navFunc(item.uuid))}>
48 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
49 ? <IllegalNamingWarning name={item.name} />
55 <Typography variant="caption">
56 <FavoriteStar resourceUuid={item.uuid} />
57 <PublicFavoriteStar resourceUuid={item.uuid} />
63 export const ResourceName = connect(
64 (state: RootState, props: { uuid: string }) => {
65 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
67 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
69 const renderIcon = (item: GroupContentsResource) => {
71 case ResourceKind.PROJECT:
72 if (item.groupClass === GroupClass.FILTER) {
73 return <FilterGroupIcon />;
75 return <ProjectIcon />;
76 case ResourceKind.COLLECTION:
77 if (item.uuid === item.currentVersionUuid) {
78 return <CollectionIcon />;
80 return <CollectionOldVersionIcon />;
81 case ResourceKind.PROCESS:
82 return <ProcessIcon />;
83 case ResourceKind.WORKFLOW:
84 return <WorkflowIcon />;
86 return <DefaultIcon />;
90 const renderDate = (date?: string) => {
91 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
94 const renderWorkflowName = (item: WorkflowResource) =>
95 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
100 <Typography color="primary" style={{ width: '100px' }}>
106 export const ResourceWorkflowName = connect(
107 (state: RootState, props: { uuid: string }) => {
108 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
110 })(renderWorkflowName);
112 const getPublicUuid = (uuidPrefix: string) => {
113 return `${uuidPrefix}-tpzed-anonymouspublic`;
116 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
117 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
120 {!isPublic && uuid &&
121 <Tooltip title="Share">
122 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
131 export const ResourceShare = connect(
132 (state: RootState, props: { uuid: string }) => {
133 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
134 const uuidPrefix = getUuidPrefix(state);
136 uuid: resource ? resource.uuid : '',
137 ownerUuid: resource ? resource.ownerUuid : '',
140 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
141 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
144 const renderFirstName = (item: { firstName: string }) => {
145 return <Typography noWrap>{item.firstName}</Typography>;
148 export const ResourceFirstName = connect(
149 (state: RootState, props: { uuid: string }) => {
150 const resource = getResource<UserResource>(props.uuid)(state.resources);
151 return resource || { firstName: '' };
154 const renderLastName = (item: { lastName: string }) =>
155 <Typography noWrap>{item.lastName}</Typography>;
157 export const ResourceLastName = connect(
158 (state: RootState, props: { uuid: string }) => {
159 const resource = getResource<UserResource>(props.uuid)(state.resources);
160 return resource || { lastName: '' };
163 const renderFullName = (item: { firstName: string, lastName: string }) =>
164 <Typography noWrap>{(item.firstName + " " + item.lastName).trim()}</Typography>;
166 export const ResourceFullName = connect(
167 (state: RootState, props: { uuid: string }) => {
168 const resource = getResource<UserResource>(props.uuid)(state.resources);
169 return resource || { firstName: '', lastName: '' };
173 const renderUuid = (item: { uuid: string }) =>
174 <Typography data-cy="uuid" noWrap>{item.uuid}</Typography>;
176 export const ResourceUuid = connect(
177 (state: RootState, props: { uuid: string }) => {
178 const resource = getResource<UserResource>(props.uuid)(state.resources);
179 return resource || { uuid: '' };
182 const renderEmail = (item: { email: string }) =>
183 <Typography noWrap>{item.email}</Typography>;
185 export const ResourceEmail = connect(
186 (state: RootState, props: { uuid: string }) => {
187 const resource = getResource<UserResource>(props.uuid)(state.resources);
188 return resource || { email: '' };
191 const renderIsActive = (props: { uuid: string, kind: ResourceKind, isActive: boolean, toggleIsActive: (uuid: string) => void }) => {
192 if (props.kind === ResourceKind.USER) {
195 checked={props.isActive}
196 onClick={() => props.toggleIsActive(props.uuid)} />;
198 return <Typography />;
202 export const ResourceIsActive = connect(
203 (state: RootState, props: { uuid: string }) => {
204 const resource = getResource<UserResource>(props.uuid)(state.resources);
205 return resource || { isActive: false, kind: ResourceKind.NONE };
206 }, { toggleIsActive }
209 export const ResourceLinkTailIsActive = connect(
210 (state: RootState, props: { uuid: string }) => {
211 const link = getResource<LinkResource>(props.uuid)(state.resources);
212 const tailResource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
214 return tailResource || { isActive: false, kind: ResourceKind.NONE };
215 }, { toggleIsActive }
218 const renderIsHidden = (props: {
219 memberLinkUuid: string,
220 permissionLinkUuid: string,
223 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void
225 if (props.memberLinkUuid) {
227 data-cy="user-visible-checkbox"
229 checked={props.visible}
230 disabled={!props.canManage}
231 onClick={() => props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible)} />;
233 return <Typography />;
237 export const ResourceLinkTailIsVisible = connect(
238 (state: RootState, props: { uuid: string }) => {
239 const link = getResource<LinkResource>(props.uuid)(state.resources);
240 const member = getResource<Resource>(link?.tailUuid || '')(state.resources);
241 const group = getResource<GroupResource>(link?.headUuid || '')(state.resources);
242 const permissions = filterResources((resource: LinkResource) => {
243 return resource.linkClass === LinkClass.PERMISSION
244 && resource.headUuid === link?.tailUuid
245 && resource.tailUuid === group?.uuid
246 && resource.name === PermissionLevel.CAN_READ;
249 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : '';
250 const isVisible = link && group && permissions.length > 0;
251 // Consider whether the current user canManage this resurce in addition when it's possible
252 const isBuiltin = isBuiltinGroup(link?.headUuid || '');
254 return member?.kind === ResourceKind.USER
255 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
256 : { memberLinkUuid: '', permissionLinkUuid: '', visible: false, canManage: false };
257 }, { setMemberIsHidden }
260 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
263 checked={props.isAdmin}
264 onClick={() => props.toggleIsAdmin(props.uuid)} />;
266 export const ResourceIsAdmin = connect(
267 (state: RootState, props: { uuid: string }) => {
268 const resource = getResource<UserResource>(props.uuid)(state.resources);
269 return resource || { isAdmin: false };
273 const renderUsername = (item: { username: string }) =>
274 <Typography noWrap>{item.username}</Typography>;
276 export const ResourceUsername = connect(
277 (state: RootState, props: { uuid: string }) => {
278 const resource = getResource<UserResource>(props.uuid)(state.resources);
279 return resource || { username: '' };
283 const renderCommonData = (data: string) =>
284 <Typography noWrap>{data}</Typography>;
286 const renderCommonDate = (date: string) =>
287 <Typography noWrap>{formatDate(date)}</Typography>;
289 export const CommonUuid = withResourceData('uuid', renderCommonData);
291 // Api Client Authorizations
292 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
294 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
296 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
298 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
300 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
302 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
304 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
306 export const TokenScopes = withResourceData('scopes', renderCommonData);
308 export const TokenUserId = withResourceData('userId', renderCommonData);
310 const clusterColors = [
318 export const ResourceCluster = (props: { uuid: string }) => {
319 const CLUSTER_ID_LENGTH = 5;
320 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
321 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
322 const ci = pos >= CLUSTER_ID_LENGTH ? (((((
323 (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
324 + props.uuid.charCodeAt(2))
325 * props.uuid.charCodeAt(3))
326 + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
327 return <span style={{
328 backgroundColor: clusterColors[ci][0],
329 color: clusterColors[ci][1],
332 }}>{clusterId}</span>;
336 const renderLinkName = (item: { name: string }) =>
337 <Typography noWrap>{item.name || '(none)'}</Typography>;
339 export const ResourceLinkName = connect(
340 (state: RootState, props: { uuid: string }) => {
341 const resource = getResource<LinkResource>(props.uuid)(state.resources);
342 return resource || { name: '' };
345 const renderLinkClass = (item: { linkClass: string }) =>
346 <Typography noWrap>{item.linkClass}</Typography>;
348 export const ResourceLinkClass = connect(
349 (state: RootState, props: { uuid: string }) => {
350 const resource = getResource<LinkResource>(props.uuid)(state.resources);
351 return resource || { linkClass: '' };
354 const getResourceDisplayName = (resource: Resource): string => {
355 if ((resource as UserResource).kind === ResourceKind.USER
356 && typeof (resource as UserResource).firstName !== 'undefined') {
357 // We can be sure the resource is UserResource
358 return getUserDisplayName(resource as UserResource);
360 return (resource as GroupContentsResource).name;
364 const renderResourceLink = (dispatch: Dispatch, item: Resource) => {
365 var displayName = getResourceDisplayName(item);
367 return <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
368 {resourceLabel(item.kind)}: {displayName || item.uuid}
372 export const ResourceLinkTail = connect(
373 (state: RootState, props: { uuid: string }) => {
374 const resource = getResource<LinkResource>(props.uuid)(state.resources);
375 const tailResource = getResource<Resource>(resource?.tailUuid || '')(state.resources);
378 item: tailResource || { uuid: resource?.tailUuid || '', kind: resource?.tailKind || ResourceKind.NONE }
380 })((props: { item: Resource } & DispatchProp<any>) =>
381 renderResourceLink(props.dispatch, props.item));
383 export const ResourceLinkHead = connect(
384 (state: RootState, props: { uuid: string }) => {
385 const resource = getResource<LinkResource>(props.uuid)(state.resources);
386 const headResource = getResource<Resource>(resource?.headUuid || '')(state.resources);
389 item: headResource || { uuid: resource?.headUuid || '', kind: resource?.headKind || ResourceKind.NONE }
391 })((props: { item: Resource } & DispatchProp<any>) =>
392 renderResourceLink(props.dispatch, props.item));
394 export const ResourceLinkUuid = connect(
395 (state: RootState, props: { uuid: string }) => {
396 const resource = getResource<LinkResource>(props.uuid)(state.resources);
397 return resource || { uuid: '' };
400 export const ResourceLinkHeadUuid = connect(
401 (state: RootState, props: { uuid: string }) => {
402 const link = getResource<LinkResource>(props.uuid)(state.resources);
403 const headResource = getResource<Resource>(link?.headUuid || '')(state.resources);
405 return headResource || { uuid: '' };
408 export const ResourceLinkTailUuid = connect(
409 (state: RootState, props: { uuid: string }) => {
410 const link = getResource<LinkResource>(props.uuid)(state.resources);
411 const tailResource = getResource<Resource>(link?.tailUuid || '')(state.resources);
413 return tailResource || { uuid: '' };
416 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
420 <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
425 <IconButton disabled data-cy="resource-delete-button">
430 return <Typography noWrap></Typography>;
434 export const ResourceLinkDelete = connect(
435 (state: RootState, props: { uuid: string }) => {
436 const link = getResource<LinkResource>(props.uuid)(state.resources);
437 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
440 item: link || { uuid: '', kind: ResourceKind.NONE },
441 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
443 })((props: { item: LinkResource, canManage: boolean } & DispatchProp<any>) =>
444 renderLinkDelete(props.dispatch, props.item, props.canManage));
446 export const ResourceLinkTailEmail = connect(
447 (state: RootState, props: { uuid: string }) => {
448 const link = getResource<LinkResource>(props.uuid)(state.resources);
449 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
451 return resource || { email: '' };
454 export const ResourceLinkTailUsername = connect(
455 (state: RootState, props: { uuid: string }) => {
456 const link = getResource<LinkResource>(props.uuid)(state.resources);
457 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
459 return resource || { username: '' };
462 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
463 return <Typography noWrap>
464 {formatPermissionLevel(link.name as PermissionLevel)}
466 <IconButton data-cy="edit-permission-button" onClick={(event) => dispatch<any>(openPermissionEditContextMenu(event, link))}>
474 export const ResourceLinkHeadPermissionLevel = connect(
475 (state: RootState, props: { uuid: string }) => {
476 const link = getResource<LinkResource>(props.uuid)(state.resources);
477 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
480 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
481 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
483 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
484 renderPermissionLevel(props.dispatch, props.link, props.canManage));
486 export const ResourceLinkTailPermissionLevel = connect(
487 (state: RootState, props: { uuid: string }) => {
488 const link = getResource<LinkResource>(props.uuid)(state.resources);
489 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
492 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
493 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
495 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
496 renderPermissionLevel(props.dispatch, props.link, props.canManage));
498 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
499 const headResource = getResource<Resource>(link.headUuid)(state.resources);
500 // const tailResource = getResource<Resource>(link.tailUuid)(state.resources);
501 const userUuid = getUserUuid(state);
503 if (headResource && headResource.kind === ResourceKind.GROUP) {
504 return userUuid ? (headResource as GroupResource).writableBy?.includes(userUuid) : false;
512 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
516 <Tooltip title="Run process">
517 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
525 export const ResourceRunProcess = connect(
526 (state: RootState, props: { uuid: string }) => {
527 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
529 uuid: resource ? resource.uuid : ''
531 })((props: { uuid: string } & DispatchProp<any>) =>
532 resourceRunProcess(props.dispatch, props.uuid));
534 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
535 if (ownerUuid === getPublicUuid(uuidPrefix)) {
536 return renderStatus(WorkflowStatus.PUBLIC);
538 return renderStatus(WorkflowStatus.PRIVATE);
542 const renderStatus = (status: string) =>
543 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
545 export const ResourceWorkflowStatus = connect(
546 (state: RootState, props: { uuid: string }) => {
547 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
548 const uuidPrefix = getUuidPrefix(state);
550 ownerUuid: resource ? resource.ownerUuid : '',
553 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
555 export const ResourceLastModifiedDate = connect(
556 (state: RootState, props: { uuid: string }) => {
557 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
558 return { date: resource ? resource.modifiedAt : '' };
559 })((props: { date: string }) => renderDate(props.date));
561 export const ResourceCreatedAtDate = connect(
562 (state: RootState, props: { uuid: string }) => {
563 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
564 return { date: resource ? resource.createdAt : '' };
565 })((props: { date: string }) => renderDate(props.date));
567 export const ResourceTrashDate = connect(
568 (state: RootState, props: { uuid: string }) => {
569 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
570 return { date: resource ? resource.trashAt : '' };
571 })((props: { date: string }) => renderDate(props.date));
573 export const ResourceDeleteDate = connect(
574 (state: RootState, props: { uuid: string }) => {
575 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
576 return { date: resource ? resource.deleteAt : '' };
577 })((props: { date: string }) => renderDate(props.date));
579 export const renderFileSize = (fileSize?: number) =>
580 <Typography noWrap style={{ minWidth: '45px' }}>
581 {formatFileSize(fileSize)}
584 export const ResourceFileSize = connect(
585 (state: RootState, props: { uuid: string }) => {
586 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
588 if (resource && resource.kind !== ResourceKind.COLLECTION) {
589 return { fileSize: '' };
592 return { fileSize: resource ? resource.fileSizeTotal : 0 };
593 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
595 const renderOwner = (owner: string) =>
600 export const ResourceOwner = connect(
601 (state: RootState, props: { uuid: string }) => {
602 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
603 return { owner: resource ? resource.ownerUuid : '' };
604 })((props: { owner: string }) => renderOwner(props.owner));
606 export const ResourceOwnerName = connect(
607 (state: RootState, props: { uuid: string }) => {
608 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
609 const ownerNameState = state.ownerName;
610 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
611 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
612 })((props: { owner: string }) => renderOwner(props.owner));
616 (state: RootState, props: { uuid: string }) => {
617 let userFullname = '';
618 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
621 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
624 return { uuid: props.uuid, userFullname };
627 export const ResourceOwnerWithName =
630 withStyles({}, { withTheme: true }))
631 ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
632 const { uuid, userFullname, dispatch, theme } = props;
634 if (userFullname === '') {
635 dispatch<any>(loadResource(uuid, false));
636 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
641 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
642 {userFullname} ({uuid})
646 export const UserNameFromID =
648 (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
649 const { uuid, userFullname, dispatch } = props;
651 if (userFullname === '') {
652 dispatch<any>(loadResource(uuid, false));
655 {userFullname ? userFullname : uuid}
659 export const ResponsiblePerson =
662 (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
663 let responsiblePersonName: string = '';
664 let responsiblePersonUUID: string = '';
665 let responsiblePersonProperty: string = '';
667 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
669 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
671 while (!responsiblePersonProperty && keys[index]) {
672 const key = keys[index];
673 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
674 responsiblePersonProperty = key;
680 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
682 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
683 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
684 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
687 if (resource && resource.kind === ResourceKind.USER) {
688 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
691 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
693 withStyles({}, { withTheme: true }))
694 ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
695 const { uuid, responsiblePersonName, parentRef, theme } = props;
697 if (!uuid && parentRef) {
698 parentRef.style.display = 'none';
700 } else if (parentRef) {
701 parentRef.style.display = 'block';
704 if (!responsiblePersonName) {
705 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
710 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
711 {responsiblePersonName} ({uuid})
715 const renderType = (type: string, subtype: string) =>
717 {resourceLabel(type, subtype)}
720 export const ResourceType = connect(
721 (state: RootState, props: { uuid: string }) => {
722 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
723 return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
724 })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
726 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
727 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
728 })((props: { resource: GroupContentsResource }) =>
729 (props.resource && props.resource.kind === ResourceKind.COLLECTION)
730 ? <CollectionStatus uuid={props.resource.uuid} />
731 : <ProcessStatus uuid={props.resource.uuid} />
734 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
735 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
736 })((props: { collection: CollectionResource }) =>
737 (props.collection.uuid !== props.collection.currentVersionUuid)
738 ? <Typography>version {props.collection.version}</Typography>
739 : <Typography>head version</Typography>
742 export const ProcessStatus = compose(
743 connect((state: RootState, props: { uuid: string }) => {
744 return { process: getProcess(props.uuid)(state.resources) };
746 withStyles({}, { withTheme: true }))
747 ((props: { process?: Process, theme: ArvadosTheme }) => {
748 const status = props.process ? getProcessStatus(props.process) : "-";
751 style={{ color: getProcessStatusColor(status, props.theme) }} >
756 export const ProcessStartDate = connect(
757 (state: RootState, props: { uuid: string }) => {
758 const process = getProcess(props.uuid)(state.resources);
759 return { date: (process && process.container) ? process.container.startedAt : '' };
760 })((props: { date: string }) => renderDate(props.date));
762 export const renderRunTime = (time: number) =>
763 <Typography noWrap style={{ minWidth: '45px' }}>
764 {formatTime(time, true)}
767 interface ContainerRunTimeProps {
771 interface ContainerRunTimeState {
775 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
776 return { process: getProcess(props.uuid)(state.resources) };
777 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
780 constructor(props: ContainerRunTimeProps) {
782 this.state = { runtime: this.getRuntime() };
786 return this.props.process ? getProcessRuntime(this.props.process) : 0;
790 this.setState({ runtime: this.getRuntime() });
793 componentDidMount() {
794 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
797 componentWillUnmount() {
798 clearInterval(this.timer);
802 return renderRunTime(this.state.runtime);