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, disabled?: boolean }) => {
192 if (props.kind === ResourceKind.USER) {
195 checked={props.isActive}
196 disabled={!!props.disabled}
197 onClick={() => props.toggleIsActive(props.uuid)} />;
199 return <Typography />;
203 export const ResourceIsActive = connect(
204 (state: RootState, props: { uuid: string, disabled?: boolean }) => {
205 const resource = getResource<UserResource>(props.uuid)(state.resources);
206 return resource ? {...resource, disabled: !!props.disabled} : { isActive: false, kind: ResourceKind.NONE };
207 }, { toggleIsActive }
210 export const ResourceLinkTailIsActive = connect(
211 (state: RootState, props: { uuid: string, disabled?: boolean }) => {
212 const link = getResource<LinkResource>(props.uuid)(state.resources);
213 const tailResource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
215 return tailResource ? {...tailResource, disabled: !!props.disabled} : { isActive: false, kind: ResourceKind.NONE };
216 }, { toggleIsActive }
219 const renderIsHidden = (props: {
220 memberLinkUuid: string,
221 permissionLinkUuid: string,
224 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void
226 if (props.memberLinkUuid) {
228 data-cy="user-visible-checkbox"
230 checked={props.visible}
231 disabled={!props.canManage}
232 onClick={() => props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible)} />;
234 return <Typography />;
238 export const ResourceLinkTailIsVisible = connect(
239 (state: RootState, props: { uuid: string }) => {
240 const link = getResource<LinkResource>(props.uuid)(state.resources);
241 const member = getResource<Resource>(link?.tailUuid || '')(state.resources);
242 const group = getResource<GroupResource>(link?.headUuid || '')(state.resources);
243 const permissions = filterResources((resource: LinkResource) => {
244 return resource.linkClass === LinkClass.PERMISSION
245 && resource.headUuid === link?.tailUuid
246 && resource.tailUuid === group?.uuid
247 && resource.name === PermissionLevel.CAN_READ;
250 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : '';
251 const isVisible = link && group && permissions.length > 0;
252 // Consider whether the current user canManage this resurce in addition when it's possible
253 const isBuiltin = isBuiltinGroup(link?.headUuid || '');
255 return member?.kind === ResourceKind.USER
256 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
257 : { memberLinkUuid: '', permissionLinkUuid: '', visible: false, canManage: false };
258 }, { setMemberIsHidden }
261 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
264 checked={props.isAdmin}
265 onClick={() => props.toggleIsAdmin(props.uuid)} />;
267 export const ResourceIsAdmin = connect(
268 (state: RootState, props: { uuid: string }) => {
269 const resource = getResource<UserResource>(props.uuid)(state.resources);
270 return resource || { isAdmin: false };
274 const renderUsername = (item: { username: string }) =>
275 <Typography noWrap>{item.username}</Typography>;
277 export const ResourceUsername = connect(
278 (state: RootState, props: { uuid: string }) => {
279 const resource = getResource<UserResource>(props.uuid)(state.resources);
280 return resource || { username: '' };
284 const renderCommonData = (data: string) =>
285 <Typography noWrap>{data}</Typography>;
287 const renderCommonDate = (date: string) =>
288 <Typography noWrap>{formatDate(date)}</Typography>;
290 export const CommonUuid = withResourceData('uuid', renderCommonData);
292 // Api Client Authorizations
293 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
295 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
297 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
299 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
301 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
303 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
305 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
307 export const TokenScopes = withResourceData('scopes', renderCommonData);
309 export const TokenUserId = withResourceData('userId', renderCommonData);
311 const clusterColors = [
319 export const ResourceCluster = (props: { uuid: string }) => {
320 const CLUSTER_ID_LENGTH = 5;
321 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
322 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : '';
323 const ci = pos >= CLUSTER_ID_LENGTH ? (((((
324 (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
325 + props.uuid.charCodeAt(2))
326 * props.uuid.charCodeAt(3))
327 + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
328 return <span style={{
329 backgroundColor: clusterColors[ci][0],
330 color: clusterColors[ci][1],
333 }}>{clusterId}</span>;
337 const renderLinkName = (item: { name: string }) =>
338 <Typography noWrap>{item.name || '(none)'}</Typography>;
340 export const ResourceLinkName = connect(
341 (state: RootState, props: { uuid: string }) => {
342 const resource = getResource<LinkResource>(props.uuid)(state.resources);
343 return resource || { name: '' };
346 const renderLinkClass = (item: { linkClass: string }) =>
347 <Typography noWrap>{item.linkClass}</Typography>;
349 export const ResourceLinkClass = connect(
350 (state: RootState, props: { uuid: string }) => {
351 const resource = getResource<LinkResource>(props.uuid)(state.resources);
352 return resource || { linkClass: '' };
355 const getResourceDisplayName = (resource: Resource): string => {
356 if ((resource as UserResource).kind === ResourceKind.USER
357 && typeof (resource as UserResource).firstName !== 'undefined') {
358 // We can be sure the resource is UserResource
359 return getUserDisplayName(resource as UserResource);
361 return (resource as GroupContentsResource).name;
365 const renderResourceLink = (dispatch: Dispatch, item: Resource) => {
366 var displayName = getResourceDisplayName(item);
368 return <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
369 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || '' : '')}: {displayName || item.uuid}
373 export const ResourceLinkTail = connect(
374 (state: RootState, props: { uuid: string }) => {
375 const resource = getResource<LinkResource>(props.uuid)(state.resources);
376 const tailResource = getResource<Resource>(resource?.tailUuid || '')(state.resources);
379 item: tailResource || { uuid: resource?.tailUuid || '', kind: resource?.tailKind || ResourceKind.NONE }
381 })((props: { item: Resource } & DispatchProp<any>) =>
382 renderResourceLink(props.dispatch, props.item));
384 export const ResourceLinkHead = connect(
385 (state: RootState, props: { uuid: string }) => {
386 const resource = getResource<LinkResource>(props.uuid)(state.resources);
387 const headResource = getResource<Resource>(resource?.headUuid || '')(state.resources);
390 item: headResource || { uuid: resource?.headUuid || '', kind: resource?.headKind || ResourceKind.NONE }
392 })((props: { item: Resource } & DispatchProp<any>) =>
393 renderResourceLink(props.dispatch, props.item));
395 export const ResourceLinkUuid = connect(
396 (state: RootState, props: { uuid: string }) => {
397 const resource = getResource<LinkResource>(props.uuid)(state.resources);
398 return resource || { uuid: '' };
401 export const ResourceLinkHeadUuid = connect(
402 (state: RootState, props: { uuid: string }) => {
403 const link = getResource<LinkResource>(props.uuid)(state.resources);
404 const headResource = getResource<Resource>(link?.headUuid || '')(state.resources);
406 return headResource || { uuid: '' };
409 export const ResourceLinkTailUuid = connect(
410 (state: RootState, props: { uuid: string }) => {
411 const link = getResource<LinkResource>(props.uuid)(state.resources);
412 const tailResource = getResource<Resource>(link?.tailUuid || '')(state.resources);
414 return tailResource || { uuid: '' };
417 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
421 <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
426 <IconButton disabled data-cy="resource-delete-button">
431 return <Typography noWrap></Typography>;
435 export const ResourceLinkDelete = connect(
436 (state: RootState, props: { uuid: string }) => {
437 const link = getResource<LinkResource>(props.uuid)(state.resources);
438 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
441 item: link || { uuid: '', kind: ResourceKind.NONE },
442 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
444 })((props: { item: LinkResource, canManage: boolean } & DispatchProp<any>) =>
445 renderLinkDelete(props.dispatch, props.item, props.canManage));
447 export const ResourceLinkTailEmail = connect(
448 (state: RootState, props: { uuid: string }) => {
449 const link = getResource<LinkResource>(props.uuid)(state.resources);
450 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
452 return resource || { email: '' };
455 export const ResourceLinkTailUsername = connect(
456 (state: RootState, props: { uuid: string }) => {
457 const link = getResource<LinkResource>(props.uuid)(state.resources);
458 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
460 return resource || { username: '' };
463 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
464 return <Typography noWrap>
465 {formatPermissionLevel(link.name as PermissionLevel)}
467 <IconButton data-cy="edit-permission-button" onClick={(event) => dispatch<any>(openPermissionEditContextMenu(event, link))}>
475 export const ResourceLinkHeadPermissionLevel = connect(
476 (state: RootState, props: { uuid: string }) => {
477 const link = getResource<LinkResource>(props.uuid)(state.resources);
478 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
481 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
482 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
484 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
485 renderPermissionLevel(props.dispatch, props.link, props.canManage));
487 export const ResourceLinkTailPermissionLevel = connect(
488 (state: RootState, props: { uuid: string }) => {
489 const link = getResource<LinkResource>(props.uuid)(state.resources);
490 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
493 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
494 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
496 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
497 renderPermissionLevel(props.dispatch, props.link, props.canManage));
499 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
500 const headResource = getResource<Resource>(link.headUuid)(state.resources);
501 // const tailResource = getResource<Resource>(link.tailUuid)(state.resources);
502 const userUuid = getUserUuid(state);
504 if (headResource && headResource.kind === ResourceKind.GROUP) {
505 return userUuid ? (headResource as GroupResource).writableBy?.includes(userUuid) : false;
513 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
517 <Tooltip title="Run process">
518 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
526 export const ResourceRunProcess = connect(
527 (state: RootState, props: { uuid: string }) => {
528 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
530 uuid: resource ? resource.uuid : ''
532 })((props: { uuid: string } & DispatchProp<any>) =>
533 resourceRunProcess(props.dispatch, props.uuid));
535 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
536 if (ownerUuid === getPublicUuid(uuidPrefix)) {
537 return renderStatus(WorkflowStatus.PUBLIC);
539 return renderStatus(WorkflowStatus.PRIVATE);
543 const renderStatus = (status: string) =>
544 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
546 export const ResourceWorkflowStatus = connect(
547 (state: RootState, props: { uuid: string }) => {
548 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
549 const uuidPrefix = getUuidPrefix(state);
551 ownerUuid: resource ? resource.ownerUuid : '',
554 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
556 export const ResourceLastModifiedDate = connect(
557 (state: RootState, props: { uuid: string }) => {
558 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
559 return { date: resource ? resource.modifiedAt : '' };
560 })((props: { date: string }) => renderDate(props.date));
562 export const ResourceCreatedAtDate = connect(
563 (state: RootState, props: { uuid: string }) => {
564 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
565 return { date: resource ? resource.createdAt : '' };
566 })((props: { date: string }) => renderDate(props.date));
568 export const ResourceTrashDate = connect(
569 (state: RootState, props: { uuid: string }) => {
570 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
571 return { date: resource ? resource.trashAt : '' };
572 })((props: { date: string }) => renderDate(props.date));
574 export const ResourceDeleteDate = connect(
575 (state: RootState, props: { uuid: string }) => {
576 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
577 return { date: resource ? resource.deleteAt : '' };
578 })((props: { date: string }) => renderDate(props.date));
580 export const renderFileSize = (fileSize?: number) =>
581 <Typography noWrap style={{ minWidth: '45px' }}>
582 {formatFileSize(fileSize)}
585 export const ResourceFileSize = connect(
586 (state: RootState, props: { uuid: string }) => {
587 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
589 if (resource && resource.kind !== ResourceKind.COLLECTION) {
590 return { fileSize: '' };
593 return { fileSize: resource ? resource.fileSizeTotal : 0 };
594 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
596 const renderOwner = (owner: string) =>
601 export const ResourceOwner = connect(
602 (state: RootState, props: { uuid: string }) => {
603 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
604 return { owner: resource ? resource.ownerUuid : '' };
605 })((props: { owner: string }) => renderOwner(props.owner));
607 export const ResourceOwnerName = connect(
608 (state: RootState, props: { uuid: string }) => {
609 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
610 const ownerNameState = state.ownerName;
611 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
612 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
613 })((props: { owner: string }) => renderOwner(props.owner));
617 (state: RootState, props: { uuid: string }) => {
618 let userFullname = '';
619 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
622 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
625 return { uuid: props.uuid, userFullname };
628 export const ResourceOwnerWithName =
631 withStyles({}, { withTheme: true }))
632 ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
633 const { uuid, userFullname, dispatch, theme } = props;
635 if (userFullname === '') {
636 dispatch<any>(loadResource(uuid, false));
637 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
642 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
643 {userFullname} ({uuid})
647 export const UserNameFromID =
649 (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
650 const { uuid, userFullname, dispatch } = props;
652 if (userFullname === '') {
653 dispatch<any>(loadResource(uuid, false));
656 {userFullname ? userFullname : uuid}
660 export const ResponsiblePerson =
663 (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
664 let responsiblePersonName: string = '';
665 let responsiblePersonUUID: string = '';
666 let responsiblePersonProperty: string = '';
668 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
670 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
672 while (!responsiblePersonProperty && keys[index]) {
673 const key = keys[index];
674 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
675 responsiblePersonProperty = key;
681 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
683 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
684 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
685 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
688 if (resource && resource.kind === ResourceKind.USER) {
689 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
692 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
694 withStyles({}, { withTheme: true }))
695 ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
696 const { uuid, responsiblePersonName, parentRef, theme } = props;
698 if (!uuid && parentRef) {
699 parentRef.style.display = 'none';
701 } else if (parentRef) {
702 parentRef.style.display = 'block';
705 if (!responsiblePersonName) {
706 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
711 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
712 {responsiblePersonName} ({uuid})
716 const renderType = (type: string, subtype: string) =>
718 {resourceLabel(type, subtype)}
721 export const ResourceType = connect(
722 (state: RootState, props: { uuid: string }) => {
723 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
724 return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
725 })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
727 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
728 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
729 })((props: { resource: GroupContentsResource }) =>
730 (props.resource && props.resource.kind === ResourceKind.COLLECTION)
731 ? <CollectionStatus uuid={props.resource.uuid} />
732 : <ProcessStatus uuid={props.resource.uuid} />
735 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
736 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
737 })((props: { collection: CollectionResource }) =>
738 (props.collection.uuid !== props.collection.currentVersionUuid)
739 ? <Typography>version {props.collection.version}</Typography>
740 : <Typography>head version</Typography>
743 export const ProcessStatus = compose(
744 connect((state: RootState, props: { uuid: string }) => {
745 return { process: getProcess(props.uuid)(state.resources) };
747 withStyles({}, { withTheme: true }))
748 ((props: { process?: Process, theme: ArvadosTheme }) => {
749 const status = props.process ? getProcessStatus(props.process) : "-";
752 style={{ color: getProcessStatusColor(status, props.theme) }} >
757 export const ProcessStartDate = connect(
758 (state: RootState, props: { uuid: string }) => {
759 const process = getProcess(props.uuid)(state.resources);
760 return { date: (process && process.container) ? process.container.startedAt : '' };
761 })((props: { date: string }) => renderDate(props.date));
763 export const renderRunTime = (time: number) =>
764 <Typography noWrap style={{ minWidth: '45px' }}>
765 {formatTime(time, true)}
768 interface ContainerRunTimeProps {
772 interface ContainerRunTimeState {
776 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
777 return { process: getProcess(props.uuid)(state.resources) };
778 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
781 constructor(props: ContainerRunTimeProps) {
783 this.state = { runtime: this.getRuntime() };
787 return this.props.process ? getProcessRuntime(this.props.process) : 0;
791 this.setState({ runtime: this.getRuntime() });
794 componentDidMount() {
795 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
798 componentWillUnmount() {
799 clearInterval(this.timer);
803 return renderRunTime(this.state.runtime);