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';
38 import { VirtualMachinesResource } from 'models/virtual-machines';
40 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
42 const navFunc = ("groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo);
43 return <Grid container alignItems="center" wrap="nowrap" spacing={16}>
48 <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} onClick={() => dispatch<any>(navFunc(item.uuid))}>
49 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
50 ? <IllegalNamingWarning name={item.name} />
56 <Typography variant="caption">
57 <FavoriteStar resourceUuid={item.uuid} />
58 <PublicFavoriteStar resourceUuid={item.uuid} />
64 export const ResourceName = connect(
65 (state: RootState, props: { uuid: string }) => {
66 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
68 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
70 const renderIcon = (item: GroupContentsResource) => {
72 case ResourceKind.PROJECT:
73 if (item.groupClass === GroupClass.FILTER) {
74 return <FilterGroupIcon />;
76 return <ProjectIcon />;
77 case ResourceKind.COLLECTION:
78 if (item.uuid === item.currentVersionUuid) {
79 return <CollectionIcon />;
81 return <CollectionOldVersionIcon />;
82 case ResourceKind.PROCESS:
83 return <ProcessIcon />;
84 case ResourceKind.WORKFLOW:
85 return <WorkflowIcon />;
87 return <DefaultIcon />;
91 const renderDate = (date?: string) => {
92 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
95 const renderWorkflowName = (item: WorkflowResource) =>
96 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
101 <Typography color="primary" style={{ width: '100px' }}>
107 export const ResourceWorkflowName = connect(
108 (state: RootState, props: { uuid: string }) => {
109 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
111 })(renderWorkflowName);
113 const getPublicUuid = (uuidPrefix: string) => {
114 return `${uuidPrefix}-tpzed-anonymouspublic`;
117 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
118 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
121 {!isPublic && uuid &&
122 <Tooltip title="Share">
123 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
132 export const ResourceShare = connect(
133 (state: RootState, props: { uuid: string }) => {
134 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
135 const uuidPrefix = getUuidPrefix(state);
137 uuid: resource ? resource.uuid : '',
138 ownerUuid: resource ? resource.ownerUuid : '',
141 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
142 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
145 const renderFirstName = (item: { firstName: string }) => {
146 return <Typography noWrap>{item.firstName}</Typography>;
149 export const ResourceFirstName = connect(
150 (state: RootState, props: { uuid: string }) => {
151 const resource = getResource<UserResource>(props.uuid)(state.resources);
152 return resource || { firstName: '' };
155 const renderLastName = (item: { lastName: string }) =>
156 <Typography noWrap>{item.lastName}</Typography>;
158 export const ResourceLastName = connect(
159 (state: RootState, props: { uuid: string }) => {
160 const resource = getResource<UserResource>(props.uuid)(state.resources);
161 return resource || { lastName: '' };
164 const renderFullName = (item: { firstName: string, lastName: string }) =>
165 <Typography noWrap>{(item.firstName + " " + item.lastName).trim()}</Typography>;
167 export const ResourceFullName = connect(
168 (state: RootState, props: { uuid: string }) => {
169 const resource = getResource<UserResource>(props.uuid)(state.resources);
170 return resource || { firstName: '', lastName: '' };
174 const renderUuid = (item: { uuid: string }) =>
175 <Typography data-cy="uuid" noWrap>{item.uuid}</Typography>;
177 export const ResourceUuid = connect(
178 (state: RootState, props: { uuid: string }) => {
179 const resource = getResource<UserResource>(props.uuid)(state.resources);
180 return resource || { uuid: '' };
183 const renderEmail = (item: { email: string }) =>
184 <Typography noWrap>{item.email}</Typography>;
186 export const ResourceEmail = connect(
187 (state: RootState, props: { uuid: string }) => {
188 const resource = getResource<UserResource>(props.uuid)(state.resources);
189 return resource || { email: '' };
192 const renderIsActive = (props: { uuid: string, kind: ResourceKind, isActive: boolean, toggleIsActive: (uuid: string) => void, disabled?: boolean }) => {
193 if (props.kind === ResourceKind.USER) {
196 checked={props.isActive}
197 disabled={!!props.disabled}
198 onClick={() => props.toggleIsActive(props.uuid)} />;
200 return <Typography />;
204 export const ResourceIsActive = connect(
205 (state: RootState, props: { uuid: string, disabled?: boolean }) => {
206 const resource = getResource<UserResource>(props.uuid)(state.resources);
207 return resource ? {...resource, disabled: !!props.disabled} : { isActive: false, kind: ResourceKind.NONE };
208 }, { toggleIsActive }
211 export const ResourceLinkTailIsActive = connect(
212 (state: RootState, props: { uuid: string, disabled?: boolean }) => {
213 const link = getResource<LinkResource>(props.uuid)(state.resources);
214 const tailResource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
216 return tailResource ? {...tailResource, disabled: !!props.disabled} : { isActive: false, kind: ResourceKind.NONE };
217 }, { toggleIsActive }
220 const renderIsHidden = (props: {
221 memberLinkUuid: string,
222 permissionLinkUuid: string,
225 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void
227 if (props.memberLinkUuid) {
229 data-cy="user-visible-checkbox"
231 checked={props.visible}
232 disabled={!props.canManage}
233 onClick={() => props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible)} />;
235 return <Typography />;
239 export const ResourceLinkTailIsVisible = connect(
240 (state: RootState, props: { uuid: string }) => {
241 const link = getResource<LinkResource>(props.uuid)(state.resources);
242 const member = getResource<Resource>(link?.tailUuid || '')(state.resources);
243 const group = getResource<GroupResource>(link?.headUuid || '')(state.resources);
244 const permissions = filterResources((resource: LinkResource) => {
245 return resource.linkClass === LinkClass.PERMISSION
246 && resource.headUuid === link?.tailUuid
247 && resource.tailUuid === group?.uuid
248 && resource.name === PermissionLevel.CAN_READ;
251 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : '';
252 const isVisible = link && group && permissions.length > 0;
253 // Consider whether the current user canManage this resurce in addition when it's possible
254 const isBuiltin = isBuiltinGroup(link?.headUuid || '');
256 return member?.kind === ResourceKind.USER
257 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
258 : { memberLinkUuid: '', permissionLinkUuid: '', visible: false, canManage: false };
259 }, { setMemberIsHidden }
262 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
265 checked={props.isAdmin}
266 onClick={() => props.toggleIsAdmin(props.uuid)} />;
268 export const ResourceIsAdmin = connect(
269 (state: RootState, props: { uuid: string }) => {
270 const resource = getResource<UserResource>(props.uuid)(state.resources);
271 return resource || { isAdmin: false };
275 const renderUsername = (item: { username: string, uuid: string }) =>
276 <Typography noWrap>{item.username || item.uuid}</Typography>;
278 export const ResourceUsername = connect(
279 (state: RootState, props: { uuid: string }) => {
280 const resource = getResource<UserResource>(props.uuid)(state.resources);
281 return resource || { username: '', uuid: props.uuid };
284 // Virtual machine resource
286 const renderHostname = (item: { hostname: string }) =>
287 <Typography noWrap>{item.hostname}</Typography>;
289 export const VirtualMachineHostname = connect(
290 (state: RootState, props: { uuid: string }) => {
291 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
292 return resource || { hostname: '' };
295 const renderVirtualMachineLogin = (login: {user: string}) =>
296 <Typography noWrap>{login.user}</Typography>
298 export const VirtualMachineLogin = connect(
299 (state: RootState, props: { linkUuid: string }) => {
300 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
301 const user = getResource<UserResource>(permission?.tailUuid || '')(state.resources);
303 return {user: user?.username || permission?.tailUuid || ''};
304 })(renderVirtualMachineLogin);
307 const renderCommonData = (data: string) =>
308 <Typography noWrap>{data}</Typography>;
310 const renderCommonDate = (date: string) =>
311 <Typography noWrap>{formatDate(date)}</Typography>;
313 export const CommonUuid = withResourceData('uuid', renderCommonData);
315 // Api Client Authorizations
316 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
318 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
320 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
322 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
324 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
326 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
328 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
330 export const TokenScopes = withResourceData('scopes', renderCommonData);
332 export const TokenUserId = withResourceData('userId', renderCommonData);
334 const clusterColors = [
342 export const ResourceCluster = (props: { uuid: string }) => {
343 const CLUSTER_ID_LENGTH = 5;
344 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5;
345 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : '';
346 const ci = pos >= CLUSTER_ID_LENGTH ? (((((
347 (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1))
348 + props.uuid.charCodeAt(2))
349 * props.uuid.charCodeAt(3))
350 + props.uuid.charCodeAt(4))) % clusterColors.length) : 0;
351 return <span style={{
352 backgroundColor: clusterColors[ci][0],
353 color: clusterColors[ci][1],
356 }}>{clusterId}</span>;
360 const renderLinkName = (item: { name: string }) =>
361 <Typography noWrap>{item.name || '(none)'}</Typography>;
363 export const ResourceLinkName = connect(
364 (state: RootState, props: { uuid: string }) => {
365 const resource = getResource<LinkResource>(props.uuid)(state.resources);
366 return resource || { name: '' };
369 const renderLinkClass = (item: { linkClass: string }) =>
370 <Typography noWrap>{item.linkClass}</Typography>;
372 export const ResourceLinkClass = connect(
373 (state: RootState, props: { uuid: string }) => {
374 const resource = getResource<LinkResource>(props.uuid)(state.resources);
375 return resource || { linkClass: '' };
378 const getResourceDisplayName = (resource: Resource): string => {
379 if ((resource as UserResource).kind === ResourceKind.USER
380 && typeof (resource as UserResource).firstName !== 'undefined') {
381 // We can be sure the resource is UserResource
382 return getUserDisplayName(resource as UserResource);
384 return (resource as GroupContentsResource).name;
388 const renderResourceLink = (dispatch: Dispatch, item: Resource) => {
389 var displayName = getResourceDisplayName(item);
391 return <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
392 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || '' : '')}: {displayName || item.uuid}
396 export const ResourceLinkTail = connect(
397 (state: RootState, props: { uuid: string }) => {
398 const resource = getResource<LinkResource>(props.uuid)(state.resources);
399 const tailResource = getResource<Resource>(resource?.tailUuid || '')(state.resources);
402 item: tailResource || { uuid: resource?.tailUuid || '', kind: resource?.tailKind || ResourceKind.NONE }
404 })((props: { item: Resource } & DispatchProp<any>) =>
405 renderResourceLink(props.dispatch, props.item));
407 export const ResourceLinkHead = connect(
408 (state: RootState, props: { uuid: string }) => {
409 const resource = getResource<LinkResource>(props.uuid)(state.resources);
410 const headResource = getResource<Resource>(resource?.headUuid || '')(state.resources);
413 item: headResource || { uuid: resource?.headUuid || '', kind: resource?.headKind || ResourceKind.NONE }
415 })((props: { item: Resource } & DispatchProp<any>) =>
416 renderResourceLink(props.dispatch, props.item));
418 export const ResourceLinkUuid = connect(
419 (state: RootState, props: { uuid: string }) => {
420 const resource = getResource<LinkResource>(props.uuid)(state.resources);
421 return resource || { uuid: '' };
424 export const ResourceLinkHeadUuid = connect(
425 (state: RootState, props: { uuid: string }) => {
426 const link = getResource<LinkResource>(props.uuid)(state.resources);
427 const headResource = getResource<Resource>(link?.headUuid || '')(state.resources);
429 return headResource || { uuid: '' };
432 export const ResourceLinkTailUuid = connect(
433 (state: RootState, props: { uuid: string }) => {
434 const link = getResource<LinkResource>(props.uuid)(state.resources);
435 const tailResource = getResource<Resource>(link?.tailUuid || '')(state.resources);
437 return tailResource || { uuid: '' };
440 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
444 <IconButton data-cy="resource-delete-button" onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}>
449 <IconButton disabled data-cy="resource-delete-button">
454 return <Typography noWrap></Typography>;
458 export const ResourceLinkDelete = connect(
459 (state: RootState, props: { uuid: string }) => {
460 const link = getResource<LinkResource>(props.uuid)(state.resources);
461 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
464 item: link || { uuid: '', kind: ResourceKind.NONE },
465 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
467 })((props: { item: LinkResource, canManage: boolean } & DispatchProp<any>) =>
468 renderLinkDelete(props.dispatch, props.item, props.canManage));
470 export const ResourceLinkTailEmail = connect(
471 (state: RootState, props: { uuid: string }) => {
472 const link = getResource<LinkResource>(props.uuid)(state.resources);
473 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
475 return resource || { email: '' };
478 export const ResourceLinkTailUsername = connect(
479 (state: RootState, props: { uuid: string }) => {
480 const link = getResource<LinkResource>(props.uuid)(state.resources);
481 const resource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
483 return resource || { username: '' };
486 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
487 return <Typography noWrap>
488 {formatPermissionLevel(link.name as PermissionLevel)}
490 <IconButton data-cy="edit-permission-button" onClick={(event) => dispatch<any>(openPermissionEditContextMenu(event, link))}>
498 export const ResourceLinkHeadPermissionLevel = connect(
499 (state: RootState, props: { uuid: string }) => {
500 const link = getResource<LinkResource>(props.uuid)(state.resources);
501 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
504 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
505 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
507 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
508 renderPermissionLevel(props.dispatch, props.link, props.canManage));
510 export const ResourceLinkTailPermissionLevel = connect(
511 (state: RootState, props: { uuid: string }) => {
512 const link = getResource<LinkResource>(props.uuid)(state.resources);
513 const isBuiltin = isBuiltinGroup(link?.headUuid || '') || isBuiltinGroup(link?.tailUuid || '');
516 link: link || { uuid: '', name: '', kind: ResourceKind.NONE },
517 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
519 })((props: { link: LinkResource, canManage: boolean } & DispatchProp<any>) =>
520 renderPermissionLevel(props.dispatch, props.link, props.canManage));
522 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
523 const headResource = getResource<Resource>(link.headUuid)(state.resources);
524 // const tailResource = getResource<Resource>(link.tailUuid)(state.resources);
525 const userUuid = getUserUuid(state);
527 if (headResource && headResource.kind === ResourceKind.GROUP) {
528 return userUuid ? (headResource as GroupResource).writableBy?.includes(userUuid) : false;
536 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
540 <Tooltip title="Run process">
541 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
549 export const ResourceRunProcess = connect(
550 (state: RootState, props: { uuid: string }) => {
551 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
553 uuid: resource ? resource.uuid : ''
555 })((props: { uuid: string } & DispatchProp<any>) =>
556 resourceRunProcess(props.dispatch, props.uuid));
558 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
559 if (ownerUuid === getPublicUuid(uuidPrefix)) {
560 return renderStatus(WorkflowStatus.PUBLIC);
562 return renderStatus(WorkflowStatus.PRIVATE);
566 const renderStatus = (status: string) =>
567 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
569 export const ResourceWorkflowStatus = connect(
570 (state: RootState, props: { uuid: string }) => {
571 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
572 const uuidPrefix = getUuidPrefix(state);
574 ownerUuid: resource ? resource.ownerUuid : '',
577 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
579 export const ResourceLastModifiedDate = connect(
580 (state: RootState, props: { uuid: string }) => {
581 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
582 return { date: resource ? resource.modifiedAt : '' };
583 })((props: { date: string }) => renderDate(props.date));
585 export const ResourceCreatedAtDate = connect(
586 (state: RootState, props: { uuid: string }) => {
587 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
588 return { date: resource ? resource.createdAt : '' };
589 })((props: { date: string }) => renderDate(props.date));
591 export const ResourceTrashDate = connect(
592 (state: RootState, props: { uuid: string }) => {
593 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
594 return { date: resource ? resource.trashAt : '' };
595 })((props: { date: string }) => renderDate(props.date));
597 export const ResourceDeleteDate = connect(
598 (state: RootState, props: { uuid: string }) => {
599 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
600 return { date: resource ? resource.deleteAt : '' };
601 })((props: { date: string }) => renderDate(props.date));
603 export const renderFileSize = (fileSize?: number) =>
604 <Typography noWrap style={{ minWidth: '45px' }}>
605 {formatFileSize(fileSize)}
608 export const ResourceFileSize = connect(
609 (state: RootState, props: { uuid: string }) => {
610 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
612 if (resource && resource.kind !== ResourceKind.COLLECTION) {
613 return { fileSize: '' };
616 return { fileSize: resource ? resource.fileSizeTotal : 0 };
617 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
619 const renderOwner = (owner: string) =>
624 export const ResourceOwner = connect(
625 (state: RootState, props: { uuid: string }) => {
626 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
627 return { owner: resource ? resource.ownerUuid : '' };
628 })((props: { owner: string }) => renderOwner(props.owner));
630 export const ResourceOwnerName = connect(
631 (state: RootState, props: { uuid: string }) => {
632 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
633 const ownerNameState = state.ownerName;
634 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
635 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
636 })((props: { owner: string }) => renderOwner(props.owner));
640 (state: RootState, props: { uuid: string }) => {
641 let userFullname = '';
642 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
645 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
648 return { uuid: props.uuid, userFullname };
651 export const ResourceOwnerWithName =
654 withStyles({}, { withTheme: true }))
655 ((props: { uuid: string, userFullname: string, dispatch: Dispatch, theme: ArvadosTheme }) => {
656 const { uuid, userFullname, dispatch, theme } = props;
658 if (userFullname === '') {
659 dispatch<any>(loadResource(uuid, false));
660 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
665 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
666 {userFullname} ({uuid})
670 export const UserNameFromID =
672 (props: { uuid: string, userFullname: string, dispatch: Dispatch }) => {
673 const { uuid, userFullname, dispatch } = props;
675 if (userFullname === '') {
676 dispatch<any>(loadResource(uuid, false));
679 {userFullname ? userFullname : uuid}
683 export const ResponsiblePerson =
686 (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
687 let responsiblePersonName: string = '';
688 let responsiblePersonUUID: string = '';
689 let responsiblePersonProperty: string = '';
691 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
693 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
695 while (!responsiblePersonProperty && keys[index]) {
696 const key = keys[index];
697 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
698 responsiblePersonProperty = key;
704 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
706 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
707 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
708 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
711 if (resource && resource.kind === ResourceKind.USER) {
712 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
715 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
717 withStyles({}, { withTheme: true }))
718 ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
719 const { uuid, responsiblePersonName, parentRef, theme } = props;
721 if (!uuid && parentRef) {
722 parentRef.style.display = 'none';
724 } else if (parentRef) {
725 parentRef.style.display = 'block';
728 if (!responsiblePersonName) {
729 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
734 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
735 {responsiblePersonName} ({uuid})
739 const renderType = (type: string, subtype: string) =>
741 {resourceLabel(type, subtype)}
744 export const ResourceType = connect(
745 (state: RootState, props: { uuid: string }) => {
746 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
747 return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' };
748 })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype));
750 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
751 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
752 })((props: { resource: GroupContentsResource }) =>
753 (props.resource && props.resource.kind === ResourceKind.COLLECTION)
754 ? <CollectionStatus uuid={props.resource.uuid} />
755 : <ProcessStatus uuid={props.resource.uuid} />
758 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
759 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
760 })((props: { collection: CollectionResource }) =>
761 (props.collection.uuid !== props.collection.currentVersionUuid)
762 ? <Typography>version {props.collection.version}</Typography>
763 : <Typography>head version</Typography>
766 export const ProcessStatus = compose(
767 connect((state: RootState, props: { uuid: string }) => {
768 return { process: getProcess(props.uuid)(state.resources) };
770 withStyles({}, { withTheme: true }))
771 ((props: { process?: Process, theme: ArvadosTheme }) => {
772 const status = props.process ? getProcessStatus(props.process) : "-";
775 style={{ color: getProcessStatusColor(status, props.theme) }} >
780 export const ProcessStartDate = connect(
781 (state: RootState, props: { uuid: string }) => {
782 const process = getProcess(props.uuid)(state.resources);
783 return { date: (process && process.container) ? process.container.startedAt : '' };
784 })((props: { date: string }) => renderDate(props.date));
786 export const renderRunTime = (time: number) =>
787 <Typography noWrap style={{ minWidth: '45px' }}>
788 {formatTime(time, true)}
791 interface ContainerRunTimeProps {
795 interface ContainerRunTimeState {
799 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
800 return { process: getProcess(props.uuid)(state.resources) };
801 })(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
804 constructor(props: ContainerRunTimeProps) {
806 this.state = { runtime: this.getRuntime() };
810 return this.props.process ? getProcessRuntime(this.props.process) : 0;
814 this.setState({ runtime: this.getRuntime() });
817 componentDidMount() {
818 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
821 componentWillUnmount() {
822 clearInterval(this.timer);
826 return renderRunTime(this.state.runtime);