1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
14 } from '@material-ui/core';
15 import { FavoriteStar, PublicFavoriteStar } from '../favorite-star/favorite-star';
16 import { Resource, ResourceKind, TrashableResource } from 'models/resource';
25 CollectionOldVersionIcon,
32 } from 'components/icon/icon';
33 import { formatDate, formatFileSize, formatTime } from 'common/formatters';
34 import { resourceLabel } from 'common/labels';
35 import { connect, DispatchProp } from 'react-redux';
36 import { RootState } from 'store/store';
37 import { getResource, filterResources } from 'store/resources/resources';
38 import { GroupContentsResource } from 'services/groups-service/groups-service';
39 import { getProcess, Process, getProcessStatus, getProcessStatusStyles, getProcessRuntime } from 'store/processes/process';
40 import { ArvadosTheme } from 'common/custom-theme';
41 import { compose, Dispatch } from 'redux';
42 import { WorkflowResource } from 'models/workflow';
43 import { ResourceStatus as WorkflowStatus } from 'views/workflow-panel/workflow-panel-view';
44 import { getUuidPrefix, openRunProcess } from 'store/workflow-panel/workflow-panel-actions';
45 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
46 import { getUserFullname, getUserDisplayName, User, UserResource } from 'models/user';
47 import { toggleIsAdmin } from 'store/users/users-actions';
48 import { LinkClass, LinkResource } from 'models/link';
49 import { navigateTo, navigateToGroupDetails, navigateToUserProfile } from 'store/navigation/navigation-action';
50 import { withResourceData } from 'views-components/data-explorer/with-resources';
51 import { CollectionResource } from 'models/collection';
52 import { IllegalNamingWarning } from 'components/warning/warning';
53 import { loadResource } from 'store/resources/resources-actions';
54 import { BuiltinGroups, getBuiltinGroupUuid, GroupClass, GroupResource, isBuiltinGroup } from 'models/group';
55 import { openRemoveGroupMemberDialog } from 'store/group-details-panel/group-details-panel-actions';
56 import { setMemberIsHidden } from 'store/group-details-panel/group-details-panel-actions';
57 import { formatPermissionLevel } from 'views-components/sharing-dialog/permission-select';
58 import { PermissionLevel } from 'models/permission';
59 import { openPermissionEditContextMenu } from 'store/context-menu/context-menu-actions';
60 import { VirtualMachinesResource } from 'models/virtual-machines';
61 import { CopyToClipboardSnackbar } from 'components/copy-to-clipboard-snackbar/copy-to-clipboard-snackbar';
62 import { ProjectResource } from 'models/project';
63 import { ProcessResource } from 'models/process';
66 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
67 const navFunc = ("groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo);
68 return <Grid container alignItems="center" wrap="nowrap" spacing={16}>
73 <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} onClick={() => dispatch<any>(navFunc(item.uuid))}>
74 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
75 ? <IllegalNamingWarning name={item.name} />
81 <Typography variant="caption">
82 <FavoriteStar resourceUuid={item.uuid} />
83 <PublicFavoriteStar resourceUuid={item.uuid} />
85 item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />
93 const FrozenProject = (props: { item: ProjectResource }) => {
94 const [fullUsername, setFullusername] = React.useState<any>(null);
95 const getFullName = React.useCallback(() => {
96 if (props.item.frozenByUuid) {
97 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
99 }, [props.item, setFullusername])
101 if (props.item.frozenByUuid) {
103 return <Tooltip onOpen={getFullName} enterDelay={500} title={<span>Project was frozen by {fullUsername}</span>}>
104 <FreezeIcon style={{ fontSize: "inherit" }} />
111 export const ResourceName = connect(
112 (state: RootState, props: { uuid: string }) => {
113 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
115 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
118 const renderIcon = (item: GroupContentsResource) => {
120 case ResourceKind.PROJECT:
121 if (item.groupClass === GroupClass.FILTER) {
122 return <FilterGroupIcon />;
124 return <ProjectIcon />;
125 case ResourceKind.COLLECTION:
126 if (item.uuid === item.currentVersionUuid) {
127 return <CollectionIcon />;
129 return <CollectionOldVersionIcon />;
130 case ResourceKind.PROCESS:
131 return <ProcessIcon />;
132 case ResourceKind.WORKFLOW:
133 return <WorkflowIcon />;
135 return <DefaultIcon />;
139 const renderDate = (date?: string) => {
140 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
143 const renderWorkflowName = (item: WorkflowResource) =>
144 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
149 <Typography color="primary" style={{ width: '100px' }}>
155 export const ResourceWorkflowName = connect(
156 (state: RootState, props: { uuid: string }) => {
157 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
159 })(renderWorkflowName);
161 const getPublicUuid = (uuidPrefix: string) => {
162 return `${uuidPrefix}-tpzed-anonymouspublic`;
165 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
166 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
169 {!isPublic && uuid &&
170 <Tooltip title="Share">
171 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
180 export const ResourceShare = connect(
181 (state: RootState, props: { uuid: string }) => {
182 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
183 const uuidPrefix = getUuidPrefix(state);
185 uuid: resource ? resource.uuid : '',
186 ownerUuid: resource ? resource.ownerUuid : '',
189 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
190 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
193 const renderFirstName = (item: { firstName: string }) => {
194 return <Typography noWrap>{item.firstName}</Typography>;
197 export const ResourceFirstName = connect(
198 (state: RootState, props: { uuid: string }) => {
199 const resource = getResource<UserResource>(props.uuid)(state.resources);
200 return resource || { firstName: '' };
203 const renderLastName = (item: { lastName: string }) =>
204 <Typography noWrap>{item.lastName}</Typography>;
206 export const ResourceLastName = connect(
207 (state: RootState, props: { uuid: string }) => {
208 const resource = getResource<UserResource>(props.uuid)(state.resources);
209 return resource || { lastName: '' };
212 const renderFullName = (dispatch: Dispatch, item: { uuid: string, firstName: string, lastName: string }, link?: boolean) => {
213 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
214 return link ? <Typography noWrap
216 style={{ 'cursor': 'pointer' }}
217 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}>
220 <Typography noWrap>{displayName}</Typography>;
223 export const UserResourceFullName = connect(
224 (state: RootState, props: { uuid: string, link?: boolean }) => {
225 const resource = getResource<UserResource>(props.uuid)(state.resources);
226 return { item: resource || { uuid: '', firstName: '', lastName: '' }, link: props.link };
227 })((props: { item: { uuid: string, firstName: string, lastName: string }, link?: boolean } & DispatchProp<any>) => renderFullName(props.dispatch, props.item, props.link));
229 const renderUuid = (item: { uuid: string }) =>
230 <Typography data-cy="uuid" noWrap>
232 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || '-'}
235 const renderUuidCopyIcon = (item: { uuid: string }) =>
236 <Typography data-cy="uuid" noWrap>
237 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || '-'}
240 export const ResourceUuid = connect((state: RootState, props: { uuid: string }) => (
241 getResource<UserResource>(props.uuid)(state.resources) || { uuid: '' }
244 const renderEmail = (item: { email: string }) =>
245 <Typography noWrap>{item.email}</Typography>;
247 export const ResourceEmail = connect(
248 (state: RootState, props: { uuid: string }) => {
249 const resource = getResource<UserResource>(props.uuid)(state.resources);
250 return resource || { email: '' };
253 enum UserAccountStatus {
255 INACTIVE = 'Inactive',
260 const renderAccountStatus = (props: { status: UserAccountStatus }) =>
261 <Grid container alignItems="center" wrap="nowrap" spacing={8} data-cy="account-status">
264 switch (props.status) {
265 case UserAccountStatus.ACTIVE:
266 return <ActiveIcon style={{ color: '#4caf50', verticalAlign: "middle" }} />;
267 case UserAccountStatus.SETUP:
268 return <SetupIcon style={{ color: '#2196f3', verticalAlign: "middle" }} />;
269 case UserAccountStatus.INACTIVE:
270 return <InactiveIcon style={{ color: '#9e9e9e', verticalAlign: "middle" }} />;
283 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
284 const user = getResource<UserResource>(props.uuid)(state.resources);
285 // Get membership links for all users group
286 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
287 const permissions = filterResources((resource: LinkResource) =>
288 resource.kind === ResourceKind.LINK &&
289 resource.linkClass === LinkClass.PERMISSION &&
290 resource.headUuid === allUsersGroupUuid &&
291 resource.tailUuid === props.uuid
295 return user.isActive ? { status: UserAccountStatus.ACTIVE } : permissions.length > 0 ? { status: UserAccountStatus.SETUP } : { status: UserAccountStatus.INACTIVE };
297 return { status: UserAccountStatus.UNKNOWN };
301 export const ResourceLinkTailAccountStatus = connect(
302 (state: RootState, props: { uuid: string }) => {
303 const link = getResource<LinkResource>(props.uuid)(state.resources);
304 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
305 })(renderAccountStatus);
307 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
309 const renderIsHidden = (props: {
310 memberLinkUuid: string,
311 permissionLinkUuid: string,
314 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void
316 if (props.memberLinkUuid) {
318 data-cy="user-visible-checkbox"
320 checked={props.visible}
321 disabled={!props.canManage}
324 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
327 return <Typography />;
331 export const ResourceLinkTailIsVisible = connect(
332 (state: RootState, props: { uuid: string }) => {
333 const link = getResource<LinkResource>(props.uuid)(state.resources);
334 const member = getResource<Resource>(link?.tailUuid || '')(state.resources);
335 const group = getResource<GroupResource>(link?.headUuid || '')(state.resources);
336 const permissions = filterResources((resource: LinkResource) => {
337 return resource.linkClass === LinkClass.PERMISSION
338 && resource.headUuid === link?.tailUuid
339 && resource.tailUuid === group?.uuid
340 && resource.name === PermissionLevel.CAN_READ;
343 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : '';
344 const isVisible = link && group && permissions.length > 0;
345 // Consider whether the current user canManage this resurce in addition when it's possible
346 const isBuiltin = isBuiltinGroup(link?.headUuid || '');
348 return member?.kind === ResourceKind.USER
349 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
350 : { memberLinkUuid: '', permissionLinkUuid: '', visible: false, canManage: false };
351 }, { setMemberIsHidden }
354 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
357 checked={props.isAdmin}
360 props.toggleIsAdmin(props.uuid);
363 export const ResourceIsAdmin = connect(
364 (state: RootState, props: { uuid: string }) => {
365 const resource = getResource<UserResource>(props.uuid)(state.resources);
366 return resource || { isAdmin: false };
370 const renderUsername = (item: { username: string, uuid: string }) =>
371 <Typography noWrap>{item.username || item.uuid}</Typography>;
373 export const ResourceUsername = connect(
374 (state: RootState, props: { uuid: string }) => {
375 const resource = getResource<UserResource>(props.uuid)(state.resources);
376 return resource || { username: '', uuid: props.uuid };
379 // Virtual machine resource
381 const renderHostname = (item: { hostname: string }) =>
382 <Typography noWrap>{item.hostname}</Typography>;
384 export const VirtualMachineHostname = connect(
385 (state: RootState, props: { uuid: string }) => {
386 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
387 return resource || { hostname: '' };
390 const renderVirtualMachineLogin = (login: { user: string }) =>
391 <Typography noWrap>{login.user}</Typography>
393 export const VirtualMachineLogin = connect(
394 (state: RootState, props: { linkUuid: string }) => {
395 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
396 const user = getResource<UserResource>(permission?.tailUuid || '')(state.resources);
398 return { user: user?.username || permission?.tailUuid || '' };
399 })(renderVirtualMachineLogin);
402 const renderCommonData = (data: string) =>
403 <Typography noWrap>{data}</Typography>;
405 const renderCommonDate = (date: string) =>
406 <Typography noWrap>{formatDate(date)}</Typography>;
408 export const CommonUuid = withResourceData('uuid', renderCommonData);
410 // Api Client Authorizations
411 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
413 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
415 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
417 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
419 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
421 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
423 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
425 export const TokenScopes = withResourceData('scopes', renderCommonData);
427 export const TokenUserId = withResourceData('userId', renderCommonData);
429 const clusterColors = [
437 export const ResourceCluster = (props: { uuid: string }) => {
438 const CLUSTER_ID_LENGTH = 5;
439 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
440 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : '';
441 const ci = pos >= CLUSTER_ID_LENGTH ? (((((
442 (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
443 + props.uuid.charCodeAt(2))
444 * props.uuid.charCodeAt(3))
445 + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
446 return <span style={{
447 backgroundColor: clusterColors[ci][0],
448 color: clusterColors[ci][1],
451 }}>{clusterId}</span>;
455 const renderLinkName = (item: { name: string }) =>
456 <Typography noWrap>{item.name || '-'}</Typography>;
458 export const ResourceLinkName = connect(
459 (state: RootState, props: { uuid: string }) => {
460 const resource = getResource<LinkResource>(props.uuid)(state.resources);
461 return resource || { name: '' };
464 const renderLinkClass = (item: { linkClass: string }) =>
465 <Typography noWrap>{item.linkClass}</Typography>;
467 export const ResourceLinkClass = connect(
468 (state: RootState, props: { uuid: string }) => {
469 const resource = getResource<LinkResource>(props.uuid)(state.resources);
470 return resource || { linkClass: '' };
473 const getResourceDisplayName = (resource: Resource): string => {
474 if ((resource as UserResource).kind === ResourceKind.USER
475 && typeof (resource as UserResource).firstName !== 'undefined') {
476 // We can be sure the resource is UserResource
477 return getUserDisplayName(resource as UserResource);
479 return (resource as GroupContentsResource).name;
483 const renderResourceLink = (dispatch: Dispatch, item: Resource) => {
484 var displayName = getResourceDisplayName(item);
486 return <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
487 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || '' : '')}: {displayName || item.uuid}
491 export const ResourceLinkTail = connect(
492 (state: RootState, props: { uuid: string }) => {
493 const resource = getResource<LinkResource>(props.uuid)(state.resources);
494 const tailResource = getResource<Resource>(resource?.tailUuid || '')(state.resources);
497 item: tailResource || { uuid: resource?.tailUuid || '', kind: resource?.tailKind || ResourceKind.NONE }
499 })((props: { item: Resource } & DispatchProp<any>) =>
500 renderResourceLink(props.dispatch, props.item));
502 export const ResourceLinkHead = connect(
503 (state: RootState, props: { uuid: string }) => {
504 const resource = getResource<LinkResource>(props.uuid)(state.resources);
505 const headResource = getResource<Resource>(resource?.headUuid || '')(state.resources);
508 item: headResource || { uuid: resource?.headUuid || '', kind: resource?.headKind || ResourceKind.NONE }
510 })((props: { item: Resource } & DispatchProp<any>) =>
511 renderResourceLink(props.dispatch, props.item));
513 export const ResourceLinkUuid = connect(
514 (state: RootState, props: { uuid: string }) => {
515 const resource = getResource<LinkResource>(props.uuid)(state.resources);
516 return resource || { uuid: '' };
519 export const ResourceLinkHeadUuid = connect(
520 (state: RootState, props: { uuid: string }) => {
521 const link = getResource<LinkResource>(props.uuid)(state.resources);
522 const headResource = getResource<Resource>(link?.headUuid || '')(state.resources);
524 return headResource || { uuid: '' };
527 export const ResourceLinkTailUuid = connect(
528 (state: RootState, props: { uuid: string }) => {
529 const link = getResource<LinkResource>(props.uuid)(state.resources);
530 const tailResource = getResource<Resource>(link?.tailUuid || '')(state.resources);
532 return tailResource || { uuid: '' };
535 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
539 <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
544 <IconButton disabled data-cy="resource-delete-button">
549 return <Typography noWrap></Typography>;
553 export const ResourceLinkDelete = connect(
554 (state: RootState, props: { uuid: string }) => {
555 const link = getResource<LinkResource>(props.uuid)(state.resources);
556 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
559 item: link || { uuid: '', kind: ResourceKind.NONE },
560 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
562 })((props: { item: LinkResource, canManage: boolean } & DispatchProp<any>) =>
563 renderLinkDelete(props.dispatch, props.item, props.canManage));
565 export const ResourceLinkTailEmail = connect(
566 (state: RootState, props: { uuid: string }) => {
567 const link = getResource<LinkResource>(props.uuid)(state.resources);
568 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
570 return resource || { email: '' };
573 export const ResourceLinkTailUsername = connect(
574 (state: RootState, props: { uuid: string }) => {
575 const link = getResource<LinkResource>(props.uuid)(state.resources);
576 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
578 return resource || { username: '' };
581 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
582 return <Typography noWrap>
583 {formatPermissionLevel(link.name as PermissionLevel)}
585 <IconButton data-cy="edit-permission-button" onClick={(event) => dispatch<any>(openPermissionEditContextMenu(event, link))}>
593 export const ResourceLinkHeadPermissionLevel = connect(
594 (state: RootState, props: { uuid: string }) => {
595 const link = getResource<LinkResource>(props.uuid)(state.resources);
596 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
599 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
600 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
602 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
603 renderPermissionLevel(props.dispatch, props.link, props.canManage));
605 export const ResourceLinkTailPermissionLevel = connect(
606 (state: RootState, props: { uuid: string }) => {
607 const link = getResource<LinkResource>(props.uuid)(state.resources);
608 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
611 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
612 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
614 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
615 renderPermissionLevel(props.dispatch, props.link, props.canManage));
617 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
618 const headResource = getResource<Resource>(link.headUuid)(state.resources);
619 if (headResource && headResource.kind === ResourceKind.GROUP) {
620 return (headResource as GroupResource).canManage;
628 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
632 <Tooltip title="Run process">
633 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
641 export const ResourceRunProcess = connect(
642 (state: RootState, props: { uuid: string }) => {
643 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
645 uuid: resource ? resource.uuid : ''
647 })((props: { uuid: string } & DispatchProp<any>) =>
648 resourceRunProcess(props.dispatch, props.uuid));
650 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
651 if (ownerUuid === getPublicUuid(uuidPrefix)) {
652 return renderStatus(WorkflowStatus.PUBLIC);
654 return renderStatus(WorkflowStatus.PRIVATE);
658 const renderStatus = (status: string) =>
659 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
661 export const ResourceWorkflowStatus = connect(
662 (state: RootState, props: { uuid: string }) => {
663 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
664 const uuidPrefix = getUuidPrefix(state);
666 ownerUuid: resource ? resource.ownerUuid : '',
669 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
671 export const ResourceContainerUuid = connect(
672 (state: RootState, props: { uuid: string }) => {
673 const process = getProcess(props.uuid)(state.resources)
674 return { uuid: process?.container?.uuid ? process?.container?.uuid : '' };
675 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
677 enum ColumnSelection {
678 OUTPUT_UUID = 'outputUuid',
682 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
683 const selectedColumnUuid = item[column]
684 return <Grid container alignItems="center" wrap="nowrap" >
686 {selectedColumnUuid ?
687 <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} noWrap
688 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}>
694 {selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}
699 export const ResourceOutputUuid = connect(
700 (state: RootState, props: { uuid: string }) => {
701 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
703 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
705 export const ResourceLogUuid = connect(
706 (state: RootState, props: { uuid: string }) => {
707 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
709 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
711 export const ResourceParentProcess = connect(
712 (state: RootState, props: { uuid: string }) => {
713 const process = getProcess(props.uuid)(state.resources)
714 return { parentProcess: process?.containerRequest?.requestingContainerUuid || '' };
715 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
717 export const ResourceModifiedByUserUuid = connect(
718 (state: RootState, props: { uuid: string }) => {
719 const process = getProcess(props.uuid)(state.resources)
720 return { userUuid: process?.containerRequest?.modifiedByUserUuid || '' };
721 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
723 export const ResourceCreatedAtDate = connect(
724 (state: RootState, props: { uuid: string }) => {
725 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
726 return { date: resource ? resource.createdAt : '' };
727 })((props: { date: string }) => renderDate(props.date));
729 export const ResourceLastModifiedDate = connect(
730 (state: RootState, props: { uuid: string }) => {
731 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
732 return { date: resource ? resource.modifiedAt : '' };
733 })((props: { date: string }) => renderDate(props.date));
735 export const ResourceTrashDate = connect(
736 (state: RootState, props: { uuid: string }) => {
737 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
738 return { date: resource ? resource.trashAt : '' };
739 })((props: { date: string }) => renderDate(props.date));
741 export const ResourceDeleteDate = connect(
742 (state: RootState, props: { uuid: string }) => {
743 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
744 return { date: resource ? resource.deleteAt : '' };
745 })((props: { date: string }) => renderDate(props.date));
747 export const renderFileSize = (fileSize?: number) =>
748 <Typography noWrap style={{ minWidth: '45px' }}>
749 {formatFileSize(fileSize)}
752 export const ResourceFileSize = connect(
753 (state: RootState, props: { uuid: string }) => {
754 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
756 if (resource && resource.kind !== ResourceKind.COLLECTION) {
757 return { fileSize: '' };
760 return { fileSize: resource ? resource.fileSizeTotal : 0 };
761 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
763 const renderOwner = (owner: string) =>
768 export const ResourceOwner = connect(
769 (state: RootState, props: { uuid: string }) => {
770 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
771 return { owner: resource ? resource.ownerUuid : '' };
772 })((props: { owner: string }) => renderOwner(props.owner));
774 export const ResourceOwnerName = connect(
775 (state: RootState, props: { uuid: string }) => {
776 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
777 const ownerNameState = state.ownerName;
778 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
779 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
780 })((props: { owner: string }) => renderOwner(props.owner));
782 export const ResourceUUID = connect(
783 (state: RootState, props: { uuid: string }) => {
784 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
785 return { uuid: resource ? resource.uuid : '' };
786 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
788 const renderVersion = (version: number) => {
789 return <Typography>{version ?? '-'}</Typography>
792 export const ResourceVersion = connect(
793 (state: RootState, props: { uuid: string }) => {
794 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
795 return { version: resource ? resource.version : '' };
796 })((props: { version: number }) => renderVersion(props.version));
798 const renderPortableDataHash = (portableDataHash: string | null) =>
800 {portableDataHash ? <>{portableDataHash}
801 <CopyToClipboardSnackbar value={portableDataHash} /></> : '-'}
804 export const ResourcePortableDataHash = connect(
805 (state: RootState, props: { uuid: string }) => {
806 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
807 return { portableDataHash: resource ? resource.portableDataHash : '' };
808 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
811 const renderFileCount = (fileCount: number) => {
812 return <Typography>{fileCount ?? '-'}</Typography>
815 export const ResourceFileCount = connect(
816 (state: RootState, props: { uuid: string }) => {
817 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
818 return { fileCount: resource ? resource.fileCount : '' };
819 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
823 (state: RootState, props: { uuid: string }) => {
824 let userFullname = '';
825 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
828 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
831 return { uuid: props.uuid, userFullname };
834 const ownerFromResourceId =
836 connect((state: RootState, props: { uuid: string }) => {
837 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
838 return { uuid: childResource ? (childResource as Resource).ownerUuid : '' };
847 const _resourceWithName =
848 withStyles({}, { withTheme: true })
849 ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
850 const { uuid, userFullname, dispatch, theme } = props;
851 if (userFullname === '') {
852 dispatch<any>(loadResource(uuid, false));
853 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
858 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
859 {userFullname} ({uuid})
863 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
865 export const ResourceWithName = userFromID(_resourceWithName);
869 export const UserNameFromID =
871 (props: { uuid: string, displayAsText?: string, userFullname: string, dispatch: Dispatch }) => {
872 const { uuid, userFullname, dispatch } = props;
874 if (userFullname === '') {
875 dispatch<any>(loadResource(uuid, false));
878 {userFullname ? userFullname : uuid}
882 export const ResponsiblePerson =
885 (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
886 let responsiblePersonName: string = '';
887 let responsiblePersonUUID: string = '';
888 let responsiblePersonProperty: string = '';
890 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
892 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
894 while (!responsiblePersonProperty && keys[index]) {
895 const key = keys[index];
896 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
897 responsiblePersonProperty = key;
903 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
905 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
906 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
907 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
910 if (resource && resource.kind === ResourceKind.USER) {
911 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
914 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
916 withStyles({}, { withTheme: true }))
917 ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
918 const { uuid, responsiblePersonName, parentRef, theme } = props;
920 if (!uuid && parentRef) {
921 parentRef.style.display = 'none';
923 } else if (parentRef) {
924 parentRef.style.display = 'block';
927 if (!responsiblePersonName) {
928 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
933 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
934 {responsiblePersonName} ({uuid})
938 const renderType = (type: string, subtype: string) =>
940 {resourceLabel(type, subtype)}
943 export const ResourceType = connect(
944 (state: RootState, props: { uuid: string }) => {
945 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
946 return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
947 })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
949 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
950 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
951 })((props: { resource: GroupContentsResource }) =>
952 (props.resource && props.resource.kind === ResourceKind.COLLECTION)
953 ? <CollectionStatus uuid={props.resource.uuid} />
954 : <ProcessStatus uuid={props.resource.uuid} />
957 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
958 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
959 })((props: { collection: CollectionResource }) =>
960 (props.collection.uuid !== props.collection.currentVersionUuid)
961 ? <Typography>version {props.collection.version}</Typography>
962 : <Typography>head version</Typography>
965 export const CollectionName = connect((state: RootState, props: { uuid: string, className?: string }) => {
967 collection: getResource<CollectionResource>(props.uuid)(state.resources),
969 className: props.className,
971 })((props: { collection: CollectionResource, uuid: string, className?: string }) =>
972 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
975 export const ProcessStatus = compose(
976 connect((state: RootState, props: { uuid: string }) => {
977 return { process: getProcess(props.uuid)(state.resources) };
979 withStyles({}, { withTheme: true }))
980 ((props: { process?: Process, theme: ArvadosTheme }) =>
982 ? <Chip label={getProcessStatus(props.process)}
984 height: props.theme.spacing.unit * 3,
985 width: props.theme.spacing.unit * 12,
986 ...getProcessStatusStyles(
987 getProcessStatus(props.process), props.theme),
988 fontSize: '0.875rem',
989 borderRadius: props.theme.spacing.unit * 0.625,
992 : <Typography>-</Typography>
995 export const ProcessStartDate = connect(
996 (state: RootState, props: { uuid: string }) => {
997 const process = getProcess(props.uuid)(state.resources);
998 return { date: (process && process.container) ? process.container.startedAt : '' };
999 })((props: { date: string }) => renderDate(props.date));
1001 export const renderRunTime = (time: number) =>
1002 <Typography noWrap style={{ minWidth: '45px' }}>
1003 {formatTime(time, true)}
1006 interface ContainerRunTimeProps {
1010 interface ContainerRunTimeState {
1014 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1015 return { process: getProcess(props.uuid)(state.resources) };
1016 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1019 constructor(props: ContainerRunTimeProps) {
1021 this.state = { runtime: this.getRuntime() };
1025 return this.props.process ? getProcessRuntime(this.props.process) : 0;
1029 this.setState({ runtime: this.getRuntime() });
1032 componentDidMount() {
1033 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1036 componentWillUnmount() {
1037 clearInterval(this.timer);
1041 return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;