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";
57 const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {
58 const navFunc = "groupClass" in item && item.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
66 <Grid item>{renderIcon(item)}</Grid>
70 style={{ width: "auto", cursor: "pointer" }}
71 onClick={() => dispatch<any>(navFunc(item.uuid))}
73 {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION ? <IllegalNamingWarning name={item.name} /> : null}
78 <Typography variant="caption">
79 <FavoriteStar resourceUuid={item.uuid} />
80 <PublicFavoriteStar resourceUuid={item.uuid} />
81 {item.kind === ResourceKind.PROJECT && <FrozenProject item={item} />}
88 const FrozenProject = (props: { item: ProjectResource }) => {
89 const [fullUsername, setFullusername] = React.useState<any>(null);
90 const getFullName = React.useCallback(() => {
91 if (props.item.frozenByUuid) {
92 setFullusername(<UserNameFromID uuid={props.item.frozenByUuid} />);
94 }, [props.item, setFullusername]);
96 if (props.item.frozenByUuid) {
101 title={<span>Project was frozen by {fullUsername}</span>}
103 <FreezeIcon style={{ fontSize: "inherit" }} />
111 export const ResourceName = connect((state: RootState, props: { uuid: string }) => {
112 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
114 })((resource: GroupContentsResource & DispatchProp<any>) => renderName(resource.dispatch, resource));
116 const renderIcon = (item: GroupContentsResource) => {
118 case ResourceKind.PROJECT:
119 if (item.groupClass === GroupClass.FILTER) {
120 return <FilterGroupIcon />;
122 return <ProjectIcon />;
123 case ResourceKind.COLLECTION:
124 if (item.uuid === item.currentVersionUuid) {
125 return <CollectionIcon />;
127 return <CollectionOldVersionIcon />;
128 case ResourceKind.PROCESS:
129 return <ProcessIcon />;
130 case ResourceKind.WORKFLOW:
131 return <WorkflowIcon />;
133 return <DefaultIcon />;
137 const renderDate = (date?: string) => {
141 style={{ minWidth: "100px" }}
148 const renderWorkflowName = (item: WorkflowResource) => (
155 <Grid item>{renderIcon(item)}</Grid>
159 style={{ width: "100px" }}
167 export const ResourceWorkflowName = connect((state: RootState, props: { uuid: string }) => {
168 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
170 })(renderWorkflowName);
172 const getPublicUuid = (uuidPrefix: string) => {
173 return `${uuidPrefix}-tpzed-anonymouspublic`;
176 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
177 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
180 {!isPublic && uuid && (
181 <Tooltip title="Share">
182 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
191 export const ResourceShare = connect((state: RootState, props: { uuid: string }) => {
192 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
193 const uuidPrefix = getUuidPrefix(state);
195 uuid: resource ? resource.uuid : "",
196 ownerUuid: resource ? resource.ownerUuid : "",
199 })((props: { ownerUuid?: string; uuidPrefix: string; uuid?: string } & DispatchProp<any>) =>
200 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid)
204 const renderFirstName = (item: { firstName: string }) => {
205 return <Typography noWrap>{item.firstName}</Typography>;
208 export const ResourceFirstName = connect((state: RootState, props: { uuid: string }) => {
209 const resource = getResource<UserResource>(props.uuid)(state.resources);
210 return resource || { firstName: "" };
213 const renderLastName = (item: { lastName: string }) => <Typography noWrap>{item.lastName}</Typography>;
215 export const ResourceLastName = connect((state: RootState, props: { uuid: string }) => {
216 const resource = getResource<UserResource>(props.uuid)(state.resources);
217 return resource || { lastName: "" };
220 const renderFullName = (dispatch: Dispatch, item: { uuid: string; firstName: string; lastName: string }, link?: boolean) => {
221 const displayName = (item.firstName + " " + item.lastName).trim() || item.uuid;
226 style={{ cursor: "pointer" }}
227 onClick={() => dispatch<any>(navigateToUserProfile(item.uuid))}
232 <Typography noWrap>{displayName}</Typography>
236 export const UserResourceFullName = connect((state: RootState, props: { uuid: string; link?: boolean }) => {
237 const resource = getResource<UserResource>(props.uuid)(state.resources);
238 return { item: resource || { uuid: "", firstName: "", lastName: "" }, link: props.link };
239 })((props: { item: { uuid: string; firstName: string; lastName: string }; link?: boolean } & DispatchProp<any>) =>
240 renderFullName(props.dispatch, props.item, props.link)
243 const renderUuid = (item: { uuid: string }) => (
249 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
253 const renderUuidCopyIcon = (item: { uuid: string }) => (
258 {(item.uuid && <CopyToClipboardSnackbar value={item.uuid} />) || "-"}
262 export const ResourceUuid = connect(
263 (state: RootState, props: { uuid: string }) => getResource<UserResource>(props.uuid)(state.resources) || { uuid: "" }
266 const renderEmail = (item: { email: string }) => <Typography noWrap>{item.email}</Typography>;
268 export const ResourceEmail = connect((state: RootState, props: { uuid: string }) => {
269 const resource = getResource<UserResource>(props.uuid)(state.resources);
270 return resource || { email: "" };
273 enum UserAccountStatus {
275 INACTIVE = "Inactive",
280 const renderAccountStatus = (props: { status: UserAccountStatus }) => (
286 data-cy="account-status"
290 switch (props.status) {
291 case UserAccountStatus.ACTIVE:
292 return <ActiveIcon style={{ color: "#4caf50", verticalAlign: "middle" }} />;
293 case UserAccountStatus.SETUP:
294 return <SetupIcon style={{ color: "#2196f3", verticalAlign: "middle" }} />;
295 case UserAccountStatus.INACTIVE:
296 return <InactiveIcon style={{ color: "#9e9e9e", verticalAlign: "middle" }} />;
303 <Typography noWrap>{props.status}</Typography>
308 const getUserAccountStatus = (state: RootState, props: { uuid: string }) => {
309 const user = getResource<UserResource>(props.uuid)(state.resources);
310 // Get membership links for all users group
311 const allUsersGroupUuid = getBuiltinGroupUuid(state.auth.localCluster, BuiltinGroups.ALL);
312 const permissions = filterResources(
313 (resource: LinkResource) =>
314 resource.kind === ResourceKind.LINK &&
315 resource.linkClass === LinkClass.PERMISSION &&
316 resource.headUuid === allUsersGroupUuid &&
317 resource.tailUuid === props.uuid
322 ? { status: UserAccountStatus.ACTIVE }
323 : permissions.length > 0
324 ? { status: UserAccountStatus.SETUP }
325 : { status: UserAccountStatus.INACTIVE };
327 return { status: UserAccountStatus.UNKNOWN };
331 export const ResourceLinkTailAccountStatus = connect((state: RootState, props: { uuid: string }) => {
332 const link = getResource<LinkResource>(props.uuid)(state.resources);
333 return link && link.tailKind === ResourceKind.USER ? getUserAccountStatus(state, { uuid: link.tailUuid }) : { status: UserAccountStatus.UNKNOWN };
334 })(renderAccountStatus);
336 export const UserResourceAccountStatus = connect(getUserAccountStatus)(renderAccountStatus);
338 const renderIsHidden = (props: {
339 memberLinkUuid: string;
340 permissionLinkUuid: string;
343 setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void;
345 if (props.memberLinkUuid) {
348 data-cy="user-visible-checkbox"
350 checked={props.visible}
351 disabled={!props.canManage}
354 props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible);
359 return <Typography />;
363 export const ResourceLinkTailIsVisible = connect(
364 (state: RootState, props: { uuid: string }) => {
365 const link = getResource<LinkResource>(props.uuid)(state.resources);
366 const member = getResource<Resource>(link?.tailUuid || "")(state.resources);
367 const group = getResource<GroupResource>(link?.headUuid || "")(state.resources);
368 const permissions = filterResources((resource: LinkResource) => {
370 resource.linkClass === LinkClass.PERMISSION &&
371 resource.headUuid === link?.tailUuid &&
372 resource.tailUuid === group?.uuid &&
373 resource.name === PermissionLevel.CAN_READ
377 const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : "";
378 const isVisible = link && group && permissions.length > 0;
379 // Consider whether the current user canManage this resurce in addition when it's possible
380 const isBuiltin = isBuiltinGroup(link?.headUuid || "");
382 return member?.kind === ResourceKind.USER
383 ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
384 : { memberLinkUuid: "", permissionLinkUuid: "", visible: false, canManage: false };
386 { setMemberIsHidden }
389 const renderIsAdmin = (props: { uuid: string; isAdmin: boolean; toggleIsAdmin: (uuid: string) => void }) => (
392 checked={props.isAdmin}
395 props.toggleIsAdmin(props.uuid);
400 export const ResourceIsAdmin = connect(
401 (state: RootState, props: { uuid: string }) => {
402 const resource = getResource<UserResource>(props.uuid)(state.resources);
403 return resource || { isAdmin: false };
408 const renderUsername = (item: { username: string; uuid: string }) => <Typography noWrap>{item.username || item.uuid}</Typography>;
410 export const ResourceUsername = connect((state: RootState, props: { uuid: string }) => {
411 const resource = getResource<UserResource>(props.uuid)(state.resources);
412 return resource || { username: "", uuid: props.uuid };
415 // Virtual machine resource
417 const renderHostname = (item: { hostname: string }) => <Typography noWrap>{item.hostname}</Typography>;
419 export const VirtualMachineHostname = connect((state: RootState, props: { uuid: string }) => {
420 const resource = getResource<VirtualMachinesResource>(props.uuid)(state.resources);
421 return resource || { hostname: "" };
424 const renderVirtualMachineLogin = (login: { user: string }) => <Typography noWrap>{login.user}</Typography>;
426 export const VirtualMachineLogin = connect((state: RootState, props: { linkUuid: string }) => {
427 const permission = getResource<LinkResource>(props.linkUuid)(state.resources);
428 const user = getResource<UserResource>(permission?.tailUuid || "")(state.resources);
430 return { user: user?.username || permission?.tailUuid || "" };
431 })(renderVirtualMachineLogin);
434 const renderCommonData = (data: string) => <Typography noWrap>{data}</Typography>;
436 const renderCommonDate = (date: string) => <Typography noWrap>{formatDate(date)}</Typography>;
438 export const CommonUuid = withResourceData("uuid", renderCommonData);
440 // Api Client Authorizations
441 export const TokenApiClientId = withResourceData("apiClientId", renderCommonData);
443 export const TokenApiToken = withResourceData("apiToken", renderCommonData);
445 export const TokenCreatedByIpAddress = withResourceData("createdByIpAddress", renderCommonDate);
447 export const TokenDefaultOwnerUuid = withResourceData("defaultOwnerUuid", renderCommonData);
449 export const TokenExpiresAt = withResourceData("expiresAt", renderCommonDate);
451 export const TokenLastUsedAt = withResourceData("lastUsedAt", renderCommonDate);
453 export const TokenLastUsedByIpAddress = withResourceData("lastUsedByIpAddress", renderCommonData);
455 export const TokenScopes = withResourceData("scopes", renderCommonData);
457 export const TokenUserId = withResourceData("userId", renderCommonData);
459 const clusterColors = [
467 export const ResourceCluster = (props: { uuid: string }) => {
468 const CLUSTER_ID_LENGTH = 5;
469 const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf("-") : 5;
470 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substring(0, pos) : "";
472 pos >= CLUSTER_ID_LENGTH
473 ? ((props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1) + props.uuid.charCodeAt(2)) * props.uuid.charCodeAt(3) +
474 props.uuid.charCodeAt(4)) %
480 backgroundColor: clusterColors[ci][0],
481 color: clusterColors[ci][1],
492 const renderLinkName = (item: { name: string }) => <Typography noWrap>{item.name || "-"}</Typography>;
494 export const ResourceLinkName = connect((state: RootState, props: { uuid: string }) => {
495 const resource = getResource<LinkResource>(props.uuid)(state.resources);
496 return resource || { name: "" };
499 const renderLinkClass = (item: { linkClass: string }) => <Typography noWrap>{item.linkClass}</Typography>;
501 export const ResourceLinkClass = connect((state: RootState, props: { uuid: string }) => {
502 const resource = getResource<LinkResource>(props.uuid)(state.resources);
503 return resource || { linkClass: "" };
506 const getResourceDisplayName = (resource: Resource): string => {
507 if ((resource as UserResource).kind === ResourceKind.USER && typeof (resource as UserResource).firstName !== "undefined") {
508 // We can be sure the resource is UserResource
509 return getUserDisplayName(resource as UserResource);
511 return (resource as GroupContentsResource).name;
515 const renderResourceLink = (dispatch: Dispatch, item: Resource) => {
516 var displayName = getResourceDisplayName(item);
522 style={{ cursor: "pointer" }}
524 item.kind === ResourceKind.GROUP && (item as GroupResource).groupClass === "role"
525 ? dispatch<any>(navigateToGroupDetails(item.uuid))
526 : dispatch<any>(navigateTo(item.uuid));
529 {resourceLabel(item.kind, item && item.kind === ResourceKind.GROUP ? (item as GroupResource).groupClass || "" : "")}:{" "}
530 {displayName || item.uuid}
535 export const ResourceLinkTail = connect((state: RootState, props: { uuid: string }) => {
536 const resource = getResource<LinkResource>(props.uuid)(state.resources);
537 const tailResource = getResource<Resource>(resource?.tailUuid || "")(state.resources);
540 item: tailResource || { uuid: resource?.tailUuid || "", kind: resource?.tailKind || ResourceKind.NONE },
542 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
544 export const ResourceLinkHead = connect((state: RootState, props: { uuid: string }) => {
545 const resource = getResource<LinkResource>(props.uuid)(state.resources);
546 const headResource = getResource<Resource>(resource?.headUuid || "")(state.resources);
549 item: headResource || { uuid: resource?.headUuid || "", kind: resource?.headKind || ResourceKind.NONE },
551 })((props: { item: Resource } & DispatchProp<any>) => renderResourceLink(props.dispatch, props.item));
553 export const ResourceLinkUuid = connect((state: RootState, props: { uuid: string }) => {
554 const resource = getResource<LinkResource>(props.uuid)(state.resources);
555 return resource || { uuid: "" };
558 export const ResourceLinkHeadUuid = connect((state: RootState, props: { uuid: string }) => {
559 const link = getResource<LinkResource>(props.uuid)(state.resources);
560 const headResource = getResource<Resource>(link?.headUuid || "")(state.resources);
562 return headResource || { uuid: "" };
565 export const ResourceLinkTailUuid = connect((state: RootState, props: { uuid: string }) => {
566 const link = getResource<LinkResource>(props.uuid)(state.resources);
567 const tailResource = getResource<Resource>(link?.tailUuid || "")(state.resources);
569 return tailResource || { uuid: "" };
572 const renderLinkDelete = (dispatch: Dispatch, item: LinkResource, canManage: boolean) => {
577 data-cy="resource-delete-button"
578 onClick={() => dispatch<any>(openRemoveGroupMemberDialog(item.uuid))}
587 data-cy="resource-delete-button"
594 return <Typography noWrap></Typography>;
598 export const ResourceLinkDelete = connect((state: RootState, props: { uuid: string }) => {
599 const link = getResource<LinkResource>(props.uuid)(state.resources);
600 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
603 item: link || { uuid: "", kind: ResourceKind.NONE },
604 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
606 })((props: { item: LinkResource; canManage: boolean } & DispatchProp<any>) => renderLinkDelete(props.dispatch, props.item, props.canManage));
608 export const ResourceLinkTailEmail = connect((state: RootState, props: { uuid: string }) => {
609 const link = getResource<LinkResource>(props.uuid)(state.resources);
610 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
612 return resource || { email: "" };
615 export const ResourceLinkTailUsername = connect((state: RootState, props: { uuid: string }) => {
616 const link = getResource<LinkResource>(props.uuid)(state.resources);
617 const resource = getResource<UserResource>(link?.tailUuid || "")(state.resources);
619 return resource || { username: "" };
622 const renderPermissionLevel = (dispatch: Dispatch, link: LinkResource, canManage: boolean) => {
625 {formatPermissionLevel(link.name as PermissionLevel)}
628 data-cy="edit-permission-button"
629 onClick={event => dispatch<any>(openPermissionEditContextMenu(event, link))}
640 export const ResourceLinkHeadPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
641 const link = getResource<LinkResource>(props.uuid)(state.resources);
642 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
645 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
646 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
648 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
650 export const ResourceLinkTailPermissionLevel = connect((state: RootState, props: { uuid: string }) => {
651 const link = getResource<LinkResource>(props.uuid)(state.resources);
652 const isBuiltin = isBuiltinGroup(link?.headUuid || "") || isBuiltinGroup(link?.tailUuid || "");
655 link: link || { uuid: "", name: "", kind: ResourceKind.NONE },
656 canManage: link && getResourceLinkCanManage(state, link) && !isBuiltin,
658 })((props: { link: LinkResource; canManage: boolean } & DispatchProp<any>) => renderPermissionLevel(props.dispatch, props.link, props.canManage));
660 const getResourceLinkCanManage = (state: RootState, link: LinkResource) => {
661 const headResource = getResource<Resource>(link.headUuid)(state.resources);
662 if (headResource && headResource.kind === ResourceKind.GROUP) {
663 return (headResource as GroupResource).canManage;
671 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
675 <Tooltip title="Run process">
676 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
685 export const ResourceRunProcess = connect((state: RootState, props: { uuid: string }) => {
686 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
688 uuid: resource ? resource.uuid : "",
690 })((props: { uuid: string } & DispatchProp<any>) => resourceRunProcess(props.dispatch, props.uuid));
692 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
693 if (ownerUuid === getPublicUuid(uuidPrefix)) {
694 return renderStatus(WorkflowStatus.PUBLIC);
696 return renderStatus(WorkflowStatus.PRIVATE);
700 const renderStatus = (status: string) => (
703 style={{ width: "60px" }}
709 export const ResourceWorkflowStatus = connect((state: RootState, props: { uuid: string }) => {
710 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
711 const uuidPrefix = getUuidPrefix(state);
713 ownerUuid: resource ? resource.ownerUuid : "",
716 })((props: { ownerUuid?: string; uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
718 export const ResourceContainerUuid = connect((state: RootState, props: { uuid: string }) => {
719 const process = getProcess(props.uuid)(state.resources);
720 return { uuid: process?.container?.uuid ? process?.container?.uuid : "" };
721 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
723 enum ColumnSelection {
724 OUTPUT_UUID = "outputUuid",
725 LOG_UUID = "logUuid",
728 const renderUuidLinkWithCopyIcon = (dispatch: Dispatch, item: ProcessResource, column: string) => {
729 const selectedColumnUuid = item[column];
737 {selectedColumnUuid ? (
740 style={{ width: "auto", cursor: "pointer" }}
742 onClick={() => dispatch<any>(navigateTo(selectedColumnUuid))}
750 <Grid item>{selectedColumnUuid && renderUuidCopyIcon({ uuid: selectedColumnUuid })}</Grid>
755 export const ResourceOutputUuid = connect((state: RootState, props: { uuid: string }) => {
756 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
758 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.OUTPUT_UUID));
760 export const ResourceLogUuid = connect((state: RootState, props: { uuid: string }) => {
761 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
763 })((process: ProcessResource & DispatchProp<any>) => renderUuidLinkWithCopyIcon(process.dispatch, process, ColumnSelection.LOG_UUID));
765 export const ResourceParentProcess = connect((state: RootState, props: { uuid: string }) => {
766 const process = getProcess(props.uuid)(state.resources);
767 return { parentProcess: process?.containerRequest?.requestingContainerUuid || "" };
768 })((props: { parentProcess: string }) => renderUuid({ uuid: props.parentProcess }));
770 export const ResourceModifiedByUserUuid = connect((state: RootState, props: { uuid: string }) => {
771 const process = getProcess(props.uuid)(state.resources);
772 return { userUuid: process?.containerRequest?.modifiedByUserUuid || "" };
773 })((props: { userUuid: string }) => renderUuid({ uuid: props.userUuid }));
775 export const ResourceCreatedAtDate = connect((state: RootState, props: { uuid: string }) => {
776 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
777 return { date: resource ? resource.createdAt : "" };
778 })((props: { date: string }) => renderDate(props.date));
780 export const ResourceLastModifiedDate = connect((state: RootState, props: { uuid: string }) => {
781 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
782 return { date: resource ? resource.modifiedAt : "" };
783 })((props: { date: string }) => renderDate(props.date));
785 export const ResourceTrashDate = connect((state: RootState, props: { uuid: string }) => {
786 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
787 return { date: resource ? resource.trashAt : "" };
788 })((props: { date: string }) => renderDate(props.date));
790 export const ResourceDeleteDate = connect((state: RootState, props: { uuid: string }) => {
791 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
792 return { date: resource ? resource.deleteAt : "" };
793 })((props: { date: string }) => renderDate(props.date));
795 export const renderFileSize = (fileSize?: number) => (
798 style={{ minWidth: "45px" }}
800 {formatFileSize(fileSize)}
804 export const ResourceFileSize = connect((state: RootState, props: { uuid: string }) => {
805 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
807 if (resource && resource.kind !== ResourceKind.COLLECTION) {
808 return { fileSize: "" };
811 return { fileSize: resource ? resource.fileSizeTotal : 0 };
812 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
814 const renderOwner = (owner: string) => <Typography noWrap>{owner || "-"}</Typography>;
816 export const ResourceOwner = connect((state: RootState, props: { uuid: string }) => {
817 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
818 return { owner: resource ? resource.ownerUuid : "" };
819 })((props: { owner: string }) => renderOwner(props.owner));
821 export const ResourceOwnerName = connect((state: RootState, props: { uuid: string }) => {
822 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
823 const ownerNameState = state.ownerName;
824 const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid);
825 return { owner: ownerName ? ownerName!.name : resource!.ownerUuid };
826 })((props: { owner: string }) => renderOwner(props.owner));
828 export const ResourceUUID = connect((state: RootState, props: { uuid: string }) => {
829 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
830 return { uuid: resource ? resource.uuid : "" };
831 })((props: { uuid: string }) => renderUuid({ uuid: props.uuid }));
833 const renderVersion = (version: number) => {
834 return <Typography>{version ?? "-"}</Typography>;
837 export const ResourceVersion = connect((state: RootState, props: { uuid: string }) => {
838 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
839 return { version: resource ? resource.version : "" };
840 })((props: { version: number }) => renderVersion(props.version));
842 const renderPortableDataHash = (portableDataHash: string | null) => (
844 {portableDataHash ? (
847 <CopyToClipboardSnackbar value={portableDataHash} />
855 export const ResourcePortableDataHash = connect((state: RootState, props: { uuid: string }) => {
856 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
857 return { portableDataHash: resource ? resource.portableDataHash : "" };
858 })((props: { portableDataHash: string }) => renderPortableDataHash(props.portableDataHash));
860 const renderFileCount = (fileCount: number) => {
861 return <Typography>{fileCount ?? "-"}</Typography>;
864 export const ResourceFileCount = connect((state: RootState, props: { uuid: string }) => {
865 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
866 return { fileCount: resource ? resource.fileCount : "" };
867 })((props: { fileCount: number }) => renderFileCount(props.fileCount));
869 const userFromID = connect((state: RootState, props: { uuid: string }) => {
870 let userFullname = "";
871 const resource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
874 userFullname = getUserFullname(resource as User) || (resource as GroupContentsResource).name;
877 return { uuid: props.uuid, userFullname };
880 const ownerFromResourceId = compose(
881 connect((state: RootState, props: { uuid: string }) => {
882 const childResource = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
883 return { uuid: childResource ? (childResource as Resource).ownerUuid : "" };
888 const _resourceWithName = withStyles(
891 )((props: { uuid: string; userFullname: string; dispatch: Dispatch; theme: ArvadosTheme }) => {
892 const { uuid, userFullname, dispatch, theme } = props;
893 if (userFullname === "") {
894 dispatch<any>(loadResource(uuid, false));
897 style={{ color: theme.palette.primary.main }}
908 style={{ color: theme.palette.primary.main }}
912 {userFullname} ({uuid})
917 export const ResourceOwnerWithName = ownerFromResourceId(_resourceWithName);
919 export const ResourceWithName = userFromID(_resourceWithName);
921 export const UserNameFromID = compose(userFromID)((props: { uuid: string; displayAsText?: string; userFullname: string; dispatch: Dispatch }) => {
922 const { uuid, userFullname, dispatch } = props;
924 if (userFullname === "") {
925 dispatch<any>(loadResource(uuid, false));
927 return <span>{userFullname ? userFullname : uuid}</span>;
930 export const ResponsiblePerson = compose(
931 connect((state: RootState, props: { uuid: string; parentRef: HTMLElement | null }) => {
932 let responsiblePersonName: string = "";
933 let responsiblePersonUUID: string = "";
934 let responsiblePersonProperty: string = "";
936 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
938 const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
940 while (!responsiblePersonProperty && keys[index]) {
941 const key = keys[index];
942 if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === "original_owner") {
943 responsiblePersonProperty = key;
949 let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
951 while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
952 responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
953 resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
956 if (resource && resource.kind === ResourceKind.USER) {
957 responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
960 return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
962 withStyles({}, { withTheme: true })
963 )((props: { uuid: string | null; responsiblePersonName: string; parentRef: HTMLElement | null; theme: ArvadosTheme }) => {
964 const { uuid, responsiblePersonName, parentRef, theme } = props;
966 if (!uuid && parentRef) {
967 parentRef.style.display = "none";
969 } else if (parentRef) {
970 parentRef.style.display = "block";
973 if (!responsiblePersonName) {
976 style={{ color: theme.palette.primary.main }}
987 style={{ color: theme.palette.primary.main }}
991 {responsiblePersonName} ({uuid})
996 const renderType = (type: string, subtype: string) => <Typography noWrap>{resourceLabel(type, subtype)}</Typography>;
998 export const ResourceType = connect((state: RootState, props: { uuid: string }) => {
999 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
1000 return { type: resource ? resource.kind : "", subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : "" };
1001 })((props: { type: string; subtype: string }) => renderType(props.type, props.subtype));
1003 export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => {
1004 return { resource: getResource<GroupContentsResource>(props.uuid)(state.resources) };
1005 })((props: { resource: GroupContentsResource }) =>
1006 props.resource && props.resource.kind === ResourceKind.COLLECTION ? (
1007 <CollectionStatus uuid={props.resource.uuid} />
1009 <ProcessStatus uuid={props.resource.uuid} />
1013 export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => {
1014 return { collection: getResource<CollectionResource>(props.uuid)(state.resources) };
1015 })((props: { collection: CollectionResource }) =>
1016 props.collection.uuid !== props.collection.currentVersionUuid ? (
1017 <Typography>version {props.collection.version}</Typography>
1019 <Typography>head version</Typography>
1023 export const CollectionName = connect((state: RootState, props: { uuid: string; className?: string }) => {
1025 collection: getResource<CollectionResource>(props.uuid)(state.resources),
1027 className: props.className,
1029 })((props: { collection: CollectionResource; uuid: string; className?: string }) => (
1030 <Typography className={props.className}>{props.collection?.name || props.uuid}</Typography>
1033 export const ProcessStatus = compose(
1034 connect((state: RootState, props: { uuid: string }) => {
1035 return { process: getProcess(props.uuid)(state.resources) };
1037 withStyles({}, { withTheme: true })
1038 )((props: { process?: Process; theme: ArvadosTheme }) =>
1041 label={getProcessStatus(props.process)}
1043 height: props.theme.spacing.unit * 3,
1044 width: props.theme.spacing.unit * 12,
1045 ...getProcessStatusStyles(getProcessStatus(props.process), props.theme),
1046 fontSize: "0.875rem",
1047 borderRadius: props.theme.spacing.unit * 0.625,
1051 <Typography>-</Typography>
1055 export const ProcessStartDate = connect((state: RootState, props: { uuid: string }) => {
1056 const process = getProcess(props.uuid)(state.resources);
1057 return { date: process && process.container ? process.container.startedAt : "" };
1058 })((props: { date: string }) => renderDate(props.date));
1060 export const renderRunTime = (time: number) => (
1063 style={{ minWidth: "45px" }}
1065 {formatTime(time, true)}
1069 interface ContainerRunTimeProps {
1073 interface ContainerRunTimeState {
1077 export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
1078 return { process: getProcess(props.uuid)(state.resources) };
1080 class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
1083 constructor(props: ContainerRunTimeProps) {
1085 this.state = { runtime: this.getRuntime() };
1089 return this.props.process ? getProcessRuntime(this.props.process) : 0;
1093 this.setState({ runtime: this.getRuntime() });
1096 componentDidMount() {
1097 this.timer = setInterval(this.updateRuntime.bind(this), 5000);
1100 componentWillUnmount() {
1101 clearInterval(this.timer);
1105 return this.props.process ? renderRunTime(this.state.runtime) : <Typography>-</Typography>;