1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Grid, Typography, 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";
19 CollectionOldVersionIcon,
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";
64 export const toggleIsAdmin = (uuid: string) =>
65 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
66 const { resources } = getState();
67 const data = getResource<UserResource>(uuid)(resources);
68 const isAdmin = data!.isAdmin;
69 const newActivity = await services.userService.update(uuid, { isAdmin: !isAdmin });
70 dispatch<any>(loadUsersPanel());
74 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
75 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
83 <Grid item style={{color: CustomTheme.palette.grey['600'] }}>{renderIcon(item)}</Grid>
87 style={{ width: "auto", cursor: "pointer" }}
90 dispatch<any>(navFunc(item.uuid))
93 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
98 <Typography variant="caption">
99 <FavoriteStar resourceUuid={item.uuid} />
100 <PublicFavoriteStar resourceUuid={item.uuid} />
101 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
108 export const FrozenProject = (props: { item: ProjectResource }) => {
109 const [fullUsername, setFullusername] = React.useState<any>(null);
110 const getFullName = React.useCallback(() => {
111 if (props.item.frozenByUuid) {
112 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
114 }, [props.item, setFullusername]);
116 if (props.item.frozenByUuid) {
121 title={<span>Project was frozen by {fullUsername}</span>}
123 <FreezeIcon style={{ fontSize: "inherit" }} />
131 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
132 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
134 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
136 const renderIcon = (item: GroupContentsResource) => {
138 case ResourceKind.PROJECT:
139 if (item.groupClass === GroupClass.FILTER) {
140 return <FilterGroupIcon />;
142 return <ProjectIcon />;
143 case ResourceKind.COLLECTION:
144 if (item.uuid === item.currentVersionUuid) {
145 return <CollectionIcon />;
147 return <CollectionOldVersionIcon />;
148 case ResourceKind.PROCESS:
149 return <ProcessIcon />;
150 case ResourceKind.WORKFLOW:
151 return <WorkflowIcon />;
153 return <DefaultIcon />;
157 const renderDate = (date?: string) => {
161 style={{ minWidth: "100px" }}
168 const renderWorkflowName = (item: WorkflowResource) => (
175 <Grid item>{renderIcon(item)}</Grid>
179 style={{ width: "100px" }}
187 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
188 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
190 })(renderWorkflowName);
192 const getPublicUuid = (uuidPrefix: string) => {
193 return `${uuidPrefix}-tpzed-anonymouspublic`;
196 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
197 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
200 {!isPublic && uuid && (
201 <Tooltip title="Share">
202 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))} size="large">
211 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
212 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
213 const uuidPrefix = getUuidPrefix(state);
215 uuid: resource ? resource.uuid : "",
216 ownerUuid: resource ? resource.ownerUuid : "",
219 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
220 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
224 const renderFirstName = (item: { firstName: string }) => {
225 return <Typography noWrap>{item.firstName}</Typography>;
228 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
229 const resource = getResource<UserResource>(props.uuid)(state.resources);
230 return resource || { firstName: "" };
233 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
235 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
236 const resource = getResource<UserResource>(props.uuid)(state.resources);
237 return resource || { lastName: "" };
240 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
241 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
246 style={{ cursor: "pointer" }}
247 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
252 <Typography noWrap>{displayName}</Typography>
256 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
257 const resource = getResource<UserResource>(props.uuid)(state.resources);
258 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
259 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
260 renderFullName(props.dispatch, props.item, props.link)
263 const renderUuid = (item: { uuid: string }) => (
269 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
273 const renderUuidCopyIcon = (item: { uuid: string }) => (
278 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
282 export const ResourceUuid = connect(
283 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
286 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
288 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
289 const resource = getResource<UserResource>(props.uuid)(state.resources);
290 return resource || { email: "" };
293 enum UserAccountStatus {
295 INACTIVE = "Inactive",
300 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
306 data-cy="account-status"
310 switch (props.status) {
311 case UserAccountStatus.ACTIVE:
312 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
313 case UserAccountStatus.SETUP:
314 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
315 case UserAccountStatus.INACTIVE:
316 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
323 <Typography noWrap>{props.status}</Typography>
328 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
329 const user = getResource<UserResource>(props.uuid)(state.resources);
330 // Get membership links for all users group
331 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
332 const permissions = filterResources(
333 (resource: LinkResource) =>
334 resource.kind === ResourceKind.LINK &&
335 resource.linkClass === LinkClass.PERMISSION &&
336 resource.headUuid === allUsersGroupUuid &&
337 resource.tailUuid === props.uuid
342 ? { status: UserAccountStatus.ACTIVE }
343 : permissions.length > 0
344 ? { status: UserAccountStatus.SETUP }
345 : { status: UserAccountStatus.INACTIVE };
347 return { status: UserAccountStatus.UNKNOWN };
351 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
352 const link = getResource<LinkResource>(props.uuid)(state.resources);
353 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
354 })(renderAccountStatus);
356 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
358 const renderIsHidden = (props: {
359 memberLinkUuid: string;
360 permissionLinkUuid: string;
363 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
365 if (props.memberLinkUuid) {
368 data-cy="user-visible-checkbox"
370 checked={props.visible}
371 disabled={!props.canManage}
374 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
379 return <Typography />;
383 export const ResourceLinkTailIsVisible = connect(
384 (state: RootState, props: { uuid: string }) => {
385 const link = getResource<LinkResource>(props.uuid)(state.resources);
386 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
387 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
388 const permissions = filterResources((resource: LinkResource) => {
390 resource.linkClass === LinkClass.PERMISSION &&
391 resource.headUuid === link?.tailUuid &&
392 resource.tailUuid === group?.uuid &&
393 resource.name === PermissionLevel.CAN_READ
397 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
398 const isVisible = link && group && permissions.length > 0;
399 // Consider whether the current user canManage this resurce in addition when it's possible
400 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
402 return member?.kind === ResourceKind.USER
403 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
404 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
406 { setMemberIsHidden }
409 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
412 checked={props.isAdmin}
415 props.toggleIsAdmin(props.uuid);
420 export const ResourceIsAdmin = connect(
421 (state: RootState, props: { uuid: string }) => {
422 const resource = getResource<UserResource>(props.uuid)(state.resources);
423 return resource || { isAdmin: false };
428 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
430 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
431 const resource = getResource<UserResource>(props.uuid)(state.resources);
432 return resource || { username: "", uuid: props.uuid };
435 // Virtual machine resource
437 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
439 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
440 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
441 return resource || { hostname: "" };
444 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
446 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
447 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
448 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
450 return { user: user?.username || permission?.tailUuid || "" };
451 })(renderVirtualMachineLogin);
454 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
456 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
458 export const CommonUuid = withResourceData("uuid", renderCommonData);
460 // Api Client Authorizations
461 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
463 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
465 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
467 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
469 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
471 export const TokenScopes = withResourceData("scopes", renderCommonData);
473 export const TokenUserId = withResourceData("userId", renderCommonData);
475 const clusterColors = [
483 export const ResourceCluster = (props: { uuid: string }) => {
484 const CLUSTER_ID_LENGTH = 5;
485 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf("-") : 5;
486 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : "";
488 pos >= CLUSTER_ID_LENGTH
489 ? ((props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1) + props.uuid.charCodeAt(2)) * props.uuid.charCodeAt(3) +
490 props.uuid.charCodeAt(4)) %
496 backgroundColor: clusterColors[ci][0],
497 color: clusterColors[ci][1],
508 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
510 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
511 const resource = getResource<LinkResource>(props.uuid)(state.resources);
512 return resource || { name: "" };
515 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
517 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
518 const resource = getResource<LinkResource>(props.uuid)(state.resources);
519 return resource || { linkClass: "" };
522 const getResourceDisplayName = (resource: Resource): string => {
523 if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
524 // We can be sure the resource is UserResource
525 return getUserDisplayName(resource as UserResource);
527 return (resource as GroupContentsResource).name;
531 const renderResourceLink = (dispatch: Dispatch, item: Resource ) => {
532 var displayName = getResourceDisplayName(item);
538 style={{ cursor: "pointer" }}
540 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
541 ? dispatch<any>(navigateToGroupDetails(item.uuid))
542 : item.kind === ResourceKind.USER
543 ? dispatch<any>(navigateToUserProfile(item.uuid))
544 : dispatch<any>(navigateTo(item.uuid));
547 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
548 {displayName || item.uuid}
553 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
554 const resource = getResource<LinkResource>(props.uuid)(state.resources);
555 const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
558 item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
560 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
562 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
563 const resource = getResource<LinkResource>(props.uuid)(state.resources);
564 const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
567 item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
569 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
571 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
572 const resource = getResource<LinkResource>(props.uuid)(state.resources);
573 return resource || { uuid: "" };
576 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
577 const link = getResource<LinkResource>(props.uuid)(state.resources);
578 const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
580 return headResource || { uuid: "" };
583 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
584 const link = getResource<LinkResource>(props.uuid)(state.resources);
585 const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
587 return tailResource || { uuid: "" };
590 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
595 data-cy="resource-delete-button"
596 onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
603 <IconButton disabled data-cy="resource-delete-button" size="large">
609 return <Typography noWrap></Typography>;
613 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
614 const link = getResource<LinkResource>(props.uuid)(state.resources);
615 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
618 item: link || { uuid: "", kind: ResourceKind.NONE },
619 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
621 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
623 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
624 const link = getResource<LinkResource>(props.uuid)(state.resources);
625 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
627 return resource || { email: "" };
630 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
631 const link = getResource<LinkResource>(props.uuid)(state.resources);
632 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
634 return resource || { username: "" };
637 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
640 {formatPermissionLevel(link.name as PermissionLevel)}
643 data-cy="edit-permission-button"
644 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
655 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
656 const link = getResource<LinkResource>(props.uuid)(state.resources);
657 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
660 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
661 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
663 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
665 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
666 const link = getResource<LinkResource>(props.uuid)(state.resources);
667 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
670 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
671 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
673 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
675 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
676 const headResource = getResource<Resource>(link.headUuid)(state.resources);
677 if (headResource && headResource.kind === ResourceKind.GROUP) {
678 return (headResource as GroupResource).canManage;
686 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
690 <Tooltip title="Run process">
691 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))} size="large">
700 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
701 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
703 uuid: resource ? resource.uuid : "",
705 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
707 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
708 if (ownerUuid === getPublicUuid(uuidPrefix)) {
709 return renderStatus(WorkflowStatus.PUBLIC);
711 return renderStatus(WorkflowStatus.PRIVATE);
715 const renderStatus = (status: string) => (
718 style={{ width: "60px" }}
724 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
725 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
726 const uuidPrefix = getUuidPrefix(state);
728 ownerUuid: resource ? resource.ownerUuid : "",
731 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
733 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
734 const process = getProcess(props.uuid)(state.resources);
735 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
736 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
738 enum ColumnSelection {
739 OUTPUT_UUID = "outputUuid",
740 LOG_UUID = "logUuid",
743 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
744 const selectedColumnUuid = item[column];
752 {selectedColumnUuid ? (
755 style={{ width: "auto", cursor: "pointer" }}
757 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
765 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
770 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
771 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
773 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
775 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
776 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
778 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
780 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
781 const process = getProcess(props.uuid)(state.resources);
782 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
783 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
785 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
786 const process = getProcess(props.uuid)(state.resources);
787 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
788 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
790 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
791 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
792 return { date: resource ? resource.createdAt : "" };
793 })((props: { date: string }) => renderDate(props.date));
795 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
796 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
797 return { date: resource ? resource.modifiedAt : "" };
798 })((props: { date: string }) => renderDate(props.date));
800 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
801 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
802 return { date: resource ? resource.trashAt : "" };
803 })((props: { date: string }) => renderDate(props.date));
805 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
806 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
807 return { date: resource ? resource.deleteAt : "" };
808 })((props: { date: string }) => renderDate(props.date));
810 export const renderFileSize = (fileSize?: number) => (
813 style={{ minWidth: "45px" }}
815 {formatFileSize(fileSize)}
819 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
820 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
822 if (resource && resource.kind !== ResourceKind.COLLECTION) {
823 return { fileSize: "" };
826 return { fileSize: resource ? resource.fileSizeTotal : 0 };
827 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
829 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
831 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
832 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
833 return { owner: resource ? resource.ownerUuid : "" };
834 })((props: { owner: string }) => renderOwner(props.owner));
836 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
837 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
838 const ownerNameState = state.ownerName;
839 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
840 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
841 })((props: { owner: string }) => renderOwner(props.owner));
843 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
844 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
845 return { uuid: resource ? resource.uuid : "" };
846 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
848 const renderVersion = (version: number) => {
849 return <Typography>{version ?? "-"}</Typography>;
852 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
853 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
854 return { version: resource ? resource.version : "" };
855 })((props: { version: number }) => renderVersion(props.version));
857 const renderPortableDataHash = (portableDataHash: string | null) => (
859 {portableDataHash ? (
862 <CopyToClipboardSnackbar value={portableDataHash} />
870 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
871 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
872 return { portableDataHash: resource ? resource.portableDataHash : "" };
873 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
875 const renderFileCount = (fileCount: number) => {
876 return <Typography>{fileCount ?? "-"}</Typography>;
879 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
880 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
881 return { fileCount: resource ? resource.fileCount : "" };
882 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
884 const userFromID = connect((state: RootState, props: { uuid: string }) => {
885 let userFullname = "";
886 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
889 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
892 return { uuid: props.uuid, userFullname };
895 const ownerFromResourceId = compose(
896 connect((state: RootState, props: { uuid: string }) => {
897 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
898 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
903 const _resourceWithName = withStyles(
906 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
907 const { uuid, userFullname, dispatch, theme } = props;
908 if (userFullname === "") {
909 dispatch<any>(loadResource(uuid, false));
912 style={{ color: theme.palette.primary.main }}
922 style={{ color: theme.palette.primary.main }}
925 {userFullname} ({uuid})
930 const _resourceWithNameLink = withStyles(
933 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
934 const { uuid, userFullname, dispatch, theme } = props;
936 dispatch<any>(loadResource(uuid, false));
941 style={{ color: theme.palette.primary.main, cursor: 'pointer' }}
944 onClick={() => dispatch<any>(navigateTo(uuid))}
946 {userFullname ? userFullname : uuid}
952 export const ResourceOwnerWithNameLink = ownerFromResourceId(_resourceWithNameLink);
954 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
956 export const ResourceWithName = userFromID(_resourceWithName);
958 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
959 const { uuid, userFullname, dispatch } = props;
961 if (userFullname === "") {
962 dispatch<any>(loadResource(uuid, false));
964 return <span>{userFullname ? userFullname : uuid}</span>;
967 export const ResponsiblePerson = compose(
968 connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
969 let responsiblePersonName: string = "";
970 let responsiblePersonUUID: string = "";
971 let responsiblePersonProperty: string = "";
973 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
975 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
977 while (!responsiblePersonProperty && keys[index]) {
978 const key = keys[index];
979 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
980 responsiblePersonProperty = key;
986 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
988 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
989 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
990 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
993 if (resource && resource.kind === ResourceKind.USER) {
994 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
997 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
999 withStyles({}, { withTheme: true })
1000 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
1001 const { uuid, responsiblePersonName, parentRef, theme } = props;
1003 if (!uuid && parentRef) {
1004 parentRef.style.display = "none";
1006 } else if (parentRef) {
1007 parentRef.style.display = "block";
1010 if (!responsiblePersonName) {
1013 style={{ color: theme.palette.primary.main }}
1024 style={{ color: theme.palette.primary.main }}
1028 {responsiblePersonName} ({uuid})
1033 const renderType = (type: string, subtype: string) => <Typography noWrap>{resourceLabel(type, subtype)}</Typography>;
1035 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
1036 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1038 type: resource ? resource.kind : "",
1040 ? resource.kind === ResourceKind.GROUP
1041 ? resource.groupClass
1042 : resource.kind === ResourceKind.PROCESS
1043 ? resource.requestingContainerUuid
1044 ? ProcessTypeFilter.CHILD_PROCESS
1045 : ProcessTypeFilter.MAIN_PROCESS
1049 })((props: { type: string; subtype: string }) => renderType(props.type, props.subtype));
1051 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1052 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1053 })((props: { resource: GroupContentsResource }) =>
1054 props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1055 <CollectionStatus uuid={props.resource.uuid} />
1057 <ProcessStatus uuid={props.resource.uuid} />
1061 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1062 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1063 })((props: { collection: CollectionResource }) =>
1064 props.collection.uuid !== props.collection.currentVersionUuid ? (
1065 <Typography>version {props.collection.version}</Typography>
1067 <Typography>head version</Typography>
1071 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1073 collection: getResource<CollectionResource>(props.uuid)(state.resources),
1075 className: props.className,
1077 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1078 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1081 export const ProcessStatus = compose(
1082 connect((state: RootState, props: { uuid: string }) => {
1083 return { process: getProcess(props.uuid)(state.resources) };
1085 withStyles({}, { withTheme: true })
1086 )((props: { process?: Process; theme: ArvadosTheme }) =>
1089 data-cy="process-status-chip"
1090 label={getProcessStatus(props.process)}
1092 height: props.theme.spacing(3),
1093 width: props.theme.spacing(12),
1094 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1095 fontSize: "0.875rem",
1096 borderRadius: props.theme.spacing(0.625),
1100 <Typography>-</Typography>
1104 export const ProcessStartDate = connect((state: RootState, props: { uuid: string }) => {
1105 const process = getProcess(props.uuid)(state.resources);
1106 return { date: process && process.container ? process.container.startedAt : "" };
1107 })((props: { date: string }) => renderDate(props.date));
1109 export const renderRunTime = (time: number) => (
1112 style={{ minWidth: "45px" }}
1114 {formatTime(time, true)}
1118 interface ContainerRunTimeProps {
1122 interface ContainerRunTimeState {
1126 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1127 return { process: getProcess(props.uuid)(state.resources) };
1129 class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1132 constructor(props: ContainerRunTimeProps) {
1134 this.state = { runtime: this.getRuntime() };
1138 return this.props.process ? getProcessRuntime(this.props.process) : 0;
1142 this.setState({ runtime: this.getRuntime() });
1145 componentDidMount() {
1146 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1149 componentWillUnmount() {
1150 clearInterval(this.timer);
1154 return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;
1159 export const GroupMembersCount = connect(
1160 (state: RootState, props: { uuid: string }) => {
1161 const group = getResource<GroupResource>(props.uuid)(state.resources);
1164 value: group?.memberCount,
1168 )(withTheme((props: {value: number | null | undefined, theme:ArvadosTheme}) => {
1169 if (props.value === undefined) {
1171 return <Typography component={"div"}>
1174 } else if (props.value === null) {
1177 <Tooltip title="Failed to load member count">
1178 <ErrorIcon style={{color: props.theme.customs.colors.greyL}}/>
1182 return <Typography children={props.value} />;