1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Grid, Typography, withStyles, Tooltip, IconButton } from '@material-ui/core';
7 import { FavoriteStar } from '../favorite-star/favorite-star';
8 import { ResourceKind, TrashableResource } from '~/models/resource';
9 import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, WorkflowIcon, ShareIcon } from '~/components/icon/icon';
10 import { formatDate, formatFileSize } from '~/common/formatters';
11 import { resourceLabel } from '~/common/labels';
12 import { connect } from 'react-redux';
13 import { RootState } from '~/store/store';
14 import { getResource } from '~/store/resources/resources';
15 import { GroupContentsResource } from '~/services/groups-service/groups-service';
16 import { getProcess, Process, getProcessStatus, getProcessStatusColor } from '~/store/processes/process';
17 import { ArvadosTheme } from '~/common/custom-theme';
18 import { compose } from 'redux';
19 import { WorkflowResource } from '~/models/workflow';
20 import { ResourceStatus } from '~/views/workflow-panel/workflow-panel-view';
21 import { getUuidPrefix } from '~/store/workflow-panel/workflow-panel-actions';
22 import { CollectionResource } from "~/models/collection";
23 import { getResourceData } from "~/store/resources-data/resources-data";
25 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
26 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
31 <Typography color="primary" style={{ width: '450px' }}>
36 <Typography variant="caption">
37 <FavoriteStar resourceUuid={item.uuid} />
42 export const ResourceName = connect(
43 (state: RootState, props: { uuid: string }) => {
44 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
45 return resource || { name: '', uuid: '', kind: '' };
48 export const renderIcon = (item: { kind: string }) => {
50 case ResourceKind.PROJECT:
51 return <ProjectIcon />;
52 case ResourceKind.COLLECTION:
53 return <CollectionIcon />;
54 case ResourceKind.PROCESS:
55 return <ProcessIcon />;
56 case ResourceKind.WORKFLOW:
57 return <WorkflowIcon />;
59 return <DefaultIcon />;
63 export const renderDate = (date?: string) => {
64 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
67 export const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
68 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
73 <Typography color="primary" style={{ width: '100px' }}>
79 export const RosurceWorkflowName = connect(
80 (state: RootState, props: { uuid: string }) => {
81 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
82 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
83 })(renderWorkflowName);
85 const getPublicUuid = (uuidPrefix: string) => {
86 return `${uuidPrefix}-tpzed-anonymouspublic`;
90 export const resourceShare = (uuidPrefix: string, ownerUuid?: string) => {
91 return <Tooltip title="Share">
92 <IconButton onClick={() => undefined}>
93 {ownerUuid === getPublicUuid(uuidPrefix) ? <ShareIcon /> : null}
98 export const ResourceShare = connect(
99 (state: RootState, props: { uuid: string }) => {
100 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
101 const uuidPrefix = getUuidPrefix(state);
103 ownerUuid: resource ? resource.ownerUuid : '',
106 })((props: { ownerUuid?: string, uuidPrefix: string }) => resourceShare(props.uuidPrefix, props.ownerUuid));
108 export const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
109 if (ownerUuid === getPublicUuid(uuidPrefix)) {
110 return renderStatus(ResourceStatus.PUBLIC);
112 return renderStatus(ResourceStatus.PRIVATE);
116 const renderStatus = (status: string) =>
117 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
119 export const ResourceWorkflowStatus = connect(
120 (state: RootState, props: { uuid: string }) => {
121 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
122 const uuidPrefix = getUuidPrefix(state);
124 ownerUuid: resource ? resource.ownerUuid : '',
127 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
129 export const ResourceLastModifiedDate = connect(
130 (state: RootState, props: { uuid: string }) => {
131 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
132 return { date: resource ? resource.modifiedAt : '' };
133 })((props: { date: string }) => renderDate(props.date));
135 export const ResourceTrashDate = connect(
136 (state: RootState, props: { uuid: string }) => {
137 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
138 return { date: resource ? resource.trashAt : '' };
139 })((props: { date: string }) => renderDate(props.date));
141 export const ResourceDeleteDate = connect(
142 (state: RootState, props: { uuid: string }) => {
143 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
144 return { date: resource ? resource.deleteAt : '' };
145 })((props: { date: string }) => renderDate(props.date));
147 export const renderFileSize = (fileSize?: number) =>
148 <Typography noWrap style={{ minWidth: '45px' }}>
149 {formatFileSize(fileSize)}
152 export const ResourceFileSize = connect(
153 (state: RootState, props: { uuid: string }) => {
154 const resource = getResourceData(props.uuid)(state.resourcesData);
155 return { fileSize: resource ? resource.fileSize : 0 };
156 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
158 export const renderOwner = (owner: string) =>
159 <Typography noWrap color="primary" >
163 export const ResourceOwner = connect(
164 (state: RootState, props: { uuid: string }) => {
165 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
166 return { owner: resource ? resource.ownerUuid : '' };
167 })((props: { owner: string }) => renderOwner(props.owner));
169 export const renderType = (type: string) =>
171 {resourceLabel(type)}
174 export const ResourceType = connect(
175 (state: RootState, props: { uuid: string }) => {
176 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
177 return { type: resource ? resource.kind : '' };
178 })((props: { type: string }) => renderType(props.type));
180 export const ProcessStatus = compose(
181 connect((state: RootState, props: { uuid: string }) => {
182 return { process: getProcess(props.uuid)(state.resources) };
184 withStyles({}, { withTheme: true }))
185 ((props: { process?: Process, theme: ArvadosTheme }) => {
186 const status = props.process ? getProcessStatus(props.process) : "-";
190 style={{ color: getProcessStatusColor(status, props.theme) }} >