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';
22 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
23 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
28 <Typography color="primary" style={{ width: '450px' }}>
33 <Typography variant="caption">
34 <FavoriteStar resourceUuid={item.uuid} />
39 export const ResourceName = connect(
40 (state: RootState, props: { uuid: string }) => {
41 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
42 return resource || { name: '', uuid: '', kind: '' };
45 export const renderIcon = (item: { kind: string }) => {
47 case ResourceKind.PROJECT:
48 return <ProjectIcon />;
49 case ResourceKind.COLLECTION:
50 return <CollectionIcon />;
51 case ResourceKind.PROCESS:
52 return <ProcessIcon />;
53 case ResourceKind.WORKFLOW:
54 return <WorkflowIcon />;
56 return <DefaultIcon />;
60 export const renderDate = (date?: string) => {
61 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
64 export const PublicUuid = 'qr1hi-tpzed-anonymouspublic';
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);
85 export const resourceShare = (props: { ownerUuid: string }) => {
86 return <Tooltip title="Share">
87 <IconButton onClick={() => undefined}>
88 {props.ownerUuid === PublicUuid ? <ShareIcon /> : null}
93 export const ResourceShare = connect(
94 (state: RootState, props: { uuid: string }) => {
95 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
96 return resource || { ownerUuid: '' };
99 export const renderWorkflowStatus = (ownerUuid?: string) => {
100 if (ownerUuid === PublicUuid) {
101 return renderStatus(ResourceStatus.PUBLIC);
103 return renderStatus(ResourceStatus.PRIVATE);
107 const renderStatus = (status: string) =>
108 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
110 export const ResourceWorkflowStatus = connect(
111 (state: RootState, props: { uuid: string }) => {
112 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
113 return { ownerUuid: resource ? resource.ownerUuid : '' };
114 })((props: { ownerUuid?: string }) => renderWorkflowStatus(props.ownerUuid));
116 export const ResourceLastModifiedDate = connect(
117 (state: RootState, props: { uuid: string }) => {
118 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
119 return { date: resource ? resource.modifiedAt : '' };
120 })((props: { date: string }) => renderDate(props.date));
122 export const ResourceTrashDate = connect(
123 (state: RootState, props: { uuid: string }) => {
124 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
125 return { date: resource ? resource.trashAt : '' };
126 })((props: { date: string }) => renderDate(props.date));
128 export const ResourceDeleteDate = connect(
129 (state: RootState, props: { uuid: string }) => {
130 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
131 return { date: resource ? resource.deleteAt : '' };
132 })((props: { date: string }) => renderDate(props.date));
134 export const renderFileSize = (fileSize?: number) =>
135 <Typography noWrap style={{ minWidth: '45px' }}>
136 {formatFileSize(fileSize)}
139 export const ResourceFileSize = connect(
140 (state: RootState, props: { uuid: string }) => {
141 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
143 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
145 export const renderOwner = (owner: string) =>
146 <Typography noWrap color="primary" >
150 export const ResourceOwner = connect(
151 (state: RootState, props: { uuid: string }) => {
152 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
153 return { owner: resource ? resource.ownerUuid : '' };
154 })((props: { owner: string }) => renderOwner(props.owner));
156 export const renderType = (type: string) =>
158 {resourceLabel(type)}
161 export const ResourceType = connect(
162 (state: RootState, props: { uuid: string }) => {
163 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
164 return { type: resource ? resource.kind : '' };
165 })((props: { type: string }) => renderType(props.type));
167 export const ProcessStatus = compose(
168 connect((state: RootState, props: { uuid: string }) => {
169 return { process: getProcess(props.uuid)(state.resources) };
171 withStyles({}, { withTheme: true }))
172 ((props: { process?: Process, theme: ArvadosTheme }) => {
173 const status = props.process ? getProcessStatus(props.process) : "-";
177 style={{ color: getProcessStatusColor(status, props.theme) }} >