X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e0effe9fd43b8d7c0d7fcb9aade9b718cf5dddda..72470537b4b0a8470b6f5360817cc4039d74978c:/src/views-components/data-explorer/renderers.tsx diff --git a/src/views-components/data-explorer/renderers.tsx b/src/views-components/data-explorer/renderers.tsx index 16ea7a99..ed8e393f 100644 --- a/src/views-components/data-explorer/renderers.tsx +++ b/src/views-components/data-explorer/renderers.tsx @@ -4,39 +4,49 @@ import * as React from 'react'; import { Grid, Typography, withStyles, Tooltip, IconButton, Checkbox } from '@material-ui/core'; -import { FavoriteStar } from '../favorite-star/favorite-star'; -import { ResourceKind, TrashableResource } from '~/models/resource'; -import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, WorkflowIcon, ShareIcon } from '~/components/icon/icon'; -import { formatDate, formatFileSize } from '~/common/formatters'; +import { FavoriteStar, PublicFavoriteStar } from '../favorite-star/favorite-star'; +import { Resource, ResourceKind, TrashableResource } from '~/models/resource'; +import { ProjectIcon, FilterGroupIcon, CollectionIcon, ProcessIcon, DefaultIcon, ShareIcon, CollectionOldVersionIcon, WorkflowIcon } from '~/components/icon/icon'; +import { formatDate, formatFileSize, formatTime } from '~/common/formatters'; import { resourceLabel } from '~/common/labels'; import { connect, DispatchProp } from 'react-redux'; import { RootState } from '~/store/store'; import { getResource } from '~/store/resources/resources'; import { GroupContentsResource } from '~/services/groups-service/groups-service'; -import { getProcess, Process, getProcessStatus, getProcessStatusColor } from '~/store/processes/process'; +import { getProcess, Process, getProcessStatus, getProcessStatusColor, getProcessRuntime } from '~/store/processes/process'; import { ArvadosTheme } from '~/common/custom-theme'; import { compose, Dispatch } from 'redux'; import { WorkflowResource } from '~/models/workflow'; -import { ResourceStatus } from '~/views/workflow-panel/workflow-panel-view'; +import { ResourceStatus as WorkflowStatus } from '~/views/workflow-panel/workflow-panel-view'; import { getUuidPrefix, openRunProcess } from '~/store/workflow-panel/workflow-panel-actions'; -import { getResourceData } from "~/store/resources-data/resources-data"; import { openSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions'; -import { UserResource } from '~/models/user'; +import { getUserFullname, User, UserResource } from '~/models/user'; import { toggleIsActive, toggleIsAdmin } from '~/store/users/users-actions'; - -const renderName = (item: { name: string; uuid: string, kind: string }) => +import { LinkResource } from '~/models/link'; +import { navigateTo } from '~/store/navigation/navigation-action'; +import { withResourceData } from '~/views-components/data-explorer/with-resources'; +import { CollectionResource } from '~/models/collection'; +import { IllegalNamingWarning } from '~/components/warning/warning'; +import { loadResource } from '~/store/resources/resources-actions'; +import { GroupClass } from '~/models/group'; + +const renderName = (dispatch: Dispatch, item: GroupContentsResource) => {renderIcon(item)} - + dispatch(navigateTo(item.uuid))}> + {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION + ? + : null} {item.name} + ; @@ -44,15 +54,21 @@ const renderName = (item: { name: string; uuid: string, kind: string }) => export const ResourceName = connect( (state: RootState, props: { uuid: string }) => { const resource = getResource(props.uuid)(state.resources); - return resource || { name: '', uuid: '', kind: '' }; - })(renderName); + return resource; + })((resource: GroupContentsResource & DispatchProp) => renderName(resource.dispatch, resource)); -const renderIcon = (item: { kind: string }) => { +const renderIcon = (item: GroupContentsResource) => { switch (item.kind) { case ResourceKind.PROJECT: + if (item.groupClass === GroupClass.FILTER) { + return ; + } return ; case ResourceKind.COLLECTION: - return ; + if (item.uuid === item.currentVersionUuid) { + return ; + } + return ; case ResourceKind.PROCESS: return ; case ResourceKind.WORKFLOW: @@ -66,7 +82,7 @@ const renderDate = (date?: string) => { return {formatDate(date)}; }; -const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) => +const renderWorkflowName = (item: WorkflowResource) => {renderIcon(item)} @@ -78,10 +94,10 @@ const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ow ; -export const RosurceWorkflowName = connect( +export const ResourceWorkflowName = connect( (state: RootState, props: { uuid: string }) => { const resource = getResource(props.uuid)(state.resources); - return resource || { name: '', uuid: '', kind: '', ownerUuid: '' }; + return resource; })(renderWorkflowName); const getPublicUuid = (uuidPrefix: string) => { @@ -119,6 +135,7 @@ const renderFirstName = (item: { firstName: string }) => { return {item.firstName}; }; +// User Resources export const ResourceFirstName = connect( (state: RootState, props: { uuid: string }) => { const resource = getResource(props.uuid)(state.resources); @@ -187,6 +204,144 @@ export const ResourceUsername = connect( return resource || { username: '' }; })(renderUsername); +// Common methods +const renderCommonData = (data: string) => + {data}; + +const renderCommonDate = (date: string) => + {formatDate(date)}; + +export const CommonUuid = withResourceData('uuid', renderCommonData); + +// Api Client Authorizations +export const TokenApiClientId = withResourceData('apiClientId', renderCommonData); + +export const TokenApiToken = withResourceData('apiToken', renderCommonData); + +export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate); + +export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData); + +export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate); + +export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate); + +export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData); + +export const TokenScopes = withResourceData('scopes', renderCommonData); + +export const TokenUserId = withResourceData('userId', renderCommonData); + +// Compute Node Resources +const renderNodeInfo = (data: string) => { + return {JSON.stringify(data, null, 4)}; +}; + +const clusterColors = [ + ['#f44336', '#fff'], + ['#2196f3', '#fff'], + ['#009688', '#fff'], + ['#cddc39', '#fff'], + ['#ff9800', '#fff'] +]; + +export const ResourceCluster = (props: { uuid: string }) => { + const CLUSTER_ID_LENGTH = 5; + const pos = props.uuid.length > CLUSTER_ID_LENGTH ? props.uuid.indexOf('-') : 5; + const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : ''; + const ci = pos >= CLUSTER_ID_LENGTH ? ((((( + (props.uuid.charCodeAt(0) * props.uuid.charCodeAt(1)) + + props.uuid.charCodeAt(2)) + * props.uuid.charCodeAt(3)) + + props.uuid.charCodeAt(4))) % clusterColors.length) : 0; + return {clusterId}; +}; + +export const ComputeNodeInfo = withResourceData('info', renderNodeInfo); + +export const ComputeNodeDomain = withResourceData('domain', renderCommonData); + +export const ComputeNodeFirstPingAt = withResourceData('firstPingAt', renderCommonDate); + +export const ComputeNodeHostname = withResourceData('hostname', renderCommonData); + +export const ComputeNodeIpAddress = withResourceData('ipAddress', renderCommonData); + +export const ComputeNodeJobUuid = withResourceData('jobUuid', renderCommonData); + +export const ComputeNodeLastPingAt = withResourceData('lastPingAt', renderCommonDate); + +// Links Resources +const renderLinkName = (item: { name: string }) => + {item.name || '(none)'}; + +export const ResourceLinkName = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + return resource || { name: '' }; + })(renderLinkName); + +const renderLinkClass = (item: { linkClass: string }) => + {item.linkClass}; + +export const ResourceLinkClass = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + return resource || { linkClass: '' }; + })(renderLinkClass); + +const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => { + const currentLabel = resourceLabel(item.tailKind); + const isUnknow = currentLabel === "Unknown"; + return (
+ {!isUnknow ? ( + renderLink(dispatch, item.tailUuid, currentLabel) + ) : ( + + {item.tailUuid} + + )} +
); +}; + +const renderLink = (dispatch: Dispatch, uuid: string, label: string) => + dispatch(navigateTo(uuid))}> + {label}: {uuid} + ; + +export const ResourceLinkTail = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + return { + item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE } + }; + })((props: { item: any } & DispatchProp) => + renderLinkTail(props.dispatch, props.item)); + +const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) => + renderLink(dispatch, item.headUuid, resourceLabel(item.headKind)); + +export const ResourceLinkHead = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + return { + item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE } + }; + })((props: { item: any } & DispatchProp) => + renderLinkHead(props.dispatch, props.item)); + +export const ResourceLinkUuid = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + return resource || { uuid: '' }; + })(renderUuid); + +// Process Resources const resourceRunProcess = (dispatch: Dispatch, uuid: string) => { return (
@@ -211,9 +366,9 @@ export const ResourceRunProcess = connect( const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => { if (ownerUuid === getPublicUuid(uuidPrefix)) { - return renderStatus(ResourceStatus.PUBLIC); + return renderStatus(WorkflowStatus.PUBLIC); } else { - return renderStatus(ResourceStatus.PRIVATE); + return renderStatus(WorkflowStatus.PRIVATE); } }; @@ -236,6 +391,12 @@ export const ResourceLastModifiedDate = connect( return { date: resource ? resource.modifiedAt : '' }; })((props: { date: string }) => renderDate(props.date)); +export const ResourceCreatedAtDate = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + return { date: resource ? resource.createdAt : '' }; + })((props: { date: string }) => renderDate(props.date)); + export const ResourceTrashDate = connect( (state: RootState, props: { uuid: string }) => { const resource = getResource(props.uuid)(state.resources); @@ -255,12 +416,12 @@ export const renderFileSize = (fileSize?: number) => export const ResourceFileSize = connect( (state: RootState, props: { uuid: string }) => { - const resource = getResourceData(props.uuid)(state.resourcesData); - return { fileSize: resource ? resource.fileSize : 0 }; + const resource = getResource(props.uuid)(state.resources); + return { fileSize: resource ? resource.fileSizeTotal : 0 }; })((props: { fileSize?: number }) => renderFileSize(props.fileSize)); const renderOwner = (owner: string) => - + {owner} ; @@ -270,16 +431,118 @@ export const ResourceOwner = connect( return { owner: resource ? resource.ownerUuid : '' }; })((props: { owner: string }) => renderOwner(props.owner)); -const renderType = (type: string) => +export const ResourceOwnerName = connect( + (state: RootState, props: { uuid: string }) => { + const resource = getResource(props.uuid)(state.resources); + const ownerNameState = state.ownerName; + const ownerName = ownerNameState.find(it => it.uuid === resource!.ownerUuid); + return { owner: ownerName ? ownerName!.name : resource!.ownerUuid }; + })((props: { owner: string }) => renderOwner(props.owner)); + +export const ResourceOwnerWithName = + compose( + connect( + (state: RootState, props: { uuid: string }) => { + let ownerName = ''; + const resource = getResource(props.uuid)(state.resources); + + if (resource) { + ownerName = getUserFullname(resource as User) || (resource as GroupContentsResource).name; + } + + return { uuid: props.uuid, ownerName }; + }), + withStyles({}, { withTheme: true })) + ((props: { uuid: string, ownerName: string, dispatch: Dispatch, theme: ArvadosTheme }) => { + const { uuid, ownerName, dispatch, theme } = props; + + if (ownerName === '') { + dispatch(loadResource(uuid, false)); + return + {uuid} + ; + } + + return + {ownerName} ({uuid}) + ; + }); + +export const ResponsiblePerson = + compose( + connect( + (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => { + let responsiblePersonName = null; + let responsiblePersonUUID = null; + let responsiblePersonProperty = null; + + if (state.auth.config.clusterConfig.Collections.ManagedProperties) { + if (state.auth.config.clusterConfig.Collections.ManagedProperties.responsible_person_uuid) { + responsiblePersonProperty = state.auth.config.clusterConfig.Collections.ManagedProperties.responsible_person_uuid.Function; + } + } + + let resource: Resource | undefined = getResource(props.uuid)(state.resources); + + while (resource && resource.kind !== ResourceKind.USER && resource.kind === ResourceKind.COLLECTION && responsiblePersonProperty) { + responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty]; + resource = getResource(responsiblePersonUUID)(state.resources); + } + + if (resource && resource.kind === ResourceKind.USER) { + responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name; + } + + return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef }; + }), + withStyles({}, { withTheme: true })) + ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => { + const { uuid, responsiblePersonName, parentRef, theme } = props; + + if (!uuid && parentRef) { + parentRef.style.display = 'none'; + return null; + } else if (parentRef) { + parentRef.style.display = 'block'; + } + + if (responsiblePersonName === '') { + return + {uuid} + ; + } + + return + {responsiblePersonName} ({uuid}) + ; + }); + +const renderType = (type: string, subtype: string) => - {resourceLabel(type)} + {resourceLabel(type, subtype)} ; export const ResourceType = connect( (state: RootState, props: { uuid: string }) => { const resource = getResource(props.uuid)(state.resources); - return { type: resource ? resource.kind : '' }; - })((props: { type: string }) => renderType(props.type)); + return { type: resource ? resource.kind : '', subtype: resource && resource.kind === ResourceKind.GROUP ? resource.groupClass : '' }; + })((props: { type: string, subtype: string }) => renderType(props.type, props.subtype)); + +export const ResourceStatus = connect((state: RootState, props: { uuid: string }) => { + return { resource: getResource(props.uuid)(state.resources) }; +})((props: { resource: GroupContentsResource }) => + (props.resource && props.resource.kind === ResourceKind.COLLECTION) + ? + : +); + +export const CollectionStatus = connect((state: RootState, props: { uuid: string }) => { + return { collection: getResource(props.uuid)(state.resources) }; +})((props: { collection: CollectionResource }) => + (props.collection.uuid !== props.collection.currentVersionUuid) + ? version {props.collection.version} + : head version +); export const ProcessStatus = compose( connect((state: RootState, props: { uuid: string }) => { @@ -290,8 +553,57 @@ export const ProcessStatus = compose( const status = props.process ? getProcessStatus(props.process) : "-"; return {status} ; }); + +export const ProcessStartDate = connect( + (state: RootState, props: { uuid: string }) => { + const process = getProcess(props.uuid)(state.resources); + return { date: (process && process.container) ? process.container.startedAt : '' }; + })((props: { date: string }) => renderDate(props.date)); + +export const renderRunTime = (time: number) => + + {formatTime(time, true)} + ; + +interface ContainerRunTimeProps { + process: Process; +} + +interface ContainerRunTimeState { + runtime: number; +} + +export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => { + return { process: getProcess(props.uuid)(state.resources) }; +})(class extends React.Component { + private timer: any; + + constructor(props: ContainerRunTimeProps) { + super(props); + this.state = { runtime: this.getRuntime() }; + } + + getRuntime() { + return this.props.process ? getProcessRuntime(this.props.process) : 0; + } + + updateRuntime() { + this.setState({ runtime: this.getRuntime() }); + } + + componentDidMount() { + this.timer = setInterval(this.updateRuntime.bind(this), 5000); + } + + componentWillUnmount() { + clearInterval(this.timer); + } + + render() { + return renderRunTime(this.state.runtime); + } +});