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, Button } 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';
26 import { LinkResource } from '~/models/link';
27 import { navigateTo } from '~/store/navigation/navigation-action';
28 import { Link } from 'react-router-dom';
29 import { NodeResource } from '../../models/node';
30 import { NodeInfo } from '~/models/node';
32 const renderName = (item: { name: string; uuid: string, kind: string }) =>
33 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
38 <Typography color="primary" style={{ width: '450px' }}>
43 <Typography variant="caption">
44 <FavoriteStar resourceUuid={item.uuid} />
49 export const ResourceName = connect(
50 (state: RootState, props: { uuid: string }) => {
51 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
52 return resource || { name: '', uuid: '', kind: '' };
55 const renderIcon = (item: { kind: string }) => {
57 case ResourceKind.PROJECT:
58 return <ProjectIcon />;
59 case ResourceKind.COLLECTION:
60 return <CollectionIcon />;
61 case ResourceKind.PROCESS:
62 return <ProcessIcon />;
63 case ResourceKind.WORKFLOW:
64 return <WorkflowIcon />;
66 return <DefaultIcon />;
70 const renderDate = (date?: string) => {
71 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
74 const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
75 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
80 <Typography color="primary" style={{ width: '100px' }}>
86 export const RosurceWorkflowName = connect(
87 (state: RootState, props: { uuid: string }) => {
88 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
89 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
90 })(renderWorkflowName);
92 const getPublicUuid = (uuidPrefix: string) => {
93 return `${uuidPrefix}-tpzed-anonymouspublic`;
96 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
97 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
100 {!isPublic && uuid &&
101 <Tooltip title="Share">
102 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
111 export const ResourceShare = connect(
112 (state: RootState, props: { uuid: string }) => {
113 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
114 const uuidPrefix = getUuidPrefix(state);
116 uuid: resource ? resource.uuid : '',
117 ownerUuid: resource ? resource.ownerUuid : '',
120 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
121 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
123 const renderFirstName = (item: { firstName: string }) => {
124 return <Typography noWrap>{item.firstName}</Typography>;
128 export const ResourceFirstName = connect(
129 (state: RootState, props: { uuid: string }) => {
130 const resource = getResource<UserResource>(props.uuid)(state.resources);
131 return resource || { firstName: '' };
134 const renderLastName = (item: { lastName: string }) =>
135 <Typography noWrap>{item.lastName}</Typography>;
137 export const ResourceLastName = connect(
138 (state: RootState, props: { uuid: string }) => {
139 const resource = getResource<UserResource>(props.uuid)(state.resources);
140 return resource || { lastName: '' };
143 const renderUuid = (item: { uuid: string }) =>
144 <Typography noWrap>{item.uuid}</Typography>;
146 export const ResourceUuid = connect(
147 (state: RootState, props: { uuid: string }) => {
148 const resource = getResource<UserResource>(props.uuid)(state.resources);
149 return resource || { uuid: '' };
152 const renderEmail = (item: { email: string }) =>
153 <Typography noWrap>{item.email}</Typography>;
155 export const ResourceEmail = connect(
156 (state: RootState, props: { uuid: string }) => {
157 const resource = getResource<UserResource>(props.uuid)(state.resources);
158 return resource || { email: '' };
161 const renderIsActive = (props: { uuid: string, isActive: boolean, toggleIsActive: (uuid: string) => void }) =>
164 checked={props.isActive}
165 onClick={() => props.toggleIsActive(props.uuid)} />;
167 export const ResourceIsActive = connect(
168 (state: RootState, props: { uuid: string }) => {
169 const resource = getResource<UserResource>(props.uuid)(state.resources);
170 return resource || { isActive: false };
171 }, { toggleIsActive }
174 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
177 checked={props.isAdmin}
178 onClick={() => props.toggleIsAdmin(props.uuid)} />;
180 export const ResourceIsAdmin = connect(
181 (state: RootState, props: { uuid: string }) => {
182 const resource = getResource<UserResource>(props.uuid)(state.resources);
183 return resource || { isAdmin: false };
187 const renderUsername = (item: { username: string }) =>
188 <Typography noWrap>{item.username}</Typography>;
190 export const ResourceUsername = connect(
191 (state: RootState, props: { uuid: string }) => {
192 const resource = getResource<UserResource>(props.uuid)(state.resources);
193 return resource || { username: '' };
196 // Compute Node Resources
197 const renderNodeDate = (date?: string) =>
198 <Typography noWrap>{formatDate(date) || '(none)'}</Typography>;
200 const renderNodeData = (property?: string) =>
201 <Typography noWrap>{property || '(none)'}</Typography>;
203 const renderNodeInfo = (item: { info: NodeInfo }) =>
205 {JSON.stringify(item.info, null, 4)}
208 export const ResourceNodeInfo = connect(
209 (state: RootState, props: { uuid: string }) => {
210 const resource = getResource<NodeResource>(props.uuid)(state.resources);
211 return resource || { info: {} };
214 export const ResourceNodeDomain = connect(
215 (state: RootState, props: { uuid: string }) => {
216 const resource = getResource<NodeResource>(props.uuid)(state.resources);
217 return { property: resource ? resource.domain : '' };
218 })((props: { property: string }) => renderNodeData(props.property));
220 export const ResourceNodeFirstPingAt = connect(
221 (state: RootState, props: { uuid: string }) => {
222 const resource = getResource<NodeResource>(props.uuid)(state.resources);
223 return { date: resource ? resource.firstPingAt : '' };
224 })((props: { date: string }) => renderNodeDate(props.date));
226 export const ResourceNodeHostname = connect(
227 (state: RootState, props: { uuid: string }) => {
228 const resource = getResource<NodeResource>(props.uuid)(state.resources);
229 return { property: resource ? resource.hostname : '' };
230 })((props: { property: string }) => renderNodeData(props.property));
232 export const ResourceNodeIpAddress = connect(
233 (state: RootState, props: { uuid: string }) => {
234 const resource = getResource<NodeResource>(props.uuid)(state.resources);
235 return { property: resource ? resource.ipAddress : '' };
236 })((props: { property: string }) => renderNodeData(props.property));
238 export const ResourceNodeJobUuid = connect(
239 (state: RootState, props: { uuid: string }) => {
240 const resource = getResource<NodeResource>(props.uuid)(state.resources);
241 return { property: resource ? resource.jobUuid : '' };
242 })((props: { property: string }) => renderNodeData(props.property));
244 export const ResourceNodeLastPingAt = connect(
245 (state: RootState, props: { uuid: string }) => {
246 const resource = getResource<NodeResource>(props.uuid)(state.resources);
247 return { date: resource ? resource.lastPingAt : '' };
248 })((props: { date: string }) => renderNodeDate(props.date));
251 const renderLinkName = (item: { name: string }) =>
252 <Typography noWrap>{item.name || '(none)'}</Typography>;
254 export const ResourceLinkName = connect(
255 (state: RootState, props: { uuid: string }) => {
256 const resource = getResource<LinkResource>(props.uuid)(state.resources);
257 return resource || { name: '' };
260 const renderLinkClass = (item: { linkClass: string }) =>
261 <Typography noWrap>{item.linkClass}</Typography>;
263 export const ResourceLinkClass = connect(
264 (state: RootState, props: { uuid: string }) => {
265 const resource = getResource<LinkResource>(props.uuid)(state.resources);
266 return resource || { linkClass: '' };
269 const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
270 const currentLabel = resourceLabel(item.tailKind);
271 const isUnknow = currentLabel === "Unknown";
274 renderLink(dispatch, item.tailUuid, currentLabel)
276 <Typography noWrap color="default">
283 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
284 <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
288 export const ResourceLinkTail = connect(
289 (state: RootState, props: { uuid: string }) => {
290 const resource = getResource<LinkResource>(props.uuid)(state.resources);
292 item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
294 })((props: { item: any } & DispatchProp<any>) =>
295 renderLinkTail(props.dispatch, props.item));
297 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
298 renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
300 export const ResourceLinkHead = connect(
301 (state: RootState, props: { uuid: string }) => {
302 const resource = getResource<LinkResource>(props.uuid)(state.resources);
304 item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
306 })((props: { item: any } & DispatchProp<any>) =>
307 renderLinkHead(props.dispatch, props.item));
309 export const ResourceLinkUuid = connect(
310 (state: RootState, props: { uuid: string }) => {
311 const resource = getResource<LinkResource>(props.uuid)(state.resources);
312 return resource || { uuid: '' };
316 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
320 <Tooltip title="Run process">
321 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
329 export const ResourceRunProcess = connect(
330 (state: RootState, props: { uuid: string }) => {
331 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
333 uuid: resource ? resource.uuid : ''
335 })((props: { uuid: string } & DispatchProp<any>) =>
336 resourceRunProcess(props.dispatch, props.uuid));
338 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
339 if (ownerUuid === getPublicUuid(uuidPrefix)) {
340 return renderStatus(ResourceStatus.PUBLIC);
342 return renderStatus(ResourceStatus.PRIVATE);
346 const renderStatus = (status: string) =>
347 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
349 export const ResourceWorkflowStatus = connect(
350 (state: RootState, props: { uuid: string }) => {
351 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
352 const uuidPrefix = getUuidPrefix(state);
354 ownerUuid: resource ? resource.ownerUuid : '',
357 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
359 export const ResourceLastModifiedDate = connect(
360 (state: RootState, props: { uuid: string }) => {
361 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
362 return { date: resource ? resource.modifiedAt : '' };
363 })((props: { date: string }) => renderDate(props.date));
365 export const ResourceTrashDate = connect(
366 (state: RootState, props: { uuid: string }) => {
367 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
368 return { date: resource ? resource.trashAt : '' };
369 })((props: { date: string }) => renderDate(props.date));
371 export const ResourceDeleteDate = connect(
372 (state: RootState, props: { uuid: string }) => {
373 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
374 return { date: resource ? resource.deleteAt : '' };
375 })((props: { date: string }) => renderDate(props.date));
377 export const renderFileSize = (fileSize?: number) =>
378 <Typography noWrap style={{ minWidth: '45px' }}>
379 {formatFileSize(fileSize)}
382 export const ResourceFileSize = connect(
383 (state: RootState, props: { uuid: string }) => {
384 const resource = getResourceData(props.uuid)(state.resourcesData);
385 return { fileSize: resource ? resource.fileSize : 0 };
386 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
388 const renderOwner = (owner: string) =>
389 <Typography noWrap color="primary" >
393 export const ResourceOwner = connect(
394 (state: RootState, props: { uuid: string }) => {
395 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
396 return { owner: resource ? resource.ownerUuid : '' };
397 })((props: { owner: string }) => renderOwner(props.owner));
399 const renderType = (type: string) =>
401 {resourceLabel(type)}
404 export const ResourceType = connect(
405 (state: RootState, props: { uuid: string }) => {
406 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
407 return { type: resource ? resource.kind : '' };
408 })((props: { type: string }) => renderType(props.type));
410 export const ProcessStatus = compose(
411 connect((state: RootState, props: { uuid: string }) => {
412 return { process: getProcess(props.uuid)(state.resources) };
414 withStyles({}, { withTheme: true }))
415 ((props: { process?: Process, theme: ArvadosTheme }) => {
416 const status = props.process ? getProcessStatus(props.process) : "-";
420 style={{ color: getProcessStatusColor(status, props.theme) }} >