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, DispatchProp } 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, Dispatch } 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";
24 import { openSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
26 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
27 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
32 <Typography color="primary" style={{ width: '450px' }}>
37 <Typography variant="caption">
38 <FavoriteStar resourceUuid={item.uuid} />
43 export const ResourceName = connect(
44 (state: RootState, props: { uuid: string }) => {
45 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
46 return resource || { name: '', uuid: '', kind: '' };
49 export const renderIcon = (item: { kind: string }) => {
51 case ResourceKind.PROJECT:
52 return <ProjectIcon />;
53 case ResourceKind.COLLECTION:
54 return <CollectionIcon />;
55 case ResourceKind.PROCESS:
56 return <ProcessIcon />;
57 case ResourceKind.WORKFLOW:
58 return <WorkflowIcon />;
60 return <DefaultIcon />;
64 export const renderDate = (date?: string) => {
65 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
68 export const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
69 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
74 <Typography color="primary" style={{ width: '100px' }}>
80 export const RosurceWorkflowName = connect(
81 (state: RootState, props: { uuid: string }) => {
82 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
83 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
84 })(renderWorkflowName);
86 const getPublicUuid = (uuidPrefix: string) => {
87 return `${uuidPrefix}-tpzed-anonymouspublic`;
90 // ToDo: share onClick
91 export const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
92 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
96 <Tooltip title="Share">
97 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
106 export const ResourceShare = connect(
107 (state: RootState, props: { uuid: string }) => {
108 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
109 const uuidPrefix = getUuidPrefix(state);
111 uuid: resource ? resource.uuid : '',
112 ownerUuid: resource ? resource.ownerUuid : '',
115 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
116 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
118 export const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
119 if (ownerUuid === getPublicUuid(uuidPrefix)) {
120 return renderStatus(ResourceStatus.PUBLIC);
122 return renderStatus(ResourceStatus.PRIVATE);
126 const renderStatus = (status: string) =>
127 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
129 export const ResourceWorkflowStatus = connect(
130 (state: RootState, props: { uuid: string }) => {
131 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
132 const uuidPrefix = getUuidPrefix(state);
134 ownerUuid: resource ? resource.ownerUuid : '',
137 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
139 export const ResourceLastModifiedDate = connect(
140 (state: RootState, props: { uuid: string }) => {
141 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
142 return { date: resource ? resource.modifiedAt : '' };
143 })((props: { date: string }) => renderDate(props.date));
145 export const ResourceTrashDate = connect(
146 (state: RootState, props: { uuid: string }) => {
147 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
148 return { date: resource ? resource.trashAt : '' };
149 })((props: { date: string }) => renderDate(props.date));
151 export const ResourceDeleteDate = connect(
152 (state: RootState, props: { uuid: string }) => {
153 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
154 return { date: resource ? resource.deleteAt : '' };
155 })((props: { date: string }) => renderDate(props.date));
157 export const renderFileSize = (fileSize?: number) =>
158 <Typography noWrap style={{ minWidth: '45px' }}>
159 {formatFileSize(fileSize)}
162 export const ResourceFileSize = connect(
163 (state: RootState, props: { uuid: string }) => {
164 const resource = getResourceData(props.uuid)(state.resourcesData);
165 return { fileSize: resource ? resource.fileSize : 0 };
166 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
168 export const renderOwner = (owner: string) =>
169 <Typography noWrap color="primary" >
173 export const ResourceOwner = connect(
174 (state: RootState, props: { uuid: string }) => {
175 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
176 return { owner: resource ? resource.ownerUuid : '' };
177 })((props: { owner: string }) => renderOwner(props.owner));
179 export const renderType = (type: string) =>
181 {resourceLabel(type)}
184 export const ResourceType = connect(
185 (state: RootState, props: { uuid: string }) => {
186 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
187 return { type: resource ? resource.kind : '' };
188 })((props: { type: string }) => renderType(props.type));
190 export const ProcessStatus = compose(
191 connect((state: RootState, props: { uuid: string }) => {
192 return { process: getProcess(props.uuid)(state.resources) };
194 withStyles({}, { withTheme: true }))
195 ((props: { process?: Process, theme: ArvadosTheme }) => {
196 const status = props.process ? getProcessStatus(props.process) : "-";
200 style={{ color: getProcessStatusColor(status, props.theme) }} >