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 { withResourceData } from '~/views-components/data-explorer/with-resources';
29 import { PublicFavorite } from '~/views-components/public-favorite-icon/public-favorite-icon';
31 const renderName = (item: { name: string; uuid: string, kind: string }) =>
32 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
37 <Typography color="primary" style={{ width: 'auto' }}>
42 <Typography variant="caption">
43 <FavoriteStar resourceUuid={item.uuid} />
47 <Typography variant="caption">
48 <PublicFavorite resourceUuid={item.uuid} />
53 export const ResourceName = connect(
54 (state: RootState, props: { uuid: string }) => {
55 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
56 return resource || { name: '', uuid: '', kind: '' };
59 const renderIcon = (item: { kind: string }) => {
61 case ResourceKind.PROJECT:
62 return <ProjectIcon />;
63 case ResourceKind.COLLECTION:
64 return <CollectionIcon />;
65 case ResourceKind.PROCESS:
66 return <ProcessIcon />;
67 case ResourceKind.WORKFLOW:
68 return <WorkflowIcon />;
70 return <DefaultIcon />;
74 const renderDate = (date?: string) => {
75 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
78 const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
79 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
84 <Typography color="primary" style={{ width: '100px' }}>
90 export const ResourceWorkflowName = connect(
91 (state: RootState, props: { uuid: string }) => {
92 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
93 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
94 })(renderWorkflowName);
96 const getPublicUuid = (uuidPrefix: string) => {
97 return `${uuidPrefix}-tpzed-anonymouspublic`;
100 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
101 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
104 {!isPublic && uuid &&
105 <Tooltip title="Share">
106 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
115 export const ResourceShare = connect(
116 (state: RootState, props: { uuid: string }) => {
117 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
118 const uuidPrefix = getUuidPrefix(state);
120 uuid: resource ? resource.uuid : '',
121 ownerUuid: resource ? resource.ownerUuid : '',
124 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
125 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
127 const renderFirstName = (item: { firstName: string }) => {
128 return <Typography noWrap>{item.firstName}</Typography>;
132 export const ResourceFirstName = connect(
133 (state: RootState, props: { uuid: string }) => {
134 const resource = getResource<UserResource>(props.uuid)(state.resources);
135 return resource || { firstName: '' };
138 const renderLastName = (item: { lastName: string }) =>
139 <Typography noWrap>{item.lastName}</Typography>;
141 export const ResourceLastName = connect(
142 (state: RootState, props: { uuid: string }) => {
143 const resource = getResource<UserResource>(props.uuid)(state.resources);
144 return resource || { lastName: '' };
147 const renderUuid = (item: { uuid: string }) =>
148 <Typography noWrap>{item.uuid}</Typography>;
150 export const ResourceUuid = connect(
151 (state: RootState, props: { uuid: string }) => {
152 const resource = getResource<UserResource>(props.uuid)(state.resources);
153 return resource || { uuid: '' };
156 const renderEmail = (item: { email: string }) =>
157 <Typography noWrap>{item.email}</Typography>;
159 export const ResourceEmail = connect(
160 (state: RootState, props: { uuid: string }) => {
161 const resource = getResource<UserResource>(props.uuid)(state.resources);
162 return resource || { email: '' };
165 const renderIsActive = (props: { uuid: string, isActive: boolean, toggleIsActive: (uuid: string) => void }) =>
168 checked={props.isActive}
169 onClick={() => props.toggleIsActive(props.uuid)} />;
171 export const ResourceIsActive = connect(
172 (state: RootState, props: { uuid: string }) => {
173 const resource = getResource<UserResource>(props.uuid)(state.resources);
174 return resource || { isActive: false };
175 }, { toggleIsActive }
178 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
181 checked={props.isAdmin}
182 onClick={() => props.toggleIsAdmin(props.uuid)} />;
184 export const ResourceIsAdmin = connect(
185 (state: RootState, props: { uuid: string }) => {
186 const resource = getResource<UserResource>(props.uuid)(state.resources);
187 return resource || { isAdmin: false };
191 const renderUsername = (item: { username: string }) =>
192 <Typography noWrap>{item.username}</Typography>;
194 export const ResourceUsername = connect(
195 (state: RootState, props: { uuid: string }) => {
196 const resource = getResource<UserResource>(props.uuid)(state.resources);
197 return resource || { username: '' };
201 const renderCommonData = (data: string) =>
202 <Typography noWrap>{data}</Typography>;
204 const renderCommonDate = (date: string) =>
205 <Typography noWrap>{formatDate(date)}</Typography>;
207 export const CommonUuid = withResourceData('uuid', renderCommonData);
209 // Api Client Authorizations
210 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
212 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
214 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
216 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
218 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
220 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
222 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
224 export const TokenScopes = withResourceData('scopes', renderCommonData);
226 export const TokenUserId = withResourceData('userId', renderCommonData);
228 // Compute Node Resources
229 const renderNodeInfo = (data: string) => {
230 return <Typography>{JSON.stringify(data, null, 4)}</Typography>;
233 const clusterColors = [
241 export const ResourceCluster = (props: { uuid: string }) => {
242 const CLUSTER_ID_LENGTH = 5;
243 const pos = props.uuid.indexOf('-');
244 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
245 const ci = pos >= CLUSTER_ID_LENGTH ? (props.uuid.charCodeAt(0) + props.uuid.charCodeAt(1)) % clusterColors.length : 0;
248 backgroundColor: clusterColors[ci][0],
249 color: clusterColors[ci][1],
256 export const ComputeNodeInfo = withResourceData('info', renderNodeInfo);
258 export const ComputeNodeDomain = withResourceData('domain', renderCommonData);
260 export const ComputeNodeFirstPingAt = withResourceData('firstPingAt', renderCommonDate);
262 export const ComputeNodeHostname = withResourceData('hostname', renderCommonData);
264 export const ComputeNodeIpAddress = withResourceData('ipAddress', renderCommonData);
266 export const ComputeNodeJobUuid = withResourceData('jobUuid', renderCommonData);
268 export const ComputeNodeLastPingAt = withResourceData('lastPingAt', renderCommonDate);
271 const renderLinkName = (item: { name: string }) =>
272 <Typography noWrap>{item.name || '(none)'}</Typography>;
274 export const ResourceLinkName = connect(
275 (state: RootState, props: { uuid: string }) => {
276 const resource = getResource<LinkResource>(props.uuid)(state.resources);
277 return resource || { name: '' };
280 const renderLinkClass = (item: { linkClass: string }) =>
281 <Typography noWrap>{item.linkClass}</Typography>;
283 export const ResourceLinkClass = connect(
284 (state: RootState, props: { uuid: string }) => {
285 const resource = getResource<LinkResource>(props.uuid)(state.resources);
286 return resource || { linkClass: '' };
289 const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
290 const currentLabel = resourceLabel(item.tailKind);
291 const isUnknow = currentLabel === "Unknown";
294 renderLink(dispatch, item.tailUuid, currentLabel)
296 <Typography noWrap color="default">
303 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
304 <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
308 export const ResourceLinkTail = connect(
309 (state: RootState, props: { uuid: string }) => {
310 const resource = getResource<LinkResource>(props.uuid)(state.resources);
312 item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
314 })((props: { item: any } & DispatchProp<any>) =>
315 renderLinkTail(props.dispatch, props.item));
317 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
318 renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
320 export const ResourceLinkHead = connect(
321 (state: RootState, props: { uuid: string }) => {
322 const resource = getResource<LinkResource>(props.uuid)(state.resources);
324 item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
326 })((props: { item: any } & DispatchProp<any>) =>
327 renderLinkHead(props.dispatch, props.item));
329 export const ResourceLinkUuid = connect(
330 (state: RootState, props: { uuid: string }) => {
331 const resource = getResource<LinkResource>(props.uuid)(state.resources);
332 return resource || { uuid: '' };
336 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
340 <Tooltip title="Run process">
341 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
349 export const ResourceRunProcess = connect(
350 (state: RootState, props: { uuid: string }) => {
351 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
353 uuid: resource ? resource.uuid : ''
355 })((props: { uuid: string } & DispatchProp<any>) =>
356 resourceRunProcess(props.dispatch, props.uuid));
358 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
359 if (ownerUuid === getPublicUuid(uuidPrefix)) {
360 return renderStatus(ResourceStatus.PUBLIC);
362 return renderStatus(ResourceStatus.PRIVATE);
366 const renderStatus = (status: string) =>
367 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
369 export const ResourceWorkflowStatus = connect(
370 (state: RootState, props: { uuid: string }) => {
371 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
372 const uuidPrefix = getUuidPrefix(state);
374 ownerUuid: resource ? resource.ownerUuid : '',
377 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
379 export const ResourceLastModifiedDate = connect(
380 (state: RootState, props: { uuid: string }) => {
381 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
382 return { date: resource ? resource.modifiedAt : '' };
383 })((props: { date: string }) => renderDate(props.date));
385 export const ResourceTrashDate = connect(
386 (state: RootState, props: { uuid: string }) => {
387 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
388 return { date: resource ? resource.trashAt : '' };
389 })((props: { date: string }) => renderDate(props.date));
391 export const ResourceDeleteDate = connect(
392 (state: RootState, props: { uuid: string }) => {
393 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
394 return { date: resource ? resource.deleteAt : '' };
395 })((props: { date: string }) => renderDate(props.date));
397 export const renderFileSize = (fileSize?: number) =>
398 <Typography noWrap style={{ minWidth: '45px' }}>
399 {formatFileSize(fileSize)}
402 export const ResourceFileSize = connect(
403 (state: RootState, props: { uuid: string }) => {
404 const resource = getResourceData(props.uuid)(state.resourcesData);
405 return { fileSize: resource ? resource.fileSize : 0 };
406 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
408 const renderOwner = (owner: string) =>
409 <Typography noWrap color="primary" >
413 export const ResourceOwner = connect(
414 (state: RootState, props: { uuid: string }) => {
415 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
416 return { owner: resource ? resource.ownerUuid : '' };
417 })((props: { owner: string }) => renderOwner(props.owner));
419 const renderType = (type: string) =>
421 {resourceLabel(type)}
424 export const ResourceType = connect(
425 (state: RootState, props: { uuid: string }) => {
426 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
427 return { type: resource ? resource.kind : '' };
428 })((props: { type: string }) => renderType(props.type));
430 export const ProcessStatus = compose(
431 connect((state: RootState, props: { uuid: string }) => {
432 return { process: getProcess(props.uuid)(state.resources) };
434 withStyles({}, { withTheme: true }))
435 ((props: { process?: Process, theme: ArvadosTheme }) => {
436 const status = props.process ? getProcessStatus(props.process) : "-";
440 style={{ color: getProcessStatusColor(status, props.theme) }} >