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 } from "@material-ui/core";
7 import { FavoriteStar, PublicFavoriteStar } from "../favorite-star/favorite-star";
8 import { Resource, ResourceKind, TrashableResource } from "models/resource";
17 CollectionOldVersionIcon,
24 } from "components/icon/icon";
25 import { formatDate, formatFileSize, formatTime } from "common/formatters";
26 import { resourceLabel } from "common/labels";
27 import { connect, DispatchProp } from "react-redux";
28 import { RootState } from "store/store";
29 import { getResource, filterResources } from "store/resources/resources";
30 import { GroupContentsResource } from "services/groups-service/groups-service";
31 import { getProcess, Process, getProcessStatus, getProcessStatusStyles, getProcessRuntime } from "store/processes/process";
32 import { ArvadosTheme } from "common/custom-theme";
33 import { compose, Dispatch } from "redux";
34 import { WorkflowResource } from "models/workflow";
35 import { ResourceStatus as WorkflowStatus } from "views/workflow-panel/workflow-panel-view";
36 import { getUuidPrefix, openRunProcess } from "store/workflow-panel/workflow-panel-actions";
37 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
38 import { getUserFullname, getUserDisplayName, User, UserResource } from "models/user";
39 import { toggleIsAdmin } from "store/users/users-actions";
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 { setBreadcrumbs } from "store/breadcrumbs/breadcrumbs-actions";
58 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
59 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
67 <Grid item>{renderIcon(item)}</Grid>
71 style={{ width: "auto", cursor: "pointer" }}
72 onClick={() => dispatch<any>(navFunc(item.uuid))}
74 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
79 <Typography variant="caption">
80 <FavoriteStar resourceUuid={item.uuid} />
81 <PublicFavoriteStar resourceUuid={item.uuid} />
82 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
89 const FrozenProject = (props: { item: ProjectResource }) => {
90 const [fullUsername, setFullusername] = React.useState<any>(null);
91 const getFullName = React.useCallback(() => {
92 if (props.item.frozenByUuid) {
93 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
95 }, [props.item, setFullusername]);
97 if (props.item.frozenByUuid) {
102 title={<span>Project was frozen by {fullUsername}</span>}
104 <FreezeIcon style={{ fontSize: "inherit" }} />
112 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
113 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
115 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
117 const renderIcon = (item: GroupContentsResource) => {
119 case ResourceKind.PROJECT:
120 if (item.groupClass === GroupClass.FILTER) {
121 return <FilterGroupIcon />;
123 return <ProjectIcon />;
124 case ResourceKind.COLLECTION:
125 if (item.uuid === item.currentVersionUuid) {
126 return <CollectionIcon />;
128 return <CollectionOldVersionIcon />;
129 case ResourceKind.PROCESS:
130 return <ProcessIcon />;
131 case ResourceKind.WORKFLOW:
132 return <WorkflowIcon />;
134 return <DefaultIcon />;
138 const renderDate = (date?: string) => {
142 style={{ minWidth: "100px" }}
149 const renderWorkflowName = (item: WorkflowResource) => (
156 <Grid item>{renderIcon(item)}</Grid>
160 style={{ width: "100px" }}
168 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
169 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
171 })(renderWorkflowName);
173 const getPublicUuid = (uuidPrefix: string) => {
174 return `${uuidPrefix}-tpzed-anonymouspublic`;
177 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
178 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
181 {!isPublic && uuid && (
182 <Tooltip title="Share">
183 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
192 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
193 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
194 const uuidPrefix = getUuidPrefix(state);
196 uuid: resource ? resource.uuid : "",
197 ownerUuid: resource ? resource.ownerUuid : "",
200 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
201 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
205 const renderFirstName = (item: { firstName: string }) => {
206 return <Typography noWrap>{item.firstName}</Typography>;
209 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
210 const resource = getResource<UserResource>(props.uuid)(state.resources);
211 return resource || { firstName: "" };
214 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
216 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
217 const resource = getResource<UserResource>(props.uuid)(state.resources);
218 return resource || { lastName: "" };
221 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
222 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
227 style={{ cursor: "pointer" }}
228 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
233 <Typography noWrap>{displayName}</Typography>
237 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
238 const resource = getResource<UserResource>(props.uuid)(state.resources);
239 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
240 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
241 renderFullName(props.dispatch, props.item, props.link)
244 const renderUuid = (item: { uuid: string }) => (
250 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
254 const renderUuidCopyIcon = (item: { uuid: string }) => (
259 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
263 export const ResourceUuid = connect(
264 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
267 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
269 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
270 const resource = getResource<UserResource>(props.uuid)(state.resources);
271 return resource || { email: "" };
274 enum UserAccountStatus {
276 INACTIVE = "Inactive",
281 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
287 data-cy="account-status"
291 switch (props.status) {
292 case UserAccountStatus.ACTIVE:
293 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
294 case UserAccountStatus.SETUP:
295 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
296 case UserAccountStatus.INACTIVE:
297 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
304 <Typography noWrap>{props.status}</Typography>
309 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
310 const user = getResource<UserResource>(props.uuid)(state.resources);
311 // Get membership links for all users group
312 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
313 const permissions = filterResources(
314 (resource: LinkResource) =>
315 resource.kind === ResourceKind.LINK &&
316 resource.linkClass === LinkClass.PERMISSION &&
317 resource.headUuid === allUsersGroupUuid &&
318 resource.tailUuid === props.uuid
323 ? { status: UserAccountStatus.ACTIVE }
324 : permissions.length > 0
325 ? { status: UserAccountStatus.SETUP }
326 : { status: UserAccountStatus.INACTIVE };
328 return { status: UserAccountStatus.UNKNOWN };
332 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
333 const link = getResource<LinkResource>(props.uuid)(state.resources);
334 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
335 })(renderAccountStatus);
337 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
339 const renderIsHidden = (props: {
340 memberLinkUuid: string;
341 permissionLinkUuid: string;
344 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
346 if (props.memberLinkUuid) {
349 data-cy="user-visible-checkbox"
351 checked={props.visible}
352 disabled={!props.canManage}
355 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
360 return <Typography />;
364 export const ResourceLinkTailIsVisible = connect(
365 (state: RootState, props: { uuid: string }) => {
366 const link = getResource<LinkResource>(props.uuid)(state.resources);
367 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
368 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
369 const permissions = filterResources((resource: LinkResource) => {
371 resource.linkClass === LinkClass.PERMISSION &&
372 resource.headUuid === link?.tailUuid &&
373 resource.tailUuid === group?.uuid &&
374 resource.name === PermissionLevel.CAN_READ
378 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
379 const isVisible = link && group && permissions.length > 0;
380 // Consider whether the current user canManage this resurce in addition when it's possible
381 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
383 return member?.kind === ResourceKind.USER
384 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
385 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
387 { setMemberIsHidden }
390 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
393 checked={props.isAdmin}
396 props.toggleIsAdmin(props.uuid);
401 export const ResourceIsAdmin = connect(
402 (state: RootState, props: { uuid: string }) => {
403 const resource = getResource<UserResource>(props.uuid)(state.resources);
404 return resource || { isAdmin: false };
409 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
411 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
412 const resource = getResource<UserResource>(props.uuid)(state.resources);
413 return resource || { username: "", uuid: props.uuid };
416 // Virtual machine resource
418 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
420 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
421 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
422 return resource || { hostname: "" };
425 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
427 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
428 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
429 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
431 return { user: user?.username || permission?.tailUuid || "" };
432 })(renderVirtualMachineLogin);
435 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
437 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
439 export const CommonUuid = withResourceData("uuid", renderCommonData);
441 // Api Client Authorizations
442 export const TokenApiClientId = withResourceData("apiClientId", renderCommonData);
444 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
446 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
448 export const TokenDefaultOwnerUuid = withResourceData("defaultOwnerUuid", renderCommonData);
450 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
452 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
454 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
456 export const TokenScopes = withResourceData("scopes", renderCommonData);
458 export const TokenUserId = withResourceData("userId", renderCommonData);
460 const clusterColors = [
468 export const ResourceCluster = (props: { uuid: string }) => {
469 const CLUSTER_ID_LENGTH = 5;
470 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf("-") : 5;
471 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : "";
473 pos >= CLUSTER_ID_LENGTH
474 ? ((props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1) + props.uuid.charCodeAt(2)) * props.uuid.charCodeAt(3) +
475 props.uuid.charCodeAt(4)) %
481 backgroundColor: clusterColors[ci][0],
482 color: clusterColors[ci][1],
493 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
495 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
496 const resource = getResource<LinkResource>(props.uuid)(state.resources);
497 return resource || { name: "" };
500 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
502 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
503 const resource = getResource<LinkResource>(props.uuid)(state.resources);
504 return resource || { linkClass: "" };
507 const getResourceDisplayName = (resource: Resource): string => {
508 if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
509 // We can be sure the resource is UserResource
510 return getUserDisplayName(resource as UserResource);
512 return (resource as GroupContentsResource).name;
516 const renderResourceLink = (dispatch: Dispatch, item: Resource, userUuid: string = '', breadcrumbs: any[] = []) => {
517 var displayName = getResourceDisplayName(item);
523 style={{ cursor: "pointer" }}
525 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
526 ? dispatch<any>(navigateToGroupDetails(item.uuid))
527 : dispatch<any>(navigateTo(item.uuid));
528 //don't add breadcrumb when navigating to 'Home Projects'
529 if (item.uuid !== userUuid) setBreadcrumbs(breadcrumbs, item as any);
532 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
533 {displayName || item.uuid}
538 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
539 const resource = getResource<LinkResource>(props.uuid)(state.resources);
540 const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
541 const userUuid = state.auth.user?.uuid
544 item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
545 breadcrumbs: state.properties.breadcrumbs || [],
548 })((props: { item: Resource, userUuid: string, breadcrumbs: any[] } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item, props.userUuid, props.breadcrumbs));
550 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
551 const resource = getResource<LinkResource>(props.uuid)(state.resources);
552 const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
555 item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
557 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
559 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
560 const resource = getResource<LinkResource>(props.uuid)(state.resources);
561 return resource || { uuid: "" };
564 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
565 const link = getResource<LinkResource>(props.uuid)(state.resources);
566 const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
568 return headResource || { uuid: "" };
571 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
572 const link = getResource<LinkResource>(props.uuid)(state.resources);
573 const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
575 return tailResource || { uuid: "" };
578 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
583 data-cy="resource-delete-button"
584 onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
593 data-cy="resource-delete-button"
600 return <Typography noWrap></Typography>;
604 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
605 const link = getResource<LinkResource>(props.uuid)(state.resources);
606 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
609 item: link || { uuid: "", kind: ResourceKind.NONE },
610 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
612 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
614 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
615 const link = getResource<LinkResource>(props.uuid)(state.resources);
616 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
618 return resource || { email: "" };
621 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
622 const link = getResource<LinkResource>(props.uuid)(state.resources);
623 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
625 return resource || { username: "" };
628 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
631 {formatPermissionLevel(link.name as PermissionLevel)}
634 data-cy="edit-permission-button"
635 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
646 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
647 const link = getResource<LinkResource>(props.uuid)(state.resources);
648 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
651 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
652 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
654 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
656 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
657 const link = getResource<LinkResource>(props.uuid)(state.resources);
658 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
661 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
662 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
664 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
666 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
667 const headResource = getResource<Resource>(link.headUuid)(state.resources);
668 if (headResource && headResource.kind === ResourceKind.GROUP) {
669 return (headResource as GroupResource).canManage;
677 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
681 <Tooltip title="Run process">
682 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
691 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
692 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
694 uuid: resource ? resource.uuid : "",
696 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
698 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
699 if (ownerUuid === getPublicUuid(uuidPrefix)) {
700 return renderStatus(WorkflowStatus.PUBLIC);
702 return renderStatus(WorkflowStatus.PRIVATE);
706 const renderStatus = (status: string) => (
709 style={{ width: "60px" }}
715 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
716 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
717 const uuidPrefix = getUuidPrefix(state);
719 ownerUuid: resource ? resource.ownerUuid : "",
722 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
724 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
725 const process = getProcess(props.uuid)(state.resources);
726 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
727 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
729 enum ColumnSelection {
730 OUTPUT_UUID = "outputUuid",
731 LOG_UUID = "logUuid",
734 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
735 const selectedColumnUuid = item[column];
743 {selectedColumnUuid ? (
746 style={{ width: "auto", cursor: "pointer" }}
748 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
756 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
761 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
762 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
764 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
766 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
767 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
769 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
771 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
772 const process = getProcess(props.uuid)(state.resources);
773 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
774 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
776 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
777 const process = getProcess(props.uuid)(state.resources);
778 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
779 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
781 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
782 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
783 return { date: resource ? resource.createdAt : "" };
784 })((props: { date: string }) => renderDate(props.date));
786 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
787 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
788 return { date: resource ? resource.modifiedAt : "" };
789 })((props: { date: string }) => renderDate(props.date));
791 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
792 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
793 return { date: resource ? resource.trashAt : "" };
794 })((props: { date: string }) => renderDate(props.date));
796 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
797 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
798 return { date: resource ? resource.deleteAt : "" };
799 })((props: { date: string }) => renderDate(props.date));
801 export const renderFileSize = (fileSize?: number) => (
804 style={{ minWidth: "45px" }}
806 {formatFileSize(fileSize)}
810 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
811 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
813 if (resource && resource.kind !== ResourceKind.COLLECTION) {
814 return { fileSize: "" };
817 return { fileSize: resource ? resource.fileSizeTotal : 0 };
818 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
820 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
822 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
823 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
824 return { owner: resource ? resource.ownerUuid : "" };
825 })((props: { owner: string }) => renderOwner(props.owner));
827 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
828 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
829 const ownerNameState = state.ownerName;
830 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
831 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
832 })((props: { owner: string }) => renderOwner(props.owner));
834 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
835 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
836 return { uuid: resource ? resource.uuid : "" };
837 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
839 const renderVersion = (version: number) => {
840 return <Typography>{version ?? "-"}</Typography>;
843 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
844 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
845 return { version: resource ? resource.version : "" };
846 })((props: { version: number }) => renderVersion(props.version));
848 const renderPortableDataHash = (portableDataHash: string | null) => (
850 {portableDataHash ? (
853 <CopyToClipboardSnackbar value={portableDataHash} />
861 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
862 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
863 return { portableDataHash: resource ? resource.portableDataHash : "" };
864 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
866 const renderFileCount = (fileCount: number) => {
867 return <Typography>{fileCount ?? "-"}</Typography>;
870 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
871 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
872 return { fileCount: resource ? resource.fileCount : "" };
873 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
875 const userFromID = connect((state: RootState, props: { uuid: string }) => {
876 let userFullname = "";
877 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
880 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
883 return { uuid: props.uuid, userFullname };
886 const ownerFromResourceId = compose(
887 connect((state: RootState, props: { uuid: string }) => {
888 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
889 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
894 const _resourceWithName = withStyles(
897 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
898 const { uuid, userFullname, dispatch, theme } = props;
899 if (userFullname === "") {
900 dispatch<any>(loadResource(uuid, false));
903 style={{ color: theme.palette.primary.main }}
914 style={{ color: theme.palette.primary.main }}
918 {userFullname} ({uuid})
923 const _resourceWithNameLink = withStyles(
926 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
927 const { uuid, userFullname, dispatch, theme } = props;
929 dispatch<any>(loadResource(uuid, false));
934 style={{ color: theme.palette.primary.main, cursor: 'pointer' }}
937 onClick={() => dispatch<any>(navigateTo(uuid))}
939 {userFullname ? userFullname : uuid}
945 export const ResourceOwnerWithNameLink = ownerFromResourceId(_resourceWithNameLink);
947 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
949 export const ResourceWithName = userFromID(_resourceWithName);
951 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
952 const { uuid, userFullname, dispatch } = props;
954 if (userFullname === "") {
955 dispatch<any>(loadResource(uuid, false));
957 return <span>{userFullname ? userFullname : uuid}</span>;
960 export const ResponsiblePerson = compose(
961 connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
962 let responsiblePersonName: string = "";
963 let responsiblePersonUUID: string = "";
964 let responsiblePersonProperty: string = "";
966 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
968 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
970 while (!responsiblePersonProperty && keys[index]) {
971 const key = keys[index];
972 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
973 responsiblePersonProperty = key;
979 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
981 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
982 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
983 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
986 if (resource && resource.kind === ResourceKind.USER) {
987 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
990 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
992 withStyles({}, { withTheme: true })
993 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
994 const { uuid, responsiblePersonName, parentRef, theme } = props;
996 if (!uuid && parentRef) {
997 parentRef.style.display = "none";
999 } else if (parentRef) {
1000 parentRef.style.display = "block";
1003 if (!responsiblePersonName) {
1006 style={{ color: theme.palette.primary.main }}
1017 style={{ color: theme.palette.primary.main }}
1021 {responsiblePersonName} ({uuid})
1026 const renderType = (type: string, subtype: string) => <Typography noWrap>{resourceLabel(type, subtype)}</Typography>;
1028 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
1029 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1030 return { type: resource ? resource.kind : "", subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : "" };
1031 })((props: { type: string; subtype: string }) => renderType(props.type, props.subtype));
1033 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1034 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1035 })((props: { resource: GroupContentsResource }) =>
1036 props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1037 <CollectionStatus uuid={props.resource.uuid} />
1039 <ProcessStatus uuid={props.resource.uuid} />
1043 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1044 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1045 })((props: { collection: CollectionResource }) =>
1046 props.collection.uuid !== props.collection.currentVersionUuid ? (
1047 <Typography>version {props.collection.version}</Typography>
1049 <Typography>head version</Typography>
1053 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1055 collection: getResource<CollectionResource>(props.uuid)(state.resources),
1057 className: props.className,
1059 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1060 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1063 export const ProcessStatus = compose(
1064 connect((state: RootState, props: { uuid: string }) => {
1065 return { process: getProcess(props.uuid)(state.resources) };
1067 withStyles({}, { withTheme: true })
1068 )((props: { process?: Process; theme: ArvadosTheme }) =>
1071 label={getProcessStatus(props.process)}
1073 height: props.theme.spacing.unit * 3,
1074 width: props.theme.spacing.unit * 12,
1075 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1076 fontSize: "0.875rem",
1077 borderRadius: props.theme.spacing.unit * 0.625,
1081 <Typography>-</Typography>
1085 export const ProcessStartDate = connect((state: RootState, props: { uuid: string }) => {
1086 const process = getProcess(props.uuid)(state.resources);
1087 return { date: process && process.container ? process.container.startedAt : "" };
1088 })((props: { date: string }) => renderDate(props.date));
1090 export const renderRunTime = (time: number) => (
1093 style={{ minWidth: "45px" }}
1095 {formatTime(time, true)}
1099 interface ContainerRunTimeProps {
1103 interface ContainerRunTimeState {
1107 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1108 return { process: getProcess(props.uuid)(state.resources) };
1110 class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1113 constructor(props: ContainerRunTimeProps) {
1115 this.state = { runtime: this.getRuntime() };
1119 return this.props.process ? getProcessRuntime(this.props.process) : 0;
1123 this.setState({ runtime: this.getRuntime() });
1126 componentDidMount() {
1127 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1130 componentWillUnmount() {
1131 clearInterval(this.timer);
1135 return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;