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, Checkbox } 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, openRunProcess } from '~/store/workflow-panel/workflow-panel-actions';
22 import { getResourceData } from "~/store/resources-data/resources-data";
23 import { openSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
24 import { UserResource } from '~/models/user';
25 import { toggleIsActive, toggleIsAdmin } from '~/store/users/users-actions';
27 const renderName = (item: { name: string; uuid: string, kind: string }) =>
28 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
33 <Typography color="primary" style={{ width: '450px' }}>
38 <Typography variant="caption">
39 <FavoriteStar resourceUuid={item.uuid} />
44 export const ResourceName = connect(
45 (state: RootState, props: { uuid: string }) => {
46 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
47 return resource || { name: '', uuid: '', kind: '' };
50 const renderIcon = (item: { kind: string }) => {
52 case ResourceKind.PROJECT:
53 return <ProjectIcon />;
54 case ResourceKind.COLLECTION:
55 return <CollectionIcon />;
56 case ResourceKind.PROCESS:
57 return <ProcessIcon />;
58 case ResourceKind.WORKFLOW:
59 return <WorkflowIcon />;
61 return <DefaultIcon />;
65 const renderDate = (date?: string) => {
66 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
69 const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
70 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
75 <Typography color="primary" style={{ width: '100px' }}>
81 export const RosurceWorkflowName = connect(
82 (state: RootState, props: { uuid: string }) => {
83 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
84 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
85 })(renderWorkflowName);
87 const getPublicUuid = (uuidPrefix: string) => {
88 return `${uuidPrefix}-tpzed-anonymouspublic`;
91 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 const renderFirstName = (item: { firstName: string }) => {
119 return <Typography noWrap>{item.firstName}</Typography>;
122 export const ResourceFirstName = connect(
123 (state: RootState, props: { uuid: string }) => {
124 const resource = getResource<UserResource>(props.uuid)(state.resources);
125 return resource || { firstName: '' };
128 const renderLastName = (item: { lastName: string }) =>
129 <Typography noWrap>{item.lastName}</Typography>;
131 export const ResourceLastName = connect(
132 (state: RootState, props: { uuid: string }) => {
133 const resource = getResource<UserResource>(props.uuid)(state.resources);
134 return resource || { lastName: '' };
137 const renderUuid = (item: { uuid: string }) =>
138 <Typography noWrap>{item.uuid}</Typography>;
140 export const ResourceUuid = connect(
141 (state: RootState, props: { uuid: string }) => {
142 const resource = getResource<UserResource>(props.uuid)(state.resources);
143 return resource || { uuid: '' };
146 const renderEmail = (item: { email: string }) =>
147 <Typography noWrap>{item.email}</Typography>;
149 export const ResourceEmail = connect(
150 (state: RootState, props: { uuid: string }) => {
151 const resource = getResource<UserResource>(props.uuid)(state.resources);
152 return resource || { email: '' };
155 const renderIsActive = (props: { uuid: string, isActive: boolean, toggleIsActive: (uuid: string) => void }) =>
158 checked={props.isActive}
159 onClick={() => props.toggleIsActive(props.uuid)} />;
161 export const ResourceIsActive = connect(
162 (state: RootState, props: { uuid: string }) => {
163 const resource = getResource<UserResource>(props.uuid)(state.resources);
164 return resource || { isActive: false };
165 }, { toggleIsActive }
168 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
171 checked={props.isAdmin}
172 onClick={() => props.toggleIsAdmin(props.uuid)} />;
174 export const ResourceIsAdmin = connect(
175 (state: RootState, props: { uuid: string }) => {
176 const resource = getResource<UserResource>(props.uuid)(state.resources);
177 return resource || { isAdmin: false };
181 const renderUsername = (item: { username: string }) =>
182 <Typography noWrap>{item.username}</Typography>;
184 export const ResourceUsername = connect(
185 (state: RootState, props: { uuid: string }) => {
186 const resource = getResource<UserResource>(props.uuid)(state.resources);
187 return resource || { username: '' };
190 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
194 <Tooltip title="Run process">
195 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
203 export const ResourceRunProcess = connect(
204 (state: RootState, props: { uuid: string }) => {
205 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
207 uuid: resource ? resource.uuid : ''
209 })((props: { uuid: string } & DispatchProp<any>) =>
210 resourceRunProcess(props.dispatch, props.uuid));
212 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
213 if (ownerUuid === getPublicUuid(uuidPrefix)) {
214 return renderStatus(ResourceStatus.PUBLIC);
216 return renderStatus(ResourceStatus.PRIVATE);
220 const renderStatus = (status: string) =>
221 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
223 export const ResourceWorkflowStatus = connect(
224 (state: RootState, props: { uuid: string }) => {
225 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
226 const uuidPrefix = getUuidPrefix(state);
228 ownerUuid: resource ? resource.ownerUuid : '',
231 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
233 export const ResourceLastModifiedDate = connect(
234 (state: RootState, props: { uuid: string }) => {
235 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
236 return { date: resource ? resource.modifiedAt : '' };
237 })((props: { date: string }) => renderDate(props.date));
239 export const ResourceTrashDate = connect(
240 (state: RootState, props: { uuid: string }) => {
241 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
242 return { date: resource ? resource.trashAt : '' };
243 })((props: { date: string }) => renderDate(props.date));
245 export const ResourceDeleteDate = connect(
246 (state: RootState, props: { uuid: string }) => {
247 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
248 return { date: resource ? resource.deleteAt : '' };
249 })((props: { date: string }) => renderDate(props.date));
251 export const renderFileSize = (fileSize?: number) =>
252 <Typography noWrap style={{ minWidth: '45px' }}>
253 {formatFileSize(fileSize)}
256 export const ResourceFileSize = connect(
257 (state: RootState, props: { uuid: string }) => {
258 const resource = getResourceData(props.uuid)(state.resourcesData);
259 return { fileSize: resource ? resource.fileSize : 0 };
260 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
262 const renderOwner = (owner: string) =>
263 <Typography noWrap color="primary" >
267 export const ResourceOwner = connect(
268 (state: RootState, props: { uuid: string }) => {
269 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
270 return { owner: resource ? resource.ownerUuid : '' };
271 })((props: { owner: string }) => renderOwner(props.owner));
273 const renderType = (type: string) =>
275 {resourceLabel(type)}
278 export const ResourceType = connect(
279 (state: RootState, props: { uuid: string }) => {
280 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
281 return { type: resource ? resource.kind : '' };
282 })((props: { type: string }) => renderType(props.type));
284 export const ProcessStatus = compose(
285 connect((state: RootState, props: { uuid: string }) => {
286 return { process: getProcess(props.uuid)(state.resources) };
288 withStyles({}, { withTheme: true }))
289 ((props: { process?: Process, theme: ArvadosTheme }) => {
290 const status = props.process ? getProcessStatus(props.process) : "-";
294 style={{ color: getProcessStatusColor(status, props.theme) }} >