1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Grid, Typography, withStyles, Tooltip, IconButton, Checkbox, Chip, withTheme } from "@material-ui/core";
7 import { FavoriteStar, PublicFavoriteStar } from "../favorite-star/favorite-star";
8 import { Resource, ResourceKind, TrashableResource } from "models/resource";
17 CollectionOldVersionIcon,
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";
60 export const toggleIsAdmin = (uuid: string) =>
61 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
62 const { resources } = getState();
63 const data = getResource<UserResource>(uuid)(resources);
64 const isAdmin = data!.isAdmin;
65 const newActivity = await services.userService.update(uuid, { isAdmin: !isAdmin });
66 dispatch<any>(loadUsersPanel());
70 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
71 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
79 <Grid item>{renderIcon(item)}</Grid>
83 style={{ width: "auto", cursor: "pointer" }}
86 dispatch<any>(navFunc(item.uuid))
89 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
94 <Typography variant="caption">
95 <FavoriteStar resourceUuid={item.uuid} />
96 <PublicFavoriteStar resourceUuid={item.uuid} />
97 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
104 export const FrozenProject = (props: { item: ProjectResource }) => {
105 const [fullUsername, setFullusername] = React.useState<any>(null);
106 const getFullName = React.useCallback(() => {
107 if (props.item.frozenByUuid) {
108 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
110 }, [props.item, setFullusername]);
112 if (props.item.frozenByUuid) {
117 title={<span>Project was frozen by {fullUsername}</span>}
119 <FreezeIcon style={{ fontSize: "inherit" }} />
127 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
128 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
130 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
132 const renderIcon = (item: GroupContentsResource) => {
134 case ResourceKind.PROJECT:
135 if (item.groupClass === GroupClass.FILTER) {
136 return <FilterGroupIcon />;
138 return <ProjectIcon />;
139 case ResourceKind.COLLECTION:
140 if (item.uuid === item.currentVersionUuid) {
141 return <CollectionIcon />;
143 return <CollectionOldVersionIcon />;
144 case ResourceKind.PROCESS:
145 return <ProcessIcon />;
146 case ResourceKind.WORKFLOW:
147 return <WorkflowIcon />;
149 return <DefaultIcon />;
153 const renderDate = (date?: string) => {
157 style={{ minWidth: "100px" }}
164 const renderWorkflowName = (item: WorkflowResource) => (
171 <Grid item>{renderIcon(item)}</Grid>
175 style={{ width: "100px" }}
183 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
184 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
186 })(renderWorkflowName);
188 const getPublicUuid = (uuidPrefix: string) => {
189 return `${uuidPrefix}-tpzed-anonymouspublic`;
192 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
193 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
196 {!isPublic && uuid && (
197 <Tooltip title="Share">
198 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
207 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
208 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
209 const uuidPrefix = getUuidPrefix(state);
211 uuid: resource ? resource.uuid : "",
212 ownerUuid: resource ? resource.ownerUuid : "",
215 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
216 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
220 const renderFirstName = (item: { firstName: string }) => {
221 return <Typography noWrap>{item.firstName}</Typography>;
224 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
225 const resource = getResource<UserResource>(props.uuid)(state.resources);
226 return resource || { firstName: "" };
229 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
231 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
232 const resource = getResource<UserResource>(props.uuid)(state.resources);
233 return resource || { lastName: "" };
236 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
237 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
242 style={{ cursor: "pointer" }}
243 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
248 <Typography noWrap>{displayName}</Typography>
252 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
253 const resource = getResource<UserResource>(props.uuid)(state.resources);
254 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
255 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
256 renderFullName(props.dispatch, props.item, props.link)
259 const renderUuid = (item: { uuid: string }) => (
265 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
269 const renderUuidCopyIcon = (item: { uuid: string }) => (
274 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
278 export const ResourceUuid = connect(
279 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
282 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
284 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
285 const resource = getResource<UserResource>(props.uuid)(state.resources);
286 return resource || { email: "" };
289 enum UserAccountStatus {
291 INACTIVE = "Inactive",
296 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
302 data-cy="account-status"
306 switch (props.status) {
307 case UserAccountStatus.ACTIVE:
308 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
309 case UserAccountStatus.SETUP:
310 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
311 case UserAccountStatus.INACTIVE:
312 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
319 <Typography noWrap>{props.status}</Typography>
324 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
325 const user = getResource<UserResource>(props.uuid)(state.resources);
326 // Get membership links for all users group
327 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
328 const permissions = filterResources(
329 (resource: LinkResource) =>
330 resource.kind === ResourceKind.LINK &&
331 resource.linkClass === LinkClass.PERMISSION &&
332 resource.headUuid === allUsersGroupUuid &&
333 resource.tailUuid === props.uuid
338 ? { status: UserAccountStatus.ACTIVE }
339 : permissions.length > 0
340 ? { status: UserAccountStatus.SETUP }
341 : { status: UserAccountStatus.INACTIVE };
343 return { status: UserAccountStatus.UNKNOWN };
347 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
348 const link = getResource<LinkResource>(props.uuid)(state.resources);
349 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
350 })(renderAccountStatus);
352 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
354 const renderIsHidden = (props: {
355 memberLinkUuid: string;
356 permissionLinkUuid: string;
359 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
361 if (props.memberLinkUuid) {
364 data-cy="user-visible-checkbox"
366 checked={props.visible}
367 disabled={!props.canManage}
370 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
375 return <Typography />;
379 export const ResourceLinkTailIsVisible = connect(
380 (state: RootState, props: { uuid: string }) => {
381 const link = getResource<LinkResource>(props.uuid)(state.resources);
382 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
383 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
384 const permissions = filterResources((resource: LinkResource) => {
386 resource.linkClass === LinkClass.PERMISSION &&
387 resource.headUuid === link?.tailUuid &&
388 resource.tailUuid === group?.uuid &&
389 resource.name === PermissionLevel.CAN_READ
393 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
394 const isVisible = link && group && permissions.length > 0;
395 // Consider whether the current user canManage this resurce in addition when it's possible
396 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
398 return member?.kind === ResourceKind.USER
399 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
400 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
402 { setMemberIsHidden }
405 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
408 checked={props.isAdmin}
411 props.toggleIsAdmin(props.uuid);
416 export const ResourceIsAdmin = connect(
417 (state: RootState, props: { uuid: string }) => {
418 const resource = getResource<UserResource>(props.uuid)(state.resources);
419 return resource || { isAdmin: false };
424 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
426 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
427 const resource = getResource<UserResource>(props.uuid)(state.resources);
428 return resource || { username: "", uuid: props.uuid };
431 // Virtual machine resource
433 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
435 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
436 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
437 return resource || { hostname: "" };
440 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
442 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
443 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
444 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
446 return { user: user?.username || permission?.tailUuid || "" };
447 })(renderVirtualMachineLogin);
450 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
452 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
454 export const CommonUuid = withResourceData("uuid", renderCommonData);
456 // Api Client Authorizations
457 export const TokenApiClientId = withResourceData("apiClientId", renderCommonData);
459 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
461 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
463 export const TokenDefaultOwnerUuid = withResourceData("defaultOwnerUuid", renderCommonData);
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))}
605 data-cy="resource-delete-button"
612 return <Typography noWrap></Typography>;
616 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
617 const link = getResource<LinkResource>(props.uuid)(state.resources);
618 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
621 item: link || { uuid: "", kind: ResourceKind.NONE },
622 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
624 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
626 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
627 const link = getResource<LinkResource>(props.uuid)(state.resources);
628 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
630 return resource || { email: "" };
633 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
634 const link = getResource<LinkResource>(props.uuid)(state.resources);
635 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
637 return resource || { username: "" };
640 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
643 {formatPermissionLevel(link.name as PermissionLevel)}
646 data-cy="edit-permission-button"
647 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
658 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
659 const link = getResource<LinkResource>(props.uuid)(state.resources);
660 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
663 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
664 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
666 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
668 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
669 const link = getResource<LinkResource>(props.uuid)(state.resources);
670 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
673 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
674 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
676 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
678 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
679 const headResource = getResource<Resource>(link.headUuid)(state.resources);
680 if (headResource && headResource.kind === ResourceKind.GROUP) {
681 return (headResource as GroupResource).canManage;
689 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
693 <Tooltip title="Run process">
694 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
703 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
704 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
706 uuid: resource ? resource.uuid : "",
708 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
710 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
711 if (ownerUuid === getPublicUuid(uuidPrefix)) {
712 return renderStatus(WorkflowStatus.PUBLIC);
714 return renderStatus(WorkflowStatus.PRIVATE);
718 const renderStatus = (status: string) => (
721 style={{ width: "60px" }}
727 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
728 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
729 const uuidPrefix = getUuidPrefix(state);
731 ownerUuid: resource ? resource.ownerUuid : "",
734 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
736 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
737 const process = getProcess(props.uuid)(state.resources);
738 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
739 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
741 enum ColumnSelection {
742 OUTPUT_UUID = "outputUuid",
743 LOG_UUID = "logUuid",
746 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
747 const selectedColumnUuid = item[column];
755 {selectedColumnUuid ? (
758 style={{ width: "auto", cursor: "pointer" }}
760 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
768 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
773 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
774 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
776 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
778 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
779 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
781 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
783 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
784 const process = getProcess(props.uuid)(state.resources);
785 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
786 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
788 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
789 const process = getProcess(props.uuid)(state.resources);
790 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
791 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
793 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
794 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
795 return { date: resource ? resource.createdAt : "" };
796 })((props: { date: string }) => renderDate(props.date));
798 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
799 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
800 return { date: resource ? resource.modifiedAt : "" };
801 })((props: { date: string }) => renderDate(props.date));
803 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
804 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
805 return { date: resource ? resource.trashAt : "" };
806 })((props: { date: string }) => renderDate(props.date));
808 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
809 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
810 return { date: resource ? resource.deleteAt : "" };
811 })((props: { date: string }) => renderDate(props.date));
813 export const renderFileSize = (fileSize?: number) => (
816 style={{ minWidth: "45px" }}
818 {formatFileSize(fileSize)}
822 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
823 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
825 if (resource && resource.kind !== ResourceKind.COLLECTION) {
826 return { fileSize: "" };
829 return { fileSize: resource ? resource.fileSizeTotal : 0 };
830 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
832 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
834 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
835 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
836 return { owner: resource ? resource.ownerUuid : "" };
837 })((props: { owner: string }) => renderOwner(props.owner));
839 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
840 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
841 const ownerNameState = state.ownerName;
842 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
843 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
844 })((props: { owner: string }) => renderOwner(props.owner));
846 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
847 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
848 return { uuid: resource ? resource.uuid : "" };
849 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
851 const renderVersion = (version: number) => {
852 return <Typography>{version ?? "-"}</Typography>;
855 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
856 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
857 return { version: resource ? resource.version : "" };
858 })((props: { version: number }) => renderVersion(props.version));
860 const renderPortableDataHash = (portableDataHash: string | null) => (
862 {portableDataHash ? (
865 <CopyToClipboardSnackbar value={portableDataHash} />
873 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
874 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
875 return { portableDataHash: resource ? resource.portableDataHash : "" };
876 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
878 const renderFileCount = (fileCount: number) => {
879 return <Typography>{fileCount ?? "-"}</Typography>;
882 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
883 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
884 return { fileCount: resource ? resource.fileCount : "" };
885 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
887 const userFromID = connect((state: RootState, props: { uuid: string }) => {
888 let userFullname = "";
889 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
892 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
895 return { uuid: props.uuid, userFullname };
898 const ownerFromResourceId = compose(
899 connect((state: RootState, props: { uuid: string }) => {
900 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
901 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
906 const _resourceWithName = withStyles(
909 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
910 const { uuid, userFullname, dispatch, theme } = props;
911 if (userFullname === "") {
912 dispatch<any>(loadResource(uuid, false));
915 style={{ color: theme.palette.primary.main }}
925 style={{ color: theme.palette.primary.main }}
928 {userFullname} ({uuid})
933 const _resourceWithNameLink = withStyles(
936 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
937 const { uuid, userFullname, dispatch, theme } = props;
939 dispatch<any>(loadResource(uuid, false));
944 style={{ color: theme.palette.primary.main, cursor: 'pointer' }}
947 onClick={() => dispatch<any>(navigateTo(uuid))}
949 {userFullname ? userFullname : uuid}
955 export const ResourceOwnerWithNameLink = ownerFromResourceId(_resourceWithNameLink);
957 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
959 export const ResourceWithName = userFromID(_resourceWithName);
961 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
962 const { uuid, userFullname, dispatch } = props;
964 if (userFullname === "") {
965 dispatch<any>(loadResource(uuid, false));
967 return <span>{userFullname ? userFullname : uuid}</span>;
970 export const ResponsiblePerson = compose(
971 connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
972 let responsiblePersonName: string = "";
973 let responsiblePersonUUID: string = "";
974 let responsiblePersonProperty: string = "";
976 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
978 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
980 while (!responsiblePersonProperty && keys[index]) {
981 const key = keys[index];
982 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
983 responsiblePersonProperty = key;
989 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
991 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
992 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
993 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
996 if (resource && resource.kind === ResourceKind.USER) {
997 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
1000 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
1002 withStyles({}, { withTheme: true })
1003 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
1004 const { uuid, responsiblePersonName, parentRef, theme } = props;
1006 if (!uuid && parentRef) {
1007 parentRef.style.display = "none";
1009 } else if (parentRef) {
1010 parentRef.style.display = "block";
1013 if (!responsiblePersonName) {
1016 style={{ color: theme.palette.primary.main }}
1027 style={{ color: theme.palette.primary.main }}
1031 {responsiblePersonName} ({uuid})
1036 const renderType = (type: string, subtype: string) => <Typography noWrap>{resourceLabel(type, subtype)}</Typography>;
1038 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
1039 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1040 return { type: resource ? resource.kind : "", subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : "" };
1041 })((props: { type: string; subtype: string }) => renderType(props.type, props.subtype));
1043 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1044 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1045 })((props: { resource: GroupContentsResource }) =>
1046 props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1047 <CollectionStatus uuid={props.resource.uuid} />
1049 <ProcessStatus uuid={props.resource.uuid} />
1053 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1054 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1055 })((props: { collection: CollectionResource }) =>
1056 props.collection.uuid !== props.collection.currentVersionUuid ? (
1057 <Typography>version {props.collection.version}</Typography>
1059 <Typography>head version</Typography>
1063 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1065 collection: getResource<CollectionResource>(props.uuid)(state.resources),
1067 className: props.className,
1069 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1070 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1073 export const ProcessStatus = compose(
1074 connect((state: RootState, props: { uuid: string }) => {
1075 return { process: getProcess(props.uuid)(state.resources) };
1077 withStyles({}, { withTheme: true })
1078 )((props: { process?: Process; theme: ArvadosTheme }) =>
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} />;