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";
59 import { ProcessTypeFilter } from "store/resource-type-filters/resource-type-filters";
61 export const toggleIsAdmin = (uuid: string) =>
62 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
63 const { resources } = getState();
64 const data = getResource<UserResource>(uuid)(resources);
65 const isAdmin = data!.isAdmin;
66 const newActivity = await services.userService.update(uuid, { isAdmin: !isAdmin });
67 dispatch<any>(loadUsersPanel());
71 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
72 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
80 <Grid item>{renderIcon(item)}</Grid>
84 style={{ width: "auto", cursor: "pointer" }}
87 dispatch<any>(navFunc(item.uuid))
90 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
95 <Typography variant="caption">
96 <FavoriteStar resourceUuid={item.uuid} />
97 <PublicFavoriteStar resourceUuid={item.uuid} />
98 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
105 export const FrozenProject = (props: { item: ProjectResource }) => {
106 const [fullUsername, setFullusername] = React.useState<any>(null);
107 const getFullName = React.useCallback(() => {
108 if (props.item.frozenByUuid) {
109 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
111 }, [props.item, setFullusername]);
113 if (props.item.frozenByUuid) {
118 title={<span>Project was frozen by {fullUsername}</span>}
120 <FreezeIcon style={{ fontSize: "inherit" }} />
128 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
129 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
131 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
133 const renderIcon = (item: GroupContentsResource) => {
135 case ResourceKind.PROJECT:
136 if (item.groupClass === GroupClass.FILTER) {
137 return <FilterGroupIcon />;
139 return <ProjectIcon />;
140 case ResourceKind.COLLECTION:
141 if (item.uuid === item.currentVersionUuid) {
142 return <CollectionIcon />;
144 return <CollectionOldVersionIcon />;
145 case ResourceKind.PROCESS:
146 return <ProcessIcon />;
147 case ResourceKind.WORKFLOW:
148 return <WorkflowIcon />;
150 return <DefaultIcon />;
154 const renderDate = (date?: string) => {
158 style={{ minWidth: "100px" }}
165 const renderWorkflowName = (item: WorkflowResource) => (
172 <Grid item>{renderIcon(item)}</Grid>
176 style={{ width: "100px" }}
184 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
185 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
187 })(renderWorkflowName);
189 const getPublicUuid = (uuidPrefix: string) => {
190 return `${uuidPrefix}-tpzed-anonymouspublic`;
193 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
194 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
197 {!isPublic && uuid && (
198 <Tooltip title="Share">
199 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
208 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
209 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
210 const uuidPrefix = getUuidPrefix(state);
212 uuid: resource ? resource.uuid : "",
213 ownerUuid: resource ? resource.ownerUuid : "",
216 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
217 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
221 const renderFirstName = (item: { firstName: string }) => {
222 return <Typography noWrap>{item.firstName}</Typography>;
225 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
226 const resource = getResource<UserResource>(props.uuid)(state.resources);
227 return resource || { firstName: "" };
230 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
232 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
233 const resource = getResource<UserResource>(props.uuid)(state.resources);
234 return resource || { lastName: "" };
237 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
238 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
243 style={{ cursor: "pointer" }}
244 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
249 <Typography noWrap>{displayName}</Typography>
253 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
254 const resource = getResource<UserResource>(props.uuid)(state.resources);
255 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
256 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
257 renderFullName(props.dispatch, props.item, props.link)
260 const renderUuid = (item: { uuid: string }) => (
266 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
270 const renderUuidCopyIcon = (item: { uuid: string }) => (
275 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
279 export const ResourceUuid = connect(
280 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
283 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
285 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
286 const resource = getResource<UserResource>(props.uuid)(state.resources);
287 return resource || { email: "" };
290 enum UserAccountStatus {
292 INACTIVE = "Inactive",
297 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
303 data-cy="account-status"
307 switch (props.status) {
308 case UserAccountStatus.ACTIVE:
309 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
310 case UserAccountStatus.SETUP:
311 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
312 case UserAccountStatus.INACTIVE:
313 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
320 <Typography noWrap>{props.status}</Typography>
325 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
326 const user = getResource<UserResource>(props.uuid)(state.resources);
327 // Get membership links for all users group
328 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
329 const permissions = filterResources(
330 (resource: LinkResource) =>
331 resource.kind === ResourceKind.LINK &&
332 resource.linkClass === LinkClass.PERMISSION &&
333 resource.headUuid === allUsersGroupUuid &&
334 resource.tailUuid === props.uuid
339 ? { status: UserAccountStatus.ACTIVE }
340 : permissions.length > 0
341 ? { status: UserAccountStatus.SETUP }
342 : { status: UserAccountStatus.INACTIVE };
344 return { status: UserAccountStatus.UNKNOWN };
348 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
349 const link = getResource<LinkResource>(props.uuid)(state.resources);
350 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
351 })(renderAccountStatus);
353 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
355 const renderIsHidden = (props: {
356 memberLinkUuid: string;
357 permissionLinkUuid: string;
360 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
362 if (props.memberLinkUuid) {
365 data-cy="user-visible-checkbox"
367 checked={props.visible}
368 disabled={!props.canManage}
371 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
376 return <Typography />;
380 export const ResourceLinkTailIsVisible = connect(
381 (state: RootState, props: { uuid: string }) => {
382 const link = getResource<LinkResource>(props.uuid)(state.resources);
383 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
384 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
385 const permissions = filterResources((resource: LinkResource) => {
387 resource.linkClass === LinkClass.PERMISSION &&
388 resource.headUuid === link?.tailUuid &&
389 resource.tailUuid === group?.uuid &&
390 resource.name === PermissionLevel.CAN_READ
394 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
395 const isVisible = link && group && permissions.length > 0;
396 // Consider whether the current user canManage this resurce in addition when it's possible
397 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
399 return member?.kind === ResourceKind.USER
400 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
401 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
403 { setMemberIsHidden }
406 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
409 checked={props.isAdmin}
412 props.toggleIsAdmin(props.uuid);
417 export const ResourceIsAdmin = connect(
418 (state: RootState, props: { uuid: string }) => {
419 const resource = getResource<UserResource>(props.uuid)(state.resources);
420 return resource || { isAdmin: false };
425 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
427 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
428 const resource = getResource<UserResource>(props.uuid)(state.resources);
429 return resource || { username: "", uuid: props.uuid };
432 // Virtual machine resource
434 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
436 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
437 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
438 return resource || { hostname: "" };
441 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
443 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
444 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
445 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
447 return { user: user?.username || permission?.tailUuid || "" };
448 })(renderVirtualMachineLogin);
451 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
453 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
455 export const CommonUuid = withResourceData("uuid", renderCommonData);
457 // Api Client Authorizations
458 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
460 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
462 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
464 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
466 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
468 export const TokenScopes = withResourceData("scopes", renderCommonData);
470 export const TokenUserId = withResourceData("userId", renderCommonData);
472 const clusterColors = [
480 export const ResourceCluster = (props: { uuid: string }) => {
481 const CLUSTER_ID_LENGTH = 5;
482 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf("-") : 5;
483 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : "";
485 pos >= CLUSTER_ID_LENGTH
486 ? ((props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1) + props.uuid.charCodeAt(2)) * props.uuid.charCodeAt(3) +
487 props.uuid.charCodeAt(4)) %
493 backgroundColor: clusterColors[ci][0],
494 color: clusterColors[ci][1],
505 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
507 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
508 const resource = getResource<LinkResource>(props.uuid)(state.resources);
509 return resource || { name: "" };
512 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
514 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
515 const resource = getResource<LinkResource>(props.uuid)(state.resources);
516 return resource || { linkClass: "" };
519 const getResourceDisplayName = (resource: Resource): string => {
520 if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
521 // We can be sure the resource is UserResource
522 return getUserDisplayName(resource as UserResource);
524 return (resource as GroupContentsResource).name;
528 const renderResourceLink = (dispatch: Dispatch, item: Resource ) => {
529 var displayName = getResourceDisplayName(item);
535 style={{ cursor: "pointer" }}
537 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
538 ? dispatch<any>(navigateToGroupDetails(item.uuid))
539 : item.kind === ResourceKind.USER
540 ? dispatch<any>(navigateToUserProfile(item.uuid))
541 : dispatch<any>(navigateTo(item.uuid));
544 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
545 {displayName || item.uuid}
550 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
551 const resource = getResource<LinkResource>(props.uuid)(state.resources);
552 const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
555 item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
557 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
559 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
560 const resource = getResource<LinkResource>(props.uuid)(state.resources);
561 const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
564 item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
566 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
568 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
569 const resource = getResource<LinkResource>(props.uuid)(state.resources);
570 return resource || { uuid: "" };
573 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
574 const link = getResource<LinkResource>(props.uuid)(state.resources);
575 const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
577 return headResource || { uuid: "" };
580 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
581 const link = getResource<LinkResource>(props.uuid)(state.resources);
582 const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
584 return tailResource || { uuid: "" };
587 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
592 data-cy="resource-delete-button"
593 onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
602 data-cy="resource-delete-button"
609 return <Typography noWrap></Typography>;
613 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
614 const link = getResource<LinkResource>(props.uuid)(state.resources);
615 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
618 item: link || { uuid: "", kind: ResourceKind.NONE },
619 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
621 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
623 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
624 const link = getResource<LinkResource>(props.uuid)(state.resources);
625 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
627 return resource || { email: "" };
630 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
631 const link = getResource<LinkResource>(props.uuid)(state.resources);
632 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
634 return resource || { username: "" };
637 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
640 {formatPermissionLevel(link.name as PermissionLevel)}
643 data-cy="edit-permission-button"
644 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
655 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
656 const link = getResource<LinkResource>(props.uuid)(state.resources);
657 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
660 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
661 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
663 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
665 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
666 const link = getResource<LinkResource>(props.uuid)(state.resources);
667 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
670 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
671 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
673 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
675 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
676 const headResource = getResource<Resource>(link.headUuid)(state.resources);
677 if (headResource && headResource.kind === ResourceKind.GROUP) {
678 return (headResource as GroupResource).canManage;
686 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
690 <Tooltip title="Run process">
691 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
700 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
701 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
703 uuid: resource ? resource.uuid : "",
705 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
707 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
708 if (ownerUuid === getPublicUuid(uuidPrefix)) {
709 return renderStatus(WorkflowStatus.PUBLIC);
711 return renderStatus(WorkflowStatus.PRIVATE);
715 const renderStatus = (status: string) => (
718 style={{ width: "60px" }}
724 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
725 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
726 const uuidPrefix = getUuidPrefix(state);
728 ownerUuid: resource ? resource.ownerUuid : "",
731 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
733 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
734 const process = getProcess(props.uuid)(state.resources);
735 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
736 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
738 enum ColumnSelection {
739 OUTPUT_UUID = "outputUuid",
740 LOG_UUID = "logUuid",
743 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
744 const selectedColumnUuid = item[column];
752 {selectedColumnUuid ? (
755 style={{ width: "auto", cursor: "pointer" }}
757 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
765 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
770 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
771 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
773 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
775 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
776 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
778 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
780 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
781 const process = getProcess(props.uuid)(state.resources);
782 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
783 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
785 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
786 const process = getProcess(props.uuid)(state.resources);
787 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
788 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
790 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
791 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
792 return { date: resource ? resource.createdAt : "" };
793 })((props: { date: string }) => renderDate(props.date));
795 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
796 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
797 return { date: resource ? resource.modifiedAt : "" };
798 })((props: { date: string }) => renderDate(props.date));
800 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
801 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
802 return { date: resource ? resource.trashAt : "" };
803 })((props: { date: string }) => renderDate(props.date));
805 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
806 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
807 return { date: resource ? resource.deleteAt : "" };
808 })((props: { date: string }) => renderDate(props.date));
810 export const renderFileSize = (fileSize?: number) => (
813 style={{ minWidth: "45px" }}
815 {formatFileSize(fileSize)}
819 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
820 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
822 if (resource && resource.kind !== ResourceKind.COLLECTION) {
823 return { fileSize: "" };
826 return { fileSize: resource ? resource.fileSizeTotal : 0 };
827 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
829 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
831 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
832 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
833 return { owner: resource ? resource.ownerUuid : "" };
834 })((props: { owner: string }) => renderOwner(props.owner));
836 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
837 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
838 const ownerNameState = state.ownerName;
839 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
840 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
841 })((props: { owner: string }) => renderOwner(props.owner));
843 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
844 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
845 return { uuid: resource ? resource.uuid : "" };
846 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
848 const renderVersion = (version: number) => {
849 return <Typography>{version ?? "-"}</Typography>;
852 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
853 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
854 return { version: resource ? resource.version : "" };
855 })((props: { version: number }) => renderVersion(props.version));
857 const renderPortableDataHash = (portableDataHash: string | null) => (
859 {portableDataHash ? (
862 <CopyToClipboardSnackbar value={portableDataHash} />
870 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
871 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
872 return { portableDataHash: resource ? resource.portableDataHash : "" };
873 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
875 const renderFileCount = (fileCount: number) => {
876 return <Typography>{fileCount ?? "-"}</Typography>;
879 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
880 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
881 return { fileCount: resource ? resource.fileCount : "" };
882 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
884 const userFromID = connect((state: RootState, props: { uuid: string }) => {
885 let userFullname = "";
886 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
889 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
892 return { uuid: props.uuid, userFullname };
895 const ownerFromResourceId = compose(
896 connect((state: RootState, props: { uuid: string }) => {
897 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
898 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
903 const _resourceWithName = withStyles(
906 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
907 const { uuid, userFullname, dispatch, theme } = props;
908 if (userFullname === "") {
909 dispatch<any>(loadResource(uuid, false));
912 style={{ color: theme.palette.primary.main }}
922 style={{ color: theme.palette.primary.main }}
925 {userFullname} ({uuid})
930 const _resourceWithNameLink = withStyles(
933 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
934 const { uuid, userFullname, dispatch, theme } = props;
936 dispatch<any>(loadResource(uuid, false));
941 style={{ color: theme.palette.primary.main, cursor: 'pointer' }}
944 onClick={() => dispatch<any>(navigateTo(uuid))}
946 {userFullname ? userFullname : uuid}
952 export const ResourceOwnerWithNameLink = ownerFromResourceId(_resourceWithNameLink);
954 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
956 export const ResourceWithName = userFromID(_resourceWithName);
958 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
959 const { uuid, userFullname, dispatch } = props;
961 if (userFullname === "") {
962 dispatch<any>(loadResource(uuid, false));
964 return <span>{userFullname ? userFullname : uuid}</span>;
967 export const ResponsiblePerson = compose(
968 connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
969 let responsiblePersonName: string = "";
970 let responsiblePersonUUID: string = "";
971 let responsiblePersonProperty: string = "";
973 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
975 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
977 while (!responsiblePersonProperty && keys[index]) {
978 const key = keys[index];
979 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
980 responsiblePersonProperty = key;
986 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
988 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
989 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
990 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
993 if (resource && resource.kind === ResourceKind.USER) {
994 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
997 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
999 withStyles({}, { withTheme: true })
1000 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
1001 const { uuid, responsiblePersonName, parentRef, theme } = props;
1003 if (!uuid && parentRef) {
1004 parentRef.style.display = "none";
1006 } else if (parentRef) {
1007 parentRef.style.display = "block";
1010 if (!responsiblePersonName) {
1013 style={{ color: theme.palette.primary.main }}
1024 style={{ color: theme.palette.primary.main }}
1028 {responsiblePersonName} ({uuid})
1033 const renderType = (type: string, subtype: string) => <Typography noWrap>{resourceLabel(type, subtype)}</Typography>;
1035 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
1036 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1038 type: resource ? resource.kind : "",
1040 ? resource.kind === ResourceKind.GROUP
1041 ? resource.groupClass
1042 : resource.kind === ResourceKind.PROCESS
1043 ? resource.requestingContainerUuid
1044 ? ProcessTypeFilter.CHILD_PROCESS
1045 : ProcessTypeFilter.MAIN_PROCESS
1049 })((props: { type: string; subtype: string }) => renderType(props.type, props.subtype));
1051 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1052 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1053 })((props: { resource: GroupContentsResource }) =>
1054 props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1055 <CollectionStatus uuid={props.resource.uuid} />
1057 <ProcessStatus uuid={props.resource.uuid} />
1061 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1062 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1063 })((props: { collection: CollectionResource }) =>
1064 props.collection.uuid !== props.collection.currentVersionUuid ? (
1065 <Typography>version {props.collection.version}</Typography>
1067 <Typography>head version</Typography>
1071 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1073 collection: getResource<CollectionResource>(props.uuid)(state.resources),
1075 className: props.className,
1077 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1078 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1081 export const ProcessStatus = compose(
1082 connect((state: RootState, props: { uuid: string }) => {
1083 return { process: getProcess(props.uuid)(state.resources) };
1085 withStyles({}, { withTheme: true })
1086 )((props: { process?: Process; theme: ArvadosTheme }) =>
1089 label={getProcessStatus(props.process)}
1091 height: props.theme.spacing.unit * 3,
1092 width: props.theme.spacing.unit * 12,
1093 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1094 fontSize: "0.875rem",
1095 borderRadius: props.theme.spacing.unit * 0.625,
1099 <Typography>-</Typography>
1103 export const ProcessStartDate = connect((state: RootState, props: { uuid: string }) => {
1104 const process = getProcess(props.uuid)(state.resources);
1105 return { date: process && process.container ? process.container.startedAt : "" };
1106 })((props: { date: string }) => renderDate(props.date));
1108 export const renderRunTime = (time: number) => (
1111 style={{ minWidth: "45px" }}
1113 {formatTime(time, true)}
1117 interface ContainerRunTimeProps {
1121 interface ContainerRunTimeState {
1125 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1126 return { process: getProcess(props.uuid)(state.resources) };
1128 class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1131 constructor(props: ContainerRunTimeProps) {
1133 this.state = { runtime: this.getRuntime() };
1137 return this.props.process ? getProcessRuntime(this.props.process) : 0;
1141 this.setState({ runtime: this.getRuntime() });
1144 componentDidMount() {
1145 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1148 componentWillUnmount() {
1149 clearInterval(this.timer);
1153 return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;
1158 export const GroupMembersCount = connect(
1159 (state: RootState, props: { uuid: string }) => {
1160 const group = getResource<GroupResource>(props.uuid)(state.resources);
1163 value: group?.memberCount,
1167 )(withTheme()((props: {value: number | null | undefined, theme:ArvadosTheme}) => {
1168 if (props.value === undefined) {
1170 return <Typography component={"div"}>
1173 } else if (props.value === null) {
1176 <Tooltip title="Failed to load member count">
1177 <ErrorIcon style={{color: props.theme.customs.colors.greyL}}/>
1181 return <Typography children={props.value} />;