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";
62 export const toggleIsAdmin = (uuid: string) =>
63 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
64 const { resources } = getState();
65 const data = getResource<UserResource>(uuid)(resources);
66 const isAdmin = data!.isAdmin;
67 const newActivity = await services.userService.update(uuid, { isAdmin: !isAdmin });
68 dispatch<any>(loadUsersPanel());
72 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
73 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
81 <Grid item>{renderIcon(item)}</Grid>
85 style={{ width: "auto", cursor: "pointer" }}
88 dispatch<any>(navFunc(item.uuid))
91 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
96 <Typography variant="caption">
97 <FavoriteStar resourceUuid={item.uuid} />
98 <PublicFavoriteStar resourceUuid={item.uuid} />
99 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
106 export const FrozenProject = (props: { item: ProjectResource }) => {
107 const [fullUsername, setFullusername] = React.useState<any>(null);
108 const getFullName = React.useCallback(() => {
109 if (props.item.frozenByUuid) {
110 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
112 }, [props.item, setFullusername]);
114 if (props.item.frozenByUuid) {
119 title={<span>Project was frozen by {fullUsername}</span>}
121 <FreezeIcon style={{ fontSize: "inherit" }} />
129 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
130 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
132 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
134 const renderIcon = (item: GroupContentsResource) => {
136 case ResourceKind.PROJECT:
137 if (item.groupClass === GroupClass.FILTER) {
138 return <FilterGroupIcon />;
140 return <ProjectIcon />;
141 case ResourceKind.COLLECTION:
142 if (item.uuid === item.currentVersionUuid) {
143 return <CollectionIcon />;
145 return <CollectionOldVersionIcon />;
146 case ResourceKind.PROCESS:
147 return <ProcessIcon />;
148 case ResourceKind.WORKFLOW:
149 return <WorkflowIcon />;
151 return <DefaultIcon />;
155 const renderDate = (date?: string) => {
159 style={{ minWidth: "100px" }}
166 const renderWorkflowName = (item: WorkflowResource) => (
173 <Grid item>{renderIcon(item)}</Grid>
177 style={{ width: "100px" }}
185 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
186 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
188 })(renderWorkflowName);
190 const getPublicUuid = (uuidPrefix: string) => {
191 return `${uuidPrefix}-tpzed-anonymouspublic`;
194 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
195 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
198 {!isPublic && uuid && (
199 <Tooltip title="Share">
200 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))} size="large">
209 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
210 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
211 const uuidPrefix = getUuidPrefix(state);
213 uuid: resource ? resource.uuid : "",
214 ownerUuid: resource ? resource.ownerUuid : "",
217 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
218 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
222 const renderFirstName = (item: { firstName: string }) => {
223 return <Typography noWrap>{item.firstName}</Typography>;
226 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
227 const resource = getResource<UserResource>(props.uuid)(state.resources);
228 return resource || { firstName: "" };
231 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
233 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
234 const resource = getResource<UserResource>(props.uuid)(state.resources);
235 return resource || { lastName: "" };
238 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
239 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
244 style={{ cursor: "pointer" }}
245 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
250 <Typography noWrap>{displayName}</Typography>
254 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
255 const resource = getResource<UserResource>(props.uuid)(state.resources);
256 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
257 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
258 renderFullName(props.dispatch, props.item, props.link)
261 const renderUuid = (item: { uuid: string }) => (
267 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
271 const renderUuidCopyIcon = (item: { uuid: string }) => (
276 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
280 export const ResourceUuid = connect(
281 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
284 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
286 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
287 const resource = getResource<UserResource>(props.uuid)(state.resources);
288 return resource || { email: "" };
291 enum UserAccountStatus {
293 INACTIVE = "Inactive",
298 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
304 data-cy="account-status"
308 switch (props.status) {
309 case UserAccountStatus.ACTIVE:
310 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
311 case UserAccountStatus.SETUP:
312 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
313 case UserAccountStatus.INACTIVE:
314 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
321 <Typography noWrap>{props.status}</Typography>
326 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
327 const user = getResource<UserResource>(props.uuid)(state.resources);
328 // Get membership links for all users group
329 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
330 const permissions = filterResources(
331 (resource: LinkResource) =>
332 resource.kind === ResourceKind.LINK &&
333 resource.linkClass === LinkClass.PERMISSION &&
334 resource.headUuid === allUsersGroupUuid &&
335 resource.tailUuid === props.uuid
340 ? { status: UserAccountStatus.ACTIVE }
341 : permissions.length > 0
342 ? { status: UserAccountStatus.SETUP }
343 : { status: UserAccountStatus.INACTIVE };
345 return { status: UserAccountStatus.UNKNOWN };
349 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
350 const link = getResource<LinkResource>(props.uuid)(state.resources);
351 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
352 })(renderAccountStatus);
354 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
356 const renderIsHidden = (props: {
357 memberLinkUuid: string;
358 permissionLinkUuid: string;
361 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
363 if (props.memberLinkUuid) {
366 data-cy="user-visible-checkbox"
368 checked={props.visible}
369 disabled={!props.canManage}
372 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
377 return <Typography />;
381 export const ResourceLinkTailIsVisible = connect(
382 (state: RootState, props: { uuid: string }) => {
383 const link = getResource<LinkResource>(props.uuid)(state.resources);
384 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
385 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
386 const permissions = filterResources((resource: LinkResource) => {
388 resource.linkClass === LinkClass.PERMISSION &&
389 resource.headUuid === link?.tailUuid &&
390 resource.tailUuid === group?.uuid &&
391 resource.name === PermissionLevel.CAN_READ
395 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
396 const isVisible = link && group && permissions.length > 0;
397 // Consider whether the current user canManage this resurce in addition when it's possible
398 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
400 return member?.kind === ResourceKind.USER
401 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
402 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
404 { setMemberIsHidden }
407 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
410 checked={props.isAdmin}
413 props.toggleIsAdmin(props.uuid);
418 export const ResourceIsAdmin = connect(
419 (state: RootState, props: { uuid: string }) => {
420 const resource = getResource<UserResource>(props.uuid)(state.resources);
421 return resource || { isAdmin: false };
426 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
428 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
429 const resource = getResource<UserResource>(props.uuid)(state.resources);
430 return resource || { username: "", uuid: props.uuid };
433 // Virtual machine resource
435 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
437 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
438 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
439 return resource || { hostname: "" };
442 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
444 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
445 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
446 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
448 return { user: user?.username || permission?.tailUuid || "" };
449 })(renderVirtualMachineLogin);
452 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
454 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
456 export const CommonUuid = withResourceData("uuid", renderCommonData);
458 // Api Client Authorizations
459 export const TokenApiClientId = withResourceData("apiClientId", renderCommonData);
461 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
463 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
465 export const TokenDefaultOwnerUuid = withResourceData("defaultOwnerUuid", renderCommonData);
467 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
469 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
471 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
473 export const TokenScopes = withResourceData("scopes", renderCommonData);
475 export const TokenUserId = withResourceData("userId", renderCommonData);
477 const clusterColors = [
485 export const ResourceCluster = (props: { uuid: string }) => {
486 const CLUSTER_ID_LENGTH = 5;
487 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf("-") : 5;
488 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : "";
490 pos >= CLUSTER_ID_LENGTH
491 ? ((props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1) + props.uuid.charCodeAt(2)) * props.uuid.charCodeAt(3) +
492 props.uuid.charCodeAt(4)) %
498 backgroundColor: clusterColors[ci][0],
499 color: clusterColors[ci][1],
510 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
512 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
513 const resource = getResource<LinkResource>(props.uuid)(state.resources);
514 return resource || { name: "" };
517 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
519 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
520 const resource = getResource<LinkResource>(props.uuid)(state.resources);
521 return resource || { linkClass: "" };
524 const getResourceDisplayName = (resource: Resource): string => {
525 if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
526 // We can be sure the resource is UserResource
527 return getUserDisplayName(resource as UserResource);
529 return (resource as GroupContentsResource).name;
533 const renderResourceLink = (dispatch: Dispatch, item: Resource ) => {
534 var displayName = getResourceDisplayName(item);
540 style={{ cursor: "pointer" }}
542 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
543 ? dispatch<any>(navigateToGroupDetails(item.uuid))
544 : item.kind === ResourceKind.USER
545 ? dispatch<any>(navigateToUserProfile(item.uuid))
546 : dispatch<any>(navigateTo(item.uuid));
549 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
550 {displayName || item.uuid}
555 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
556 const resource = getResource<LinkResource>(props.uuid)(state.resources);
557 const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
560 item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
562 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
564 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
565 const resource = getResource<LinkResource>(props.uuid)(state.resources);
566 const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
569 item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
571 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
573 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
574 const resource = getResource<LinkResource>(props.uuid)(state.resources);
575 return resource || { uuid: "" };
578 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
579 const link = getResource<LinkResource>(props.uuid)(state.resources);
580 const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
582 return headResource || { uuid: "" };
585 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
586 const link = getResource<LinkResource>(props.uuid)(state.resources);
587 const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
589 return tailResource || { uuid: "" };
592 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
597 data-cy="resource-delete-button"
598 onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
605 <IconButton disabled data-cy="resource-delete-button" size="large">
611 return <Typography noWrap></Typography>;
615 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
616 const link = getResource<LinkResource>(props.uuid)(state.resources);
617 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
620 item: link || { uuid: "", kind: ResourceKind.NONE },
621 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
623 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
625 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
626 const link = getResource<LinkResource>(props.uuid)(state.resources);
627 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
629 return resource || { email: "" };
632 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
633 const link = getResource<LinkResource>(props.uuid)(state.resources);
634 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
636 return resource || { username: "" };
639 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
642 {formatPermissionLevel(link.name as PermissionLevel)}
645 data-cy="edit-permission-button"
646 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
657 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
658 const link = getResource<LinkResource>(props.uuid)(state.resources);
659 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
662 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
663 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
665 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
667 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
668 const link = getResource<LinkResource>(props.uuid)(state.resources);
669 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
672 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
673 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
675 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
677 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
678 const headResource = getResource<Resource>(link.headUuid)(state.resources);
679 if (headResource && headResource.kind === ResourceKind.GROUP) {
680 return (headResource as GroupResource).canManage;
688 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
692 <Tooltip title="Run process">
693 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))} size="large">
702 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
703 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
705 uuid: resource ? resource.uuid : "",
707 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
709 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
710 if (ownerUuid === getPublicUuid(uuidPrefix)) {
711 return renderStatus(WorkflowStatus.PUBLIC);
713 return renderStatus(WorkflowStatus.PRIVATE);
717 const renderStatus = (status: string) => (
720 style={{ width: "60px" }}
726 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
727 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
728 const uuidPrefix = getUuidPrefix(state);
730 ownerUuid: resource ? resource.ownerUuid : "",
733 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
735 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
736 const process = getProcess(props.uuid)(state.resources);
737 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
738 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
740 enum ColumnSelection {
741 OUTPUT_UUID = "outputUuid",
742 LOG_UUID = "logUuid",
745 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
746 const selectedColumnUuid = item[column];
754 {selectedColumnUuid ? (
757 style={{ width: "auto", cursor: "pointer" }}
759 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
767 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
772 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
773 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
775 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
777 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
778 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
780 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
782 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
783 const process = getProcess(props.uuid)(state.resources);
784 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
785 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
787 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
788 const process = getProcess(props.uuid)(state.resources);
789 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
790 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
792 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
793 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
794 return { date: resource ? resource.createdAt : "" };
795 })((props: { date: string }) => renderDate(props.date));
797 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
798 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
799 return { date: resource ? resource.modifiedAt : "" };
800 })((props: { date: string }) => renderDate(props.date));
802 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
803 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
804 return { date: resource ? resource.trashAt : "" };
805 })((props: { date: string }) => renderDate(props.date));
807 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
808 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
809 return { date: resource ? resource.deleteAt : "" };
810 })((props: { date: string }) => renderDate(props.date));
812 export const renderFileSize = (fileSize?: number) => (
815 style={{ minWidth: "45px" }}
817 {formatFileSize(fileSize)}
821 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
822 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
824 if (resource && resource.kind !== ResourceKind.COLLECTION) {
825 return { fileSize: "" };
828 return { fileSize: resource ? resource.fileSizeTotal : 0 };
829 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
831 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
833 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
834 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
835 return { owner: resource ? resource.ownerUuid : "" };
836 })((props: { owner: string }) => renderOwner(props.owner));
838 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
839 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
840 const ownerNameState = state.ownerName;
841 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
842 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
843 })((props: { owner: string }) => renderOwner(props.owner));
845 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
846 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
847 return { uuid: resource ? resource.uuid : "" };
848 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
850 const renderVersion = (version: number) => {
851 return <Typography>{version ?? "-"}</Typography>;
854 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
855 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
856 return { version: resource ? resource.version : "" };
857 })((props: { version: number }) => renderVersion(props.version));
859 const renderPortableDataHash = (portableDataHash: string | null) => (
861 {portableDataHash ? (
864 <CopyToClipboardSnackbar value={portableDataHash} />
872 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
873 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
874 return { portableDataHash: resource ? resource.portableDataHash : "" };
875 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
877 const renderFileCount = (fileCount: number) => {
878 return <Typography>{fileCount ?? "-"}</Typography>;
881 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
882 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
883 return { fileCount: resource ? resource.fileCount : "" };
884 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
886 const userFromID = connect((state: RootState, props: { uuid: string }) => {
887 let userFullname = "";
888 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
891 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
894 return { uuid: props.uuid, userFullname };
897 const ownerFromResourceId = compose(
898 connect((state: RootState, props: { uuid: string }) => {
899 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
900 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
905 const _resourceWithName = withStyles(
908 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
909 const { uuid, userFullname, dispatch, theme } = props;
910 if (userFullname === "") {
911 dispatch<any>(loadResource(uuid, false));
914 style={{ color: theme.palette.primary.main }}
924 style={{ color: theme.palette.primary.main }}
927 {userFullname} ({uuid})
932 const _resourceWithNameLink = withStyles(
935 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
936 const { uuid, userFullname, dispatch, theme } = props;
938 dispatch<any>(loadResource(uuid, false));
943 style={{ color: theme.palette.primary.main, cursor: 'pointer' }}
946 onClick={() => dispatch<any>(navigateTo(uuid))}
948 {userFullname ? userFullname : uuid}
954 export const ResourceOwnerWithNameLink = ownerFromResourceId(_resourceWithNameLink);
956 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
958 export const ResourceWithName = userFromID(_resourceWithName);
960 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
961 const { uuid, userFullname, dispatch } = props;
963 if (userFullname === "") {
964 dispatch<any>(loadResource(uuid, false));
966 return <span>{userFullname ? userFullname : uuid}</span>;
969 export const ResponsiblePerson = compose(
970 connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
971 let responsiblePersonName: string = "";
972 let responsiblePersonUUID: string = "";
973 let responsiblePersonProperty: string = "";
975 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
977 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
979 while (!responsiblePersonProperty && keys[index]) {
980 const key = keys[index];
981 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
982 responsiblePersonProperty = key;
988 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
990 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
991 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
992 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
995 if (resource && resource.kind === ResourceKind.USER) {
996 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
999 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
1001 withStyles({}, { withTheme: true })
1002 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
1003 const { uuid, responsiblePersonName, parentRef, theme } = props;
1005 if (!uuid && parentRef) {
1006 parentRef.style.display = "none";
1008 } else if (parentRef) {
1009 parentRef.style.display = "block";
1012 if (!responsiblePersonName) {
1015 style={{ color: theme.palette.primary.main }}
1026 style={{ color: theme.palette.primary.main }}
1030 {responsiblePersonName} ({uuid})
1035 const renderType = (type: string, subtype: string) => <Typography noWrap>{resourceLabel(type, subtype)}</Typography>;
1037 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
1038 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1039 return { type: resource ? resource.kind : "", subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : "" };
1040 })((props: { type: string; subtype: string }) => renderType(props.type, props.subtype));
1042 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1043 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1044 })((props: { resource: GroupContentsResource }) =>
1045 props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1046 <CollectionStatus uuid={props.resource.uuid} />
1048 <ProcessStatus uuid={props.resource.uuid} />
1052 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1053 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1054 })((props: { collection: CollectionResource }) =>
1055 props.collection.uuid !== props.collection.currentVersionUuid ? (
1056 <Typography>version {props.collection.version}</Typography>
1058 <Typography>head version</Typography>
1062 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1064 collection: getResource<CollectionResource>(props.uuid)(state.resources),
1066 className: props.className,
1068 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1069 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1072 export const ProcessStatus = compose(
1073 connect((state: RootState, props: { uuid: string }) => {
1074 return { process: getProcess(props.uuid)(state.resources) };
1076 withStyles({}, { withTheme: true })
1077 )((props: { process?: Process; theme: ArvadosTheme }) =>
1080 data-cy="process-status-chip"
1081 label={getProcessStatus(props.process)}
1083 height: props.theme.spacing(3),
1084 width: props.theme.spacing(12),
1085 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1086 fontSize: "0.875rem",
1087 borderRadius: props.theme.spacing(0.625),
1091 <Typography>-</Typography>
1095 export const ProcessStartDate = connect((state: RootState, props: { uuid: string }) => {
1096 const process = getProcess(props.uuid)(state.resources);
1097 return { date: process && process.container ? process.container.startedAt : "" };
1098 })((props: { date: string }) => renderDate(props.date));
1100 export const renderRunTime = (time: number) => (
1103 style={{ minWidth: "45px" }}
1105 {formatTime(time, true)}
1109 interface ContainerRunTimeProps {
1113 interface ContainerRunTimeState {
1117 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1118 return { process: getProcess(props.uuid)(state.resources) };
1120 class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1123 constructor(props: ContainerRunTimeProps) {
1125 this.state = { runtime: this.getRuntime() };
1129 return this.props.process ? getProcessRuntime(this.props.process) : 0;
1133 this.setState({ runtime: this.getRuntime() });
1136 componentDidMount() {
1137 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1140 componentWillUnmount() {
1141 clearInterval(this.timer);
1145 return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;
1150 export const GroupMembersCount = connect(
1151 (state: RootState, props: { uuid: string }) => {
1152 const group = getResource<GroupResource>(props.uuid)(state.resources);
1155 value: group?.memberCount,
1159 )(withTheme((props: {value: number | null | undefined, theme:ArvadosTheme}) => {
1160 if (props.value === undefined) {
1162 return <Typography component={"div"}>
1165 } else if (props.value === null) {
1168 <Tooltip title="Failed to load member count">
1169 <ErrorIcon style={{color: props.theme.customs.colors.greyL}}/>
1173 return <Typography children={props.value} />;