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 { LinkClass, LinkResource } from "models/link";
40 import { navigateTo, navigateToGroupDetails, navigateToUserProfile } from "store/navigation/navigation-action";
41 import { withResourceData } from "views-components/data-explorer/with-resources";
42 import { CollectionResource } from "models/collection";
43 import { IllegalNamingWarning } from "components/warning/warning";
44 import { loadResource } from "store/resources/resources-actions";
45 import { BuiltinGroups, getBuiltinGroupUuid, GroupClass, GroupResource, isBuiltinGroup } from "models/group";
46 import { openRemoveGroupMemberDialog } from "store/group-details-panel/group-details-panel-actions";
47 import { setMemberIsHidden } from "store/group-details-panel/group-details-panel-actions";
48 import { formatPermissionLevel } from "views-components/sharing-dialog/permission-select";
49 import { PermissionLevel } from "models/permission";
50 import { openPermissionEditContextMenu } from "store/context-menu/context-menu-actions";
51 import { VirtualMachinesResource } from "models/virtual-machines";
52 import { CopyToClipboardSnackbar } from "components/copy-to-clipboard-snackbar/copy-to-clipboard-snackbar";
53 import { ProjectResource } from "models/project";
54 import { ProcessResource } from "models/process";
55 import { ServiceRepository } from "services/services";
56 import { loadUsersPanel } from "store/users/users-actions";
58 export const toggleIsAdmin = (uuid: string) =>
59 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
60 const { resources } = getState();
61 const data = getResource<UserResource>(uuid)(resources);
62 const isAdmin = data!.isAdmin;
63 const newActivity = await services.userService.update(uuid, { isAdmin: !isAdmin });
64 dispatch<any>(loadUsersPanel());
68 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
69 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
77 <Grid item>{renderIcon(item)}</Grid>
81 style={{ width: "auto", cursor: "pointer" }}
84 dispatch<any>(navFunc(item.uuid))
87 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
92 <Typography variant="caption">
93 <FavoriteStar resourceUuid={item.uuid} />
94 <PublicFavoriteStar resourceUuid={item.uuid} />
95 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
102 export const FrozenProject = (props: { item: ProjectResource }) => {
103 const [fullUsername, setFullusername] = React.useState<any>(null);
104 const getFullName = React.useCallback(() => {
105 if (props.item.frozenByUuid) {
106 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
108 }, [props.item, setFullusername]);
110 if (props.item.frozenByUuid) {
115 title={<span>Project was frozen by {fullUsername}</span>}
117 <FreezeIcon style={{ fontSize: "inherit" }} />
125 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
126 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
128 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
130 const renderIcon = (item: GroupContentsResource) => {
132 case ResourceKind.PROJECT:
133 if (item.groupClass === GroupClass.FILTER) {
134 return <FilterGroupIcon />;
136 return <ProjectIcon />;
137 case ResourceKind.COLLECTION:
138 if (item.uuid === item.currentVersionUuid) {
139 return <CollectionIcon />;
141 return <CollectionOldVersionIcon />;
142 case ResourceKind.PROCESS:
143 return <ProcessIcon />;
144 case ResourceKind.WORKFLOW:
145 return <WorkflowIcon />;
147 return <DefaultIcon />;
151 const renderDate = (date?: string) => {
155 style={{ minWidth: "100px" }}
162 const renderWorkflowName = (item: WorkflowResource) => (
169 <Grid item>{renderIcon(item)}</Grid>
173 style={{ width: "100px" }}
181 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
182 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
184 })(renderWorkflowName);
186 const getPublicUuid = (uuidPrefix: string) => {
187 return `${uuidPrefix}-tpzed-anonymouspublic`;
190 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
191 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
194 {!isPublic && uuid && (
195 <Tooltip title="Share">
196 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
205 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
206 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
207 const uuidPrefix = getUuidPrefix(state);
209 uuid: resource ? resource.uuid : "",
210 ownerUuid: resource ? resource.ownerUuid : "",
213 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
214 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
218 const renderFirstName = (item: { firstName: string }) => {
219 return <Typography noWrap>{item.firstName}</Typography>;
222 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
223 const resource = getResource<UserResource>(props.uuid)(state.resources);
224 return resource || { firstName: "" };
227 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
229 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
230 const resource = getResource<UserResource>(props.uuid)(state.resources);
231 return resource || { lastName: "" };
234 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
235 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
240 style={{ cursor: "pointer" }}
241 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
246 <Typography noWrap>{displayName}</Typography>
250 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
251 const resource = getResource<UserResource>(props.uuid)(state.resources);
252 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
253 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
254 renderFullName(props.dispatch, props.item, props.link)
257 const renderUuid = (item: { uuid: string }) => (
263 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
267 const renderUuidCopyIcon = (item: { uuid: string }) => (
272 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
276 export const ResourceUuid = connect(
277 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
280 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
282 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
283 const resource = getResource<UserResource>(props.uuid)(state.resources);
284 return resource || { email: "" };
287 enum UserAccountStatus {
289 INACTIVE = "Inactive",
294 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
300 data-cy="account-status"
304 switch (props.status) {
305 case UserAccountStatus.ACTIVE:
306 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
307 case UserAccountStatus.SETUP:
308 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
309 case UserAccountStatus.INACTIVE:
310 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
317 <Typography noWrap>{props.status}</Typography>
322 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
323 const user = getResource<UserResource>(props.uuid)(state.resources);
324 // Get membership links for all users group
325 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
326 const permissions = filterResources(
327 (resource: LinkResource) =>
328 resource.kind === ResourceKind.LINK &&
329 resource.linkClass === LinkClass.PERMISSION &&
330 resource.headUuid === allUsersGroupUuid &&
331 resource.tailUuid === props.uuid
336 ? { status: UserAccountStatus.ACTIVE }
337 : permissions.length > 0
338 ? { status: UserAccountStatus.SETUP }
339 : { status: UserAccountStatus.INACTIVE };
341 return { status: UserAccountStatus.UNKNOWN };
345 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
346 const link = getResource<LinkResource>(props.uuid)(state.resources);
347 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
348 })(renderAccountStatus);
350 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
352 const renderIsHidden = (props: {
353 memberLinkUuid: string;
354 permissionLinkUuid: string;
357 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
359 if (props.memberLinkUuid) {
362 data-cy="user-visible-checkbox"
364 checked={props.visible}
365 disabled={!props.canManage}
368 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
373 return <Typography />;
377 export const ResourceLinkTailIsVisible = connect(
378 (state: RootState, props: { uuid: string }) => {
379 const link = getResource<LinkResource>(props.uuid)(state.resources);
380 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
381 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
382 const permissions = filterResources((resource: LinkResource) => {
384 resource.linkClass === LinkClass.PERMISSION &&
385 resource.headUuid === link?.tailUuid &&
386 resource.tailUuid === group?.uuid &&
387 resource.name === PermissionLevel.CAN_READ
391 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
392 const isVisible = link && group && permissions.length > 0;
393 // Consider whether the current user canManage this resurce in addition when it's possible
394 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
396 return member?.kind === ResourceKind.USER
397 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
398 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
400 { setMemberIsHidden }
403 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
406 checked={props.isAdmin}
409 props.toggleIsAdmin(props.uuid);
414 export const ResourceIsAdmin = connect(
415 (state: RootState, props: { uuid: string }) => {
416 const resource = getResource<UserResource>(props.uuid)(state.resources);
417 return resource || { isAdmin: false };
422 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
424 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
425 const resource = getResource<UserResource>(props.uuid)(state.resources);
426 return resource || { username: "", uuid: props.uuid };
429 // Virtual machine resource
431 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
433 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
434 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
435 return resource || { hostname: "" };
438 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
440 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
441 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
442 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
444 return { user: user?.username || permission?.tailUuid || "" };
445 })(renderVirtualMachineLogin);
448 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
450 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
452 export const CommonUuid = withResourceData("uuid", renderCommonData);
454 // Api Client Authorizations
455 export const TokenApiClientId = withResourceData("apiClientId", renderCommonData);
457 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
459 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
461 export const TokenDefaultOwnerUuid = withResourceData("defaultOwnerUuid", renderCommonData);
463 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
465 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
467 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
469 export const TokenScopes = withResourceData("scopes", renderCommonData);
471 export const TokenUserId = withResourceData("userId", renderCommonData);
473 const clusterColors = [
481 export const ResourceCluster = (props: { uuid: string }) => {
482 const CLUSTER_ID_LENGTH = 5;
483 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf("-") : 5;
484 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : "";
486 pos >= CLUSTER_ID_LENGTH
487 ? ((props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1) + props.uuid.charCodeAt(2)) * props.uuid.charCodeAt(3) +
488 props.uuid.charCodeAt(4)) %
494 backgroundColor: clusterColors[ci][0],
495 color: clusterColors[ci][1],
506 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
508 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
509 const resource = getResource<LinkResource>(props.uuid)(state.resources);
510 return resource || { name: "" };
513 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
515 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
516 const resource = getResource<LinkResource>(props.uuid)(state.resources);
517 return resource || { linkClass: "" };
520 const getResourceDisplayName = (resource: Resource): string => {
521 if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
522 // We can be sure the resource is UserResource
523 return getUserDisplayName(resource as UserResource);
525 return (resource as GroupContentsResource).name;
529 const renderResourceLink = (dispatch: Dispatch, item: Resource ) => {
530 var displayName = getResourceDisplayName(item);
536 style={{ cursor: "pointer" }}
538 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
539 ? dispatch<any>(navigateToGroupDetails(item.uuid))
540 : item.kind === ResourceKind.USER
541 ? dispatch<any>(navigateToUserProfile(item.uuid))
542 : dispatch<any>(navigateTo(item.uuid));
545 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
546 {displayName || item.uuid}
551 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
552 const resource = getResource<LinkResource>(props.uuid)(state.resources);
553 const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
556 item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
558 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
560 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
561 const resource = getResource<LinkResource>(props.uuid)(state.resources);
562 const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
565 item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
567 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
569 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
570 const resource = getResource<LinkResource>(props.uuid)(state.resources);
571 return resource || { uuid: "" };
574 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
575 const link = getResource<LinkResource>(props.uuid)(state.resources);
576 const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
578 return headResource || { uuid: "" };
581 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
582 const link = getResource<LinkResource>(props.uuid)(state.resources);
583 const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
585 return tailResource || { uuid: "" };
588 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
593 data-cy="resource-delete-button"
594 onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
603 data-cy="resource-delete-button"
610 return <Typography noWrap></Typography>;
614 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
615 const link = getResource<LinkResource>(props.uuid)(state.resources);
616 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
619 item: link || { uuid: "", kind: ResourceKind.NONE },
620 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
622 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
624 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
625 const link = getResource<LinkResource>(props.uuid)(state.resources);
626 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
628 return resource || { email: "" };
631 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
632 const link = getResource<LinkResource>(props.uuid)(state.resources);
633 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
635 return resource || { username: "" };
638 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
641 {formatPermissionLevel(link.name as PermissionLevel)}
644 data-cy="edit-permission-button"
645 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
656 export const ResourceLinkHeadPermissionLevel = 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 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
667 const link = getResource<LinkResource>(props.uuid)(state.resources);
668 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
671 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
672 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
674 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
676 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
677 const headResource = getResource<Resource>(link.headUuid)(state.resources);
678 if (headResource && headResource.kind === ResourceKind.GROUP) {
679 return (headResource as GroupResource).canManage;
687 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
691 <Tooltip title="Run process">
692 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
701 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
702 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
704 uuid: resource ? resource.uuid : "",
706 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
708 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
709 if (ownerUuid === getPublicUuid(uuidPrefix)) {
710 return renderStatus(WorkflowStatus.PUBLIC);
712 return renderStatus(WorkflowStatus.PRIVATE);
716 const renderStatus = (status: string) => (
719 style={{ width: "60px" }}
725 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
726 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
727 const uuidPrefix = getUuidPrefix(state);
729 ownerUuid: resource ? resource.ownerUuid : "",
732 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
734 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
735 const process = getProcess(props.uuid)(state.resources);
736 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
737 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
739 enum ColumnSelection {
740 OUTPUT_UUID = "outputUuid",
741 LOG_UUID = "logUuid",
744 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
745 const selectedColumnUuid = item[column];
753 {selectedColumnUuid ? (
756 style={{ width: "auto", cursor: "pointer" }}
758 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
766 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
771 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
772 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
774 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
776 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
777 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
779 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
781 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
782 const process = getProcess(props.uuid)(state.resources);
783 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
784 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
786 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
787 const process = getProcess(props.uuid)(state.resources);
788 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
789 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
791 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
792 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
793 return { date: resource ? resource.createdAt : "" };
794 })((props: { date: string }) => renderDate(props.date));
796 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
797 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
798 return { date: resource ? resource.modifiedAt : "" };
799 })((props: { date: string }) => renderDate(props.date));
801 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
802 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
803 return { date: resource ? resource.trashAt : "" };
804 })((props: { date: string }) => renderDate(props.date));
806 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
807 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
808 return { date: resource ? resource.deleteAt : "" };
809 })((props: { date: string }) => renderDate(props.date));
811 export const renderFileSize = (fileSize?: number) => (
814 style={{ minWidth: "45px" }}
816 {formatFileSize(fileSize)}
820 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
821 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
823 if (resource && resource.kind !== ResourceKind.COLLECTION) {
824 return { fileSize: "" };
827 return { fileSize: resource ? resource.fileSizeTotal : 0 };
828 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
830 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
832 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
833 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
834 return { owner: resource ? resource.ownerUuid : "" };
835 })((props: { owner: string }) => renderOwner(props.owner));
837 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
838 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
839 const ownerNameState = state.ownerName;
840 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
841 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
842 })((props: { owner: string }) => renderOwner(props.owner));
844 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
845 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
846 return { uuid: resource ? resource.uuid : "" };
847 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
849 const renderVersion = (version: number) => {
850 return <Typography>{version ?? "-"}</Typography>;
853 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
854 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
855 return { version: resource ? resource.version : "" };
856 })((props: { version: number }) => renderVersion(props.version));
858 const renderPortableDataHash = (portableDataHash: string | null) => (
860 {portableDataHash ? (
863 <CopyToClipboardSnackbar value={portableDataHash} />
871 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
872 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
873 return { portableDataHash: resource ? resource.portableDataHash : "" };
874 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
876 const renderFileCount = (fileCount: number) => {
877 return <Typography>{fileCount ?? "-"}</Typography>;
880 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
881 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
882 return { fileCount: resource ? resource.fileCount : "" };
883 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
885 const userFromID = connect((state: RootState, props: { uuid: string }) => {
886 let userFullname = "";
887 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
890 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
893 return { uuid: props.uuid, userFullname };
896 const ownerFromResourceId = compose(
897 connect((state: RootState, props: { uuid: string }) => {
898 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
899 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
904 const _resourceWithName = withStyles(
907 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
908 const { uuid, userFullname, dispatch, theme } = props;
909 if (userFullname === "") {
910 dispatch<any>(loadResource(uuid, false));
913 style={{ color: theme.palette.primary.main }}
924 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.unit * 3,
1084 width: props.theme.spacing.unit * 12,
1085 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1086 fontSize: "0.875rem",
1087 borderRadius: props.theme.spacing.unit * 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>;