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