]> git.arvados.org - arvados.git/blob - services/workbench2/src/views-components/data-explorer/renderers.tsx
22159: fixed group details username display
[arvados.git] / services / workbench2 / src / views-components / data-explorer / renderers.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { Grid, Typography, Tooltip, IconButton, Checkbox, Chip } from "@mui/material";
7 import withStyles from '@mui/styles/withStyles';
8 import withTheme from '@mui/styles/withTheme';
9 import { FavoriteStar, PublicFavoriteStar } from "../favorite-star/favorite-star";
10 import { Resource, ResourceKind, TrashableResource } from "models/resource";
11 import {
12     FreezeIcon,
13     ProjectIcon,
14     FilterGroupIcon,
15     CollectionIcon,
16     ProcessIcon,
17     DefaultIcon,
18     ShareIcon,
19     CollectionOldVersionIcon,
20     WorkflowIcon,
21     RemoveIcon,
22     RenameIcon,
23     ActiveIcon,
24     SetupIcon,
25     InactiveIcon,
26     ErrorIcon,
27 } from "components/icon/icon";
28 import { formatDate, formatFileSize, formatTime } from "common/formatters";
29 import { resourceLabel } from "common/labels";
30 import { connect, DispatchProp } from "react-redux";
31 import { RootState } from "store/store";
32 import { getResource, filterResources } from "store/resources/resources";
33 import { GroupContentsResource } from "services/groups-service/groups-service";
34 import { getProcess, Process, getProcessStatus, getProcessStatusStyles, getProcessRuntime } from "store/processes/process";
35 import { ArvadosTheme } from "common/custom-theme";
36 import { compose, Dispatch } from "redux";
37 import { WorkflowResource } from "models/workflow";
38 import { ResourceStatus as WorkflowStatus } from "views/workflow-panel/workflow-panel-view";
39 import { getUuidPrefix, openRunProcess } from "store/workflow-panel/workflow-panel-actions";
40 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
41 import { getUserFullname, getUserDisplayName, User, UserResource } from "models/user";
42 import { LinkClass, LinkResource } from "models/link";
43 import { navigateTo, navigateToGroupDetails, navigateToUserProfile } from "store/navigation/navigation-action";
44 import { withResourceData } from "views-components/data-explorer/with-resources";
45 import { CollectionResource } from "models/collection";
46 import { IllegalNamingWarning } from "components/warning/warning";
47 import { loadResource } from "store/resources/resources-actions";
48 import { BuiltinGroups, getBuiltinGroupUuid, GroupClass, GroupResource, isBuiltinGroup } from "models/group";
49 import { openRemoveGroupMemberDialog } from "store/group-details-panel/group-details-panel-actions";
50 import { setMemberIsHidden } from "store/group-details-panel/group-details-panel-actions";
51 import { formatPermissionLevel } from "views-components/sharing-dialog/permission-select";
52 import { PermissionLevel } from "models/permission";
53 import { openPermissionEditContextMenu } from "store/context-menu/context-menu-actions";
54 import { VirtualMachinesResource } from "models/virtual-machines";
55 import { CopyToClipboardSnackbar } from "components/copy-to-clipboard-snackbar/copy-to-clipboard-snackbar";
56 import { ProjectResource } from "models/project";
57 import { ProcessResource } from "models/process";
58 import { ServiceRepository } from "services/services";
59 import { loadUsersPanel } from "store/users/users-actions";
60 import { InlinePulser } from "components/loading/inline-pulser";
61 import { ProcessTypeFilter } from "store/resource-type-filters/resource-type-filters";
62 import { CustomTheme } from "common/custom-theme";
63 import { dispatchAction } from "common/dispatch-action";
64 import { getProperty } from "store/properties/properties";
65 import { ClusterBadge } from "store/auth/cluster-badges";
66 import { PermissionResource } from 'models/permission';
67
68 export const toggleIsAdmin = (uuid: string) =>
69     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
70         const { resources } = getState();
71         const data = getResource<UserResource>(uuid)(resources);
72         const isAdmin = data!.isAdmin;
73         const newActivity = await services.userService.update(uuid, { isAdmin: !isAdmin });
74         dispatch<any>(loadUsersPanel());
75         return newActivity;
76     };
77
78 export const renderName = (item: GroupContentsResource) => {
79     const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
80     return (
81         <Grid
82             container
83             alignItems="center"
84             wrap="nowrap"
85             spacing={2}
86         >
87             <Grid item style={{color: CustomTheme.palette.grey['600'] }}>{renderIcon(item)}</Grid>
88             <Grid item>
89                 <Typography
90                     color="primary"
91                     style={{ width: "auto", cursor: "pointer" }}
92                     onClick={(ev) => {
93                         ev.stopPropagation()
94                         dispatchAction(navFunc, item.uuid)
95                     }}
96                 >
97                     {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
98                     {item.name}
99                 </Typography>
100             </Grid>
101             <Grid item>
102                 <Typography variant="caption">
103                     <FavoriteStar resourceUuid={item.uuid} />
104                     <PublicFavoriteStar resourceUuid={item.uuid} />
105                     {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
106                 </Typography>
107             </Grid>
108         </Grid>
109     );
110 };
111
112 export const FrozenProject = (props: { item: ProjectResource }) => {
113     const [fullUsername, setFullusername] = React.useState<any>(null);
114     const getFullName = React.useCallback(() => {
115         if (props.item.frozenByUuid) {
116             setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
117         }
118     }, [props.item, setFullusername]);
119
120     if (props.item.frozenByUuid) {
121         return (
122             <Tooltip
123                 onOpen={getFullName}
124                 enterDelay={500}
125                 title={<span>Project was frozen by {fullUsername}</span>}
126             >
127                 <FreezeIcon style={{ fontSize: "inherit" }} />
128             </Tooltip>
129         );
130     } else {
131         return null;
132     }
133 };
134
135 // export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
136 //     const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
137 //     return resource;
138 // })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource));
139
140 const renderIcon = (item: GroupContentsResource) => {
141     switch (item.kind) {
142         case ResourceKind.PROJECT:
143             if (item.groupClass === GroupClass.FILTER) {
144                 return <FilterGroupIcon />;
145             }
146             return <ProjectIcon />;
147         case ResourceKind.COLLECTION:
148             if (item.uuid === item.currentVersionUuid) {
149                 return <CollectionIcon />;
150             }
151             return <CollectionOldVersionIcon />;
152         case ResourceKind.PROCESS:
153             return <ProcessIcon />;
154         case ResourceKind.WORKFLOW:
155             return <WorkflowIcon />;
156         default:
157             return <DefaultIcon />;
158     }
159 };
160
161 const renderDate = (date?: string) => {
162     return (
163         <Typography
164             noWrap
165             style={{ minWidth: "100px" }}
166         >
167             {formatDate(date)}
168         </Typography>
169     );
170 };
171
172 const renderWorkflowName = (item: WorkflowResource) => (
173     <Grid
174         container
175         alignItems="center"
176         wrap="nowrap"
177         spacing={2}
178     >
179         <Grid item>{renderIcon(item)}</Grid>
180         <Grid item>
181             <Typography
182                 color="primary"
183                 style={{ width: "100px" }}
184             >
185                 {item.name}
186             </Typography>
187         </Grid>
188     </Grid>
189 );
190
191 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
192     const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
193     return resource;
194 })(renderWorkflowName);
195
196 const getPublicUuid = (uuidPrefix: string) => {
197     return `${uuidPrefix}-tpzed-anonymouspublic`;
198 };
199
200 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
201     const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
202     return (
203         <div>
204             {!isPublic && uuid && (
205                 <Tooltip title="Share">
206                     <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))} size="large">
207                         <ShareIcon />
208                     </IconButton>
209                 </Tooltip>
210             )}
211         </div>
212     );
213 };
214
215 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
216     const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
217     const uuidPrefix = getUuidPrefix(state);
218     return {
219         uuid: resource ? resource.uuid : "",
220         ownerUuid: resource ? resource.ownerUuid : "",
221         uuidPrefix,
222     };
223 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
224     resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
225 );
226
227 // User Resources
228 const renderFirstName = (item: { firstName: string }) => {
229     return <Typography noWrap>{item.firstName}</Typography>;
230 };
231
232 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
233     const resource = getResource<UserResource>(props.uuid)(state.resources);
234     return resource || { firstName: "" };
235 })(renderFirstName);
236
237 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
238
239 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
240     const resource = getResource<UserResource>(props.uuid)(state.resources);
241     return resource || { lastName: "" };
242 })(renderLastName);
243
244 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
245     const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
246     return link ? (
247         <Typography
248             noWrap
249             color="primary"
250             style={{ cursor: "pointer" }}
251             onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
252         >
253             {displayName}
254         </Typography>
255     ) : (
256         <Typography noWrap>{displayName}</Typography>
257     );
258 };
259
260 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
261     const resource = getResource<UserResource>(props.uuid)(state.resources);
262     return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
263 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
264     renderFullName(props.dispatch, props.item, props.link)
265 );
266
267 const renderUuid = (item: { uuid: string }) => (
268     <Typography
269         data-cy="uuid"
270         noWrap
271     >
272         {item.uuid}
273         {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
274     </Typography>
275 );
276
277 const renderUuidCopyIcon = (item: { uuid: string }) => (
278     <Typography
279         data-cy="uuid"
280         noWrap
281     >
282         {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
283     </Typography>
284 );
285
286 export const ResourceUuid = connect(
287     (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
288 )(renderUuid);
289
290 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
291
292 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
293     const resource = getResource<UserResource>(props.uuid)(state.resources);
294     return resource || { email: "" };
295 })(renderEmail);
296
297 enum UserAccountStatus {
298     ACTIVE = "Active",
299     INACTIVE = "Inactive",
300     SETUP = "Setup",
301     UNKNOWN = "",
302 }
303
304 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
305     <Grid
306         container
307         alignItems="center"
308         wrap="nowrap"
309         spacing={1}
310         data-cy="account-status"
311     >
312         <Grid item>
313             {(() => {
314                 switch (props.status) {
315                     case UserAccountStatus.ACTIVE:
316                         return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
317                     case UserAccountStatus.SETUP:
318                         return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
319                     case UserAccountStatus.INACTIVE:
320                         return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
321                     default:
322                         return <></>;
323                 }
324             })()}
325         </Grid>
326         <Grid item>
327             <Typography noWrap>{props.status}</Typography>
328         </Grid>
329     </Grid>
330 );
331
332 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
333     const user = getResource<UserResource>(props.uuid)(state.resources);
334     // Get membership links for all users group
335     const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
336     const permissions = filterResources(
337         (resource: LinkResource) =>
338             resource.kind === ResourceKind.LINK &&
339             resource.linkClass === LinkClass.PERMISSION &&
340             resource.headUuid === allUsersGroupUuid &&
341             resource.tailUuid === props.uuid
342     )(state.resources);
343
344     if (user) {
345         return user.isActive
346             ? { status: UserAccountStatus.ACTIVE }
347             : permissions.length > 0
348             ? { status: UserAccountStatus.SETUP }
349             : { status: UserAccountStatus.INACTIVE };
350     } else {
351         return { status: UserAccountStatus.UNKNOWN };
352     }
353 };
354
355 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
356     const link = getResource<LinkResource>(props.uuid)(state.resources);
357     return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
358 })(renderAccountStatus);
359
360 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
361
362 const renderIsHidden = (props: {
363     memberLinkUuid: string;
364     permissionLinkUuid: string;
365     visible: boolean;
366     canManage: boolean;
367     setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
368 }) => {
369     if (props.memberLinkUuid) {
370         return (
371             <Checkbox
372                 data-cy="user-visible-checkbox"
373                 color="primary"
374                 checked={props.visible}
375                 disabled={!props.canManage}
376                 onClick={e => {
377                     e.stopPropagation();
378                     props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
379                 }}
380             />
381         );
382     } else {
383         return <Typography />;
384     }
385 };
386
387 export const ResourceLinkTailIsVisible = connect(
388     (state: RootState, props: { uuid: string }) => {
389         const link = getResource<LinkResource>(props.uuid)(state.resources);
390         const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
391         const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
392         const permissions = filterResources((resource: LinkResource) => {
393             return (
394                 resource.linkClass === LinkClass.PERMISSION &&
395                 resource.headUuid === link?.tailUuid &&
396                 resource.tailUuid === group?.uuid &&
397                 resource.name === PermissionLevel.CAN_READ
398             );
399         })(state.resources);
400
401         const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
402         const isVisible = link && group && permissions.length > 0;
403         // Consider whether the current user canManage this resurce in addition when it's possible
404         const isBuiltin = isBuiltinGroup(link?.headUuid || "");
405
406         return member?.kind === ResourceKind.USER
407             ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
408             : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
409     },
410     { setMemberIsHidden }
411 )(renderIsHidden);
412
413 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
414     <Checkbox
415         color="primary"
416         checked={props.isAdmin}
417         onClick={e => {
418             e.stopPropagation();
419             props.toggleIsAdmin(props.uuid);
420         }}
421     />
422 );
423
424 export const ResourceIsAdmin = connect(
425     (state: RootState, props: { uuid: string }) => {
426         const resource = getResource<UserResource>(props.uuid)(state.resources);
427         return resource || { isAdmin: false };
428     },
429     { toggleIsAdmin }
430 )(renderIsAdmin);
431
432 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
433
434 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
435     const resource = getResource<UserResource>(props.uuid)(state.resources);
436     return resource || { username: "", uuid: props.uuid };
437 })(renderUsername);
438
439 // Virtual machine resource
440
441 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
442
443 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
444     const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
445     return resource || { hostname: "" };
446 })(renderHostname);
447
448 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
449
450 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
451     const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
452     const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
453
454     return { user: user?.username || permission?.tailUuid || "" };
455 })(renderVirtualMachineLogin);
456
457 // Common methods
458 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
459
460 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
461
462 export const CommonUuid = withResourceData("uuid", renderCommonData);
463
464 // Api Client Authorizations
465 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
466
467 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
468
469 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
470
471 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
472
473 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
474
475 export const TokenScopes = withResourceData("scopes", renderCommonData);
476
477 export const TokenUserId = withResourceData("userId", renderCommonData);
478
479 export const ResourceCluster = connect((state: RootState, props: { uuid: string }) => {
480     const clusterId = props.uuid.slice(0, 5)
481     const clusterBadge = getProperty<ClusterBadge[]>('clusterBadges')(state.properties)?.find(badge => badge.text === clusterId);
482     // dark grey is default BG color
483     return clusterBadge || { text: clusterId, color: '#fff', backgroundColor: '#696969' };
484 })(renderClusterBadge);
485
486 function renderClusterBadge(badge: ClusterBadge) {
487     
488     const style = {
489         backgroundColor: badge.backgroundColor,
490         color: badge.color,
491         padding: "2px 7px",
492         borderRadius: 3,
493     };
494
495     return <span style={style}>{badge.text}</span>
496 };
497
498 // Links Resources
499 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
500
501 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
502     const resource = getResource<LinkResource>(props.uuid)(state.resources);
503     return resource || { name: "" };
504 })(renderLinkName);
505
506 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
507
508 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
509     const resource = getResource<LinkResource>(props.uuid)(state.resources);
510     return resource || { linkClass: "" };
511 })(renderLinkClass);
512
513 const getResourceDisplayName = (resource: Resource): string => {
514     if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
515         // We can be sure the resource is UserResource
516         return getUserDisplayName(resource as UserResource);
517     } else {
518         return (resource as GroupContentsResource).name;
519     }
520 };
521
522 const renderResourceLink = (dispatch: Dispatch, item: Resource ) => {
523     var displayName = getResourceDisplayName(item);
524
525     return (
526         <Typography
527             noWrap
528             color="primary"
529             style={{ cursor: "pointer" }}
530             onClick={() => {
531                 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
532                     ? dispatch<any>(navigateToGroupDetails(item.uuid))
533                     : item.kind === ResourceKind.USER
534                     ? dispatch<any>(navigateToUserProfile(item.uuid))
535                     : dispatch<any>(navigateTo(item.uuid));
536             }}
537         >
538             {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
539             {displayName || item.uuid}
540         </Typography>
541     );
542 };
543
544 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
545     const resource = getResource<LinkResource>(props.uuid)(state.resources);
546     const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
547
548     return {
549         item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
550     };
551 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
552
553 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
554     const resource = getResource<LinkResource>(props.uuid)(state.resources);
555     const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
556
557     return {
558         item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
559     };
560 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
561
562 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
563     const resource = getResource<LinkResource>(props.uuid)(state.resources);
564     return resource || { uuid: "" };
565 })(renderUuid);
566
567 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
568     const link = getResource<LinkResource>(props.uuid)(state.resources);
569     const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
570
571     return headResource || { uuid: "" };
572 })(renderUuid);
573
574 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
575     const link = getResource<LinkResource>(props.uuid)(state.resources);
576     const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
577
578     return tailResource || { uuid: "" };
579 })(renderUuid);
580
581 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
582     if (item.uuid) {
583         return canManage ? (
584             <Typography noWrap>
585                 <IconButton
586                     data-cy="resource-delete-button"
587                     onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
588                     size="large">
589                     <RemoveIcon />
590                 </IconButton>
591             </Typography>
592         ) : (
593             <Typography noWrap>
594                 <IconButton disabled data-cy="resource-delete-button" size="large">
595                     <RemoveIcon />
596                 </IconButton>
597             </Typography>
598         );
599     } else {
600         return <Typography noWrap></Typography>;
601     }
602 };
603
604 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
605     const link = getResource<LinkResource>(props.uuid)(state.resources);
606     const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
607
608     return {
609         item: link || { uuid: "", kind: ResourceKind.NONE },
610         canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
611     };
612 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
613
614 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
615     const link = getResource<LinkResource>(props.uuid)(state.resources);
616     const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
617
618     return resource || { email: "" };
619 })(renderEmail);
620
621 export const ResourceLinkTailUsername = connect((state: RootState, props: { resource: PermissionResource }) => {
622     const resource = getResource<UserResource>(props.resource.tailUuid || "")(state.resources);
623     return resource;
624 })((user:UserResource) => <Typography noWrap>{user.username || user.uuid || "-"}</Typography>);
625
626 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
627     return (
628         <Typography noWrap>
629             {formatPermissionLevel(link.name as PermissionLevel)}
630             {canManage ? (
631                 <IconButton
632                     data-cy="edit-permission-button"
633                     onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
634                     size="large">
635                     <RenameIcon />
636                 </IconButton>
637             ) : (
638                 ""
639             )}
640         </Typography>
641     );
642 };
643
644 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
645     const link = getResource<LinkResource>(props.uuid)(state.resources);
646     const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
647
648     return {
649         link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
650         canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
651     };
652 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
653
654 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
655     const link = getResource<LinkResource>(props.uuid)(state.resources);
656     const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
657
658     return {
659         link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
660         canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
661     };
662 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
663
664 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
665     const headResource = getResource<Resource>(link.headUuid)(state.resources);
666     if (headResource && headResource.kind === ResourceKind.GROUP) {
667         return (headResource as GroupResource).canManage;
668     } else {
669         // true for now
670         return true;
671     }
672 };
673
674 // Process Resources
675 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
676     return (
677         <div>
678             {uuid && (
679                 <Tooltip title="Run process">
680                     <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))} size="large">
681                         <ProcessIcon />
682                     </IconButton>
683                 </Tooltip>
684             )}
685         </div>
686     );
687 };
688
689 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
690     const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
691     return {
692         uuid: resource ? resource.uuid : "",
693     };
694 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
695
696 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
697     if (ownerUuid === getPublicUuid(uuidPrefix)) {
698         return renderStatus(WorkflowStatus.PUBLIC);
699     } else {
700         return renderStatus(WorkflowStatus.PRIVATE);
701     }
702 };
703
704 const renderStatus = (status: string) => (
705     <Typography
706         noWrap
707         style={{ width: "60px" }}
708     >
709         {status}
710     </Typography>
711 );
712
713 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
714     const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
715     const uuidPrefix = getUuidPrefix(state);
716     return {
717         ownerUuid: resource ? resource.ownerUuid : "",
718         uuidPrefix,
719     };
720 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
721
722 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
723     const process = getProcess(props.uuid)(state.resources);
724     return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
725 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
726
727 enum ColumnSelection {
728     OUTPUT_UUID = "outputUuid",
729     LOG_UUID = "logUuid",
730 }
731
732 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
733     const selectedColumnUuid = item[column];
734     return (
735         <Grid
736             container
737             alignItems="center"
738             wrap="nowrap"
739         >
740             <Grid item>
741                 {selectedColumnUuid ? (
742                     <Typography
743                         color="primary"
744                         style={{ width: "auto", cursor: "pointer" }}
745                         noWrap
746                         onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
747                     >
748                         {selectedColumnUuid}
749                     </Typography>
750                 ) : (
751                     "-"
752                 )}
753             </Grid>
754             <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
755         </Grid>
756     );
757 };
758
759 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
760     const resource = getResource<ProcessResource>(props.uuid)(state.resources);
761     return resource;
762 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
763
764 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
765     const resource = getResource<ProcessResource>(props.uuid)(state.resources);
766     return resource;
767 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
768
769 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
770     const process = getProcess(props.uuid)(state.resources);
771     return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
772 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
773
774 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
775     const process = getProcess(props.uuid)(state.resources);
776     return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
777 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
778
779 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
780     const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
781     return { date: resource ? resource.createdAt : "" };
782 })((props: { date: string }) => renderDate(props.date));
783
784 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
785     const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
786     return { date: resource ? resource.modifiedAt : "" };
787 })((props: { date: string }) => renderDate(props.date));
788
789 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
790     const resource = getResource<TrashableResource>(props.uuid)(state.resources);
791     return { date: resource ? resource.trashAt : "" };
792 })((props: { date: string }) => renderDate(props.date));
793
794 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
795     const resource = getResource<TrashableResource>(props.uuid)(state.resources);
796     return { date: resource ? resource.deleteAt : "" };
797 })((props: { date: string }) => renderDate(props.date));
798
799 export const renderFileSize = (fileSize?: number) => (
800     <Typography
801         noWrap
802         style={{ minWidth: "45px" }}
803     >
804         {formatFileSize(fileSize)}
805     </Typography>
806 );
807
808 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
809     const resource = getResource<CollectionResource>(props.uuid)(state.resources);
810
811     if (resource && resource.kind !== ResourceKind.COLLECTION) {
812         return { fileSize: "" };
813     }
814
815     return { fileSize: resource ? resource.fileSizeTotal : 0 };
816 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
817
818 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
819
820 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
821     const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
822     return { owner: resource ? resource.ownerUuid : "" };
823 })((props: { owner: string }) => renderOwner(props.owner));
824
825 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
826     const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
827     const ownerNameState = state.ownerName;
828     const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
829     return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
830 })((props: { owner: string }) => renderOwner(props.owner));
831
832 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
833     const resource = getResource<CollectionResource>(props.uuid)(state.resources);
834     return { uuid: resource ? resource.uuid : "" };
835 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
836
837 const renderVersion = (version: number) => {
838     return <Typography>{version ?? "-"}</Typography>;
839 };
840
841 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
842     const resource = getResource<CollectionResource>(props.uuid)(state.resources);
843     return { version: resource ? resource.version : "" };
844 })((props: { version: number }) => renderVersion(props.version));
845
846 const renderPortableDataHash = (portableDataHash: string | null) => (
847     <Typography noWrap>
848         {portableDataHash ? (
849             <>
850                 {portableDataHash}
851                 <CopyToClipboardSnackbar value={portableDataHash} />
852             </>
853         ) : (
854             "-"
855         )}
856     </Typography>
857 );
858
859 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
860     const resource = getResource<CollectionResource>(props.uuid)(state.resources);
861     return { portableDataHash: resource ? resource.portableDataHash : "" };
862 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
863
864 const renderFileCount = (fileCount: number) => {
865     return <Typography>{fileCount ?? "-"}</Typography>;
866 };
867
868 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
869     const resource = getResource<CollectionResource>(props.uuid)(state.resources);
870     return { fileCount: resource ? resource.fileCount : "" };
871 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
872
873 const userFromID = connect((state: RootState, props: { uuid: string }) => {
874     let userFullname = "";
875     const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
876
877     if (resource) {
878         userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
879     }
880
881     return { uuid: props.uuid, userFullname };
882 });
883
884 const ownerFromResourceId = compose(
885     connect((state: RootState, props: { uuid: string }) => {
886         const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
887         return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
888     }),
889     userFromID
890 );
891
892 const _resourceWithName = withStyles(
893     {},
894     { withTheme: true }
895 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
896     const { uuid, userFullname, dispatch, theme } = props;
897     if (userFullname === "") {
898         dispatch<any>(loadResource(uuid, false));
899         return (
900             <Typography
901                 style={{ color: theme.palette.primary.main }}
902                 display="inline"
903             >
904                 {uuid}
905             </Typography>
906         );
907     }
908
909     return (
910         <Typography
911             style={{ color: theme.palette.primary.main }}
912             display="inline"
913         >
914             {userFullname} ({uuid})
915         </Typography>
916     );
917 });
918
919 const _resourceWithNameLink = withStyles(
920     {},
921     { withTheme: true }
922 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
923     const { uuid, userFullname, dispatch, theme } = props;
924     if (!userFullname) {
925         dispatch<any>(loadResource(uuid, false));
926     }
927
928     return (
929         <Typography
930             style={{ color: theme.palette.primary.main, cursor: 'pointer' }}
931             display="inline"
932             noWrap
933             onClick={() => dispatch<any>(navigateTo(uuid))}
934         >
935             {userFullname ? userFullname : uuid}
936         </Typography>
937     )
938 });
939
940
941 export const ResourceOwnerWithNameLink = ownerFromResourceId(_resourceWithNameLink);
942
943 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
944 export const OwnerWithName = connect((state: RootState, props: {resource: GroupContentsResource}) => {
945     const owner= getResource<UserResource>(props.resource.ownerUuid)(state.resources);
946     const ownerName = owner ? getUserDisplayName(owner) : props.resource.ownerUuid;
947     return { ownerName, ownerUuid: props.resource.ownerUuid };
948 })((props: {ownerName: string, ownerUuid: string}) => {
949     return <Typography 
950                 noWrap
951                 style={{ color: CustomTheme.palette.primary.main }}
952                 display="inline"
953             >{`${props.ownerName} (${props.ownerUuid})`}</Typography>;
954 });
955
956
957 export const ResourceWithName = userFromID(_resourceWithName);
958
959 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
960     const { uuid, userFullname, dispatch } = props;
961
962     if (userFullname === "") {
963         dispatch<any>(loadResource(uuid, false));
964     }
965     return <span>{userFullname ? userFullname : uuid}</span>;
966 });
967
968 export const ResponsiblePerson = compose(
969     connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
970         let responsiblePersonName: string = "";
971         let responsiblePersonUUID: string = "";
972         let responsiblePersonProperty: string = "";
973
974         if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
975             let index = 0;
976             const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
977
978             while (!responsiblePersonProperty && keys[index]) {
979                 const key = keys[index];
980                 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
981                     responsiblePersonProperty = key;
982                 }
983                 index++;
984             }
985         }
986
987         let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
988
989         while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
990             responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
991             resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
992         }
993
994         if (resource && resource.kind === ResourceKind.USER) {
995             responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
996         }
997
998         return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
999     }),
1000     withStyles({}, { withTheme: true })
1001 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
1002     const { uuid, responsiblePersonName, parentRef, theme } = props;
1003
1004     if (!uuid && parentRef) {
1005         parentRef.style.display = "none";
1006         return null;
1007     } else if (parentRef) {
1008         parentRef.style.display = "block";
1009     }
1010
1011     if (!responsiblePersonName) {
1012         return (
1013             <Typography
1014                 style={{ color: theme.palette.primary.main }}
1015                 display="inline"
1016                 noWrap
1017             >
1018                 {uuid}
1019             </Typography>
1020         );
1021     }
1022
1023     return (
1024         <Typography
1025             style={{ color: theme.palette.primary.main }}
1026             display="inline"
1027             noWrap
1028         >
1029             {responsiblePersonName} ({uuid})
1030         </Typography>
1031     );
1032 });
1033
1034 export const renderType = (resource: GroupContentsResource | undefined) => {
1035     if(!resource) return <Typography noWrap>-</Typography>;
1036     const type = resource.kind;
1037     const subtype = resource.kind === ResourceKind.GROUP
1038                         ? resource.groupClass
1039                         : resource.kind === ResourceKind.PROCESS
1040                             ? resource.requestingContainerUuid
1041                                 ? ProcessTypeFilter.CHILD_PROCESS
1042                                 : ProcessTypeFilter.MAIN_PROCESS
1043                             : ""
1044     return<Typography noWrap>{resourceLabel(type, subtype)}</Typography>
1045 };
1046
1047 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
1048     const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1049     return resource
1050     // return {
1051     //     type: resource ? resource.kind : "",
1052     //     subtype: resource
1053     //         ? resource.kind === ResourceKind.GROUP
1054     //             ? resource.groupClass
1055     //             : resource.kind === ResourceKind.PROCESS
1056     //                 ? resource.requestingContainerUuid
1057     //                     ? ProcessTypeFilter.CHILD_PROCESS
1058     //                     : ProcessTypeFilter.MAIN_PROCESS
1059     //                 : ""
1060     //         : ""
1061     // };
1062 })((props: { resource: any}) => renderType(props.resource || undefined));
1063
1064 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1065     return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1066 })((props: { resource: GroupContentsResource }) =>
1067     props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1068         <CollectionStatus uuid={props.resource.uuid} />
1069     ) : (
1070         <ProcessStatus uuid={props.resource.uuid} />
1071     )
1072 );
1073
1074 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1075     return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1076 })((props: { collection: CollectionResource }) =>
1077     props.collection.uuid !== props.collection.currentVersionUuid ? (
1078         <Typography>version {props.collection.version}</Typography>
1079     ) : (
1080         <Typography>head version</Typography>
1081     )
1082 );
1083
1084 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1085     return {
1086         collection: getResource<CollectionResource>(props.uuid)(state.resources),
1087         uuid: props.uuid,
1088         className: props.className,
1089     };
1090 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1091     <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1092 ));
1093
1094 export const ProcessStatus = compose(
1095     connect((state: RootState, props: { uuid: string }) => {
1096         return { process: getProcess(props.uuid)(state.resources) };
1097     }),
1098     withStyles({}, { withTheme: true })
1099 )((props: { process?: Process; theme: ArvadosTheme }) =>
1100     props.process ? (
1101         <Chip
1102             data-cy="process-status-chip"
1103             label={getProcessStatus(props.process)}
1104             style={{
1105                 height: props.theme.spacing(3),
1106                 width: props.theme.spacing(12),
1107                 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1108                 fontSize: "0.875rem",
1109                 borderRadius: props.theme.spacing(0.625),
1110             }}
1111         />
1112     ) : (
1113         <Typography>-</Typography>
1114     )
1115 );
1116
1117 export const ProcessStartDate = connect((state: RootState, props: { uuid: string }) => {
1118     const process = getProcess(props.uuid)(state.resources);
1119     return { date: process && process.container ? process.container.startedAt : "" };
1120 })((props: { date: string }) => renderDate(props.date));
1121
1122 export const renderRunTime = (time: number) => (
1123     <Typography
1124         noWrap
1125         style={{ minWidth: "45px" }}
1126     >
1127         {formatTime(time, true)}
1128     </Typography>
1129 );
1130
1131 interface ContainerRunTimeProps {
1132     process: Process;
1133 }
1134
1135 interface ContainerRunTimeState {
1136     runtime: number;
1137 }
1138
1139 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1140     return { process: getProcess(props.uuid)(state.resources) };
1141 })(
1142     class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1143         private timer: any;
1144
1145         constructor(props: ContainerRunTimeProps) {
1146             super(props);
1147             this.state = { runtime: this.getRuntime() };
1148         }
1149
1150         getRuntime() {
1151             return this.props.process ? getProcessRuntime(this.props.process) : 0;
1152         }
1153
1154         updateRuntime() {
1155             this.setState({ runtime: this.getRuntime() });
1156         }
1157
1158         componentDidMount() {
1159             this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1160         }
1161
1162         componentWillUnmount() {
1163             clearInterval(this.timer);
1164         }
1165
1166         render() {
1167             return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;
1168         }
1169     }
1170 );
1171
1172 export const GroupMembersCount = connect(
1173     (state: RootState, props: { uuid: string }) => {
1174         const group = getResource<GroupResource>(props.uuid)(state.resources);
1175
1176         return {
1177             value: group?.memberCount,
1178         };
1179
1180     }
1181 )(withTheme((props: {value: number | null | undefined, theme:ArvadosTheme}) => {
1182     if (props.value === undefined) {
1183         // Loading
1184         return <Typography component={"div"}>
1185             <InlinePulser />
1186         </Typography>;
1187     } else if (props.value === null) {
1188         // Error
1189         return <Typography>
1190             <Tooltip title="Failed to load member count">
1191                 <ErrorIcon style={{color: props.theme.customs.colors.greyL}}/>
1192             </Tooltip>
1193         </Typography>;
1194     } else {
1195         return <Typography children={props.value} />;
1196     }
1197 }));