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";
24 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
25 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
30 <Typography color="primary" style={{ width: '450px' }}>
35 <Typography variant="caption">
36 <FavoriteStar resourceUuid={item.uuid} />
41 export const ResourceName = connect(
42 (state: RootState, props: { uuid: string }) => {
43 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
44 return resource || { name: '', uuid: '', kind: '' };
47 export const renderIcon = (item: { kind: string }) => {
49 case ResourceKind.PROJECT:
50 return <ProjectIcon />;
51 case ResourceKind.COLLECTION:
52 return <CollectionIcon />;
53 case ResourceKind.PROCESS:
54 return <ProcessIcon />;
55 case ResourceKind.WORKFLOW:
56 return <WorkflowIcon />;
58 return <DefaultIcon />;
62 export const renderDate = (date?: string) => {
63 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
66 export const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
67 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
72 <Typography color="primary" style={{ width: '100px' }}>
78 export const RosurceWorkflowName = connect(
79 (state: RootState, props: { uuid: string }) => {
80 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
81 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
82 })(renderWorkflowName);
84 const getPublicUuid = (uuidPrefix: string) => {
85 return `${uuidPrefix}-tpzed-anonymouspublic`;
89 export const resourceShare = (uuidPrefix: string, ownerUuid?: string) => {
90 return <Tooltip title="Share">
91 <IconButton onClick={() => undefined}>
92 {ownerUuid === getPublicUuid(uuidPrefix) ? <ShareIcon /> : null}
97 export const ResourceShare = connect(
98 (state: RootState, props: { uuid: string }) => {
99 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
100 const uuidPrefix = getUuidPrefix(state);
102 ownerUuid: resource ? resource.ownerUuid : '',
105 })((props: { ownerUuid?: string, uuidPrefix: string }) => resourceShare(props.uuidPrefix, props.ownerUuid));
107 export const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
108 if (ownerUuid === getPublicUuid(uuidPrefix)) {
109 return renderStatus(ResourceStatus.PUBLIC);
111 return renderStatus(ResourceStatus.PRIVATE);
115 const renderStatus = (status: string) =>
116 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
118 export const ResourceWorkflowStatus = connect(
119 (state: RootState, props: { uuid: string }) => {
120 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
121 const uuidPrefix = getUuidPrefix(state);
123 ownerUuid: resource ? resource.ownerUuid : '',
126 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
128 export const ResourceLastModifiedDate = connect(
129 (state: RootState, props: { uuid: string }) => {
130 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
131 return { date: resource ? resource.modifiedAt : '' };
132 })((props: { date: string }) => renderDate(props.date));
134 export const ResourceTrashDate = connect(
135 (state: RootState, props: { uuid: string }) => {
136 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
137 return { date: resource ? resource.trashAt : '' };
138 })((props: { date: string }) => renderDate(props.date));
140 export const ResourceDeleteDate = connect(
141 (state: RootState, props: { uuid: string }) => {
142 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
143 return { date: resource ? resource.deleteAt : '' };
144 })((props: { date: string }) => renderDate(props.date));
146 export const renderFileSize = (fileSize?: number) =>
147 <Typography noWrap style={{ minWidth: '45px' }}>
148 {formatFileSize(fileSize)}
151 export const ResourceFileSize = connect(
152 (state: RootState, props: { uuid: string }) => {
153 const resource = getResource<CollectionResource>(props.uuid)(state.resources);
154 return { fileSize: resource ? resource.fileSize : 0 };
155 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
157 export const renderOwner = (owner: string) =>
158 <Typography noWrap color="primary" >
162 export const ResourceOwner = connect(
163 (state: RootState, props: { uuid: string }) => {
164 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
165 return { owner: resource ? resource.ownerUuid : '' };
166 })((props: { owner: string }) => renderOwner(props.owner));
168 export const renderType = (type: string) =>
170 {resourceLabel(type)}
173 export const ResourceType = connect(
174 (state: RootState, props: { uuid: string }) => {
175 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
176 return { type: resource ? resource.kind : '' };
177 })((props: { type: string }) => renderType(props.type));
179 export const ProcessStatus = compose(
180 connect((state: RootState, props: { uuid: string }) => {
181 return { process: getProcess(props.uuid)(state.resources) };
183 withStyles({}, { withTheme: true }))
184 ((props: { process?: Process, theme: ArvadosTheme }) => {
185 const status = props.process ? getProcessStatus(props.process) : "-";
189 style={{ color: getProcessStatusColor(status, props.theme) }} >