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 { withResource, getDataFromResource, withResourceData } from '~/views-components/data-explorer/with-resources';
30 const renderName = (item: { name: string; uuid: string, kind: string }) =>
31 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
36 <Typography color="primary" style={{ width: 'auto' }}>
41 <Typography variant="caption">
42 <FavoriteStar resourceUuid={item.uuid} />
47 export const ResourceName = connect(
48 (state: RootState, props: { uuid: string }) => {
49 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
50 return resource || { name: '', uuid: '', kind: '' };
53 const renderIcon = (item: { kind: string }) => {
55 case ResourceKind.PROJECT:
56 return <ProjectIcon />;
57 case ResourceKind.COLLECTION:
58 return <CollectionIcon />;
59 case ResourceKind.PROCESS:
60 return <ProcessIcon />;
61 case ResourceKind.WORKFLOW:
62 return <WorkflowIcon />;
64 return <DefaultIcon />;
68 const renderDate = (date?: string) => {
69 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
72 const renderWorkflowName = (item: { name: string; uuid: string, kind: string, ownerUuid: string }) =>
73 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
78 <Typography color="primary" style={{ width: '100px' }}>
84 export const ResourceWorkflowName = connect(
85 (state: RootState, props: { uuid: string }) => {
86 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
87 return resource || { name: '', uuid: '', kind: '', ownerUuid: '' };
88 })(renderWorkflowName);
90 const getPublicUuid = (uuidPrefix: string) => {
91 return `${uuidPrefix}-tpzed-anonymouspublic`;
94 const resourceShare = (dispatch: Dispatch, uuidPrefix: string, ownerUuid?: string, uuid?: string) => {
95 const isPublic = ownerUuid === getPublicUuid(uuidPrefix);
99 <Tooltip title="Share">
100 <IconButton onClick={() => dispatch<any>(openSharingDialog(uuid))}>
109 export const ResourceShare = connect(
110 (state: RootState, props: { uuid: string }) => {
111 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
112 const uuidPrefix = getUuidPrefix(state);
114 uuid: resource ? resource.uuid : '',
115 ownerUuid: resource ? resource.ownerUuid : '',
118 })((props: { ownerUuid?: string, uuidPrefix: string, uuid?: string } & DispatchProp<any>) =>
119 resourceShare(props.dispatch, props.uuidPrefix, props.ownerUuid, props.uuid));
121 const renderFirstName = (item: { firstName: string }) => {
122 return <Typography noWrap>{item.firstName}</Typography>;
126 export const ResourceFirstName = connect(
127 (state: RootState, props: { uuid: string }) => {
128 const resource = getResource<UserResource>(props.uuid)(state.resources);
129 return resource || { firstName: '' };
132 const renderLastName = (item: { lastName: string }) =>
133 <Typography noWrap>{item.lastName}</Typography>;
135 export const ResourceLastName = connect(
136 (state: RootState, props: { uuid: string }) => {
137 const resource = getResource<UserResource>(props.uuid)(state.resources);
138 return resource || { lastName: '' };
141 const renderUuid = (item: { uuid: string }) =>
142 <Typography noWrap>{item.uuid}</Typography>;
144 export const ResourceUuid = connect(
145 (state: RootState, props: { uuid: string }) => {
146 const resource = getResource<UserResource>(props.uuid)(state.resources);
147 return resource || { uuid: '' };
150 const renderEmail = (item: { email: string }) =>
151 <Typography noWrap>{item.email}</Typography>;
153 export const ResourceEmail = connect(
154 (state: RootState, props: { uuid: string }) => {
155 const resource = getResource<UserResource>(props.uuid)(state.resources);
156 return resource || { email: '' };
159 const renderIsActive = (props: { uuid: string, isActive: boolean, toggleIsActive: (uuid: string) => void }) =>
162 checked={props.isActive}
163 onClick={() => props.toggleIsActive(props.uuid)} />;
165 export const ResourceIsActive = connect(
166 (state: RootState, props: { uuid: string }) => {
167 const resource = getResource<UserResource>(props.uuid)(state.resources);
168 return resource || { isActive: false };
169 }, { toggleIsActive }
172 const renderIsAdmin = (props: { uuid: string, isAdmin: boolean, toggleIsAdmin: (uuid: string) => void }) =>
175 checked={props.isAdmin}
176 onClick={() => props.toggleIsAdmin(props.uuid)} />;
178 export const ResourceIsAdmin = connect(
179 (state: RootState, props: { uuid: string }) => {
180 const resource = getResource<UserResource>(props.uuid)(state.resources);
181 return resource || { isAdmin: false };
185 const renderUsername = (item: { username: string }) =>
186 <Typography noWrap>{item.username}</Typography>;
188 export const ResourceUsername = connect(
189 (state: RootState, props: { uuid: string }) => {
190 const resource = getResource<UserResource>(props.uuid)(state.resources);
191 return resource || { username: '' };
195 const renderCommonData = (data: string) =>
196 <Typography noWrap>{data}</Typography>;
198 const renderCommonDate = (date: string) =>
199 <Typography noWrap>{formatDate(date)}</Typography>;
201 export const CommonUuid = withResourceData('uuid', renderCommonData);
203 // Api Client Authorizations
204 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
206 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
208 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
210 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
212 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
214 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
216 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
218 export const TokenScopes = withResourceData('scopes', renderCommonData);
220 export const TokenUserId = withResourceData('userId', renderCommonData);
222 // Compute Node Resources
223 const renderNodeInfo = (data: string) => {
224 return <Typography>{JSON.stringify(data, null, 4)}</Typography>;
227 const clusterColors = [
235 export const ResourceCluster = (props: { uuid: string }) => {
236 const CLUSTER_ID_LENGTH = 5;
237 const pos = props.uuid.indexOf('-');
238 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
239 const ci = pos >= CLUSTER_ID_LENGTH ? (props.uuid.charCodeAt(0) + props.uuid.charCodeAt(1)) % clusterColors.length : 0;
242 backgroundColor: clusterColors[ci][0],
243 color: clusterColors[ci][1],
250 export const ComputeNodeInfo = withResourceData('info', renderNodeInfo);
252 export const ComputeNodeDomain = withResourceData('domain', renderCommonData);
254 export const ComputeNodeFirstPingAt = withResourceData('firstPingAt', renderCommonDate);
256 export const ComputeNodeHostname = withResourceData('hostname', renderCommonData);
258 export const ComputeNodeIpAddress = withResourceData('ipAddress', renderCommonData);
260 export const ComputeNodeJobUuid = withResourceData('jobUuid', renderCommonData);
262 export const ComputeNodeLastPingAt = withResourceData('lastPingAt', renderCommonDate);
265 const renderLinkName = (item: { name: string }) =>
266 <Typography noWrap>{item.name || '(none)'}</Typography>;
268 export const ResourceLinkName = connect(
269 (state: RootState, props: { uuid: string }) => {
270 const resource = getResource<LinkResource>(props.uuid)(state.resources);
271 return resource || { name: '' };
274 const renderLinkClass = (item: { linkClass: string }) =>
275 <Typography noWrap>{item.linkClass}</Typography>;
277 export const ResourceLinkClass = connect(
278 (state: RootState, props: { uuid: string }) => {
279 const resource = getResource<LinkResource>(props.uuid)(state.resources);
280 return resource || { linkClass: '' };
283 const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
284 const currentLabel = resourceLabel(item.tailKind);
285 const isUnknow = currentLabel === "Unknown";
288 renderLink(dispatch, item.tailUuid, currentLabel)
290 <Typography noWrap color="default">
297 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
298 <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
302 export const ResourceLinkTail = connect(
303 (state: RootState, props: { uuid: string }) => {
304 const resource = getResource<LinkResource>(props.uuid)(state.resources);
306 item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
308 })((props: { item: any } & DispatchProp<any>) =>
309 renderLinkTail(props.dispatch, props.item));
311 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
312 renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
314 export const ResourceLinkHead = connect(
315 (state: RootState, props: { uuid: string }) => {
316 const resource = getResource<LinkResource>(props.uuid)(state.resources);
318 item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
320 })((props: { item: any } & DispatchProp<any>) =>
321 renderLinkHead(props.dispatch, props.item));
323 export const ResourceLinkUuid = connect(
324 (state: RootState, props: { uuid: string }) => {
325 const resource = getResource<LinkResource>(props.uuid)(state.resources);
326 return resource || { uuid: '' };
330 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
334 <Tooltip title="Run process">
335 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
343 export const ResourceRunProcess = connect(
344 (state: RootState, props: { uuid: string }) => {
345 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
347 uuid: resource ? resource.uuid : ''
349 })((props: { uuid: string } & DispatchProp<any>) =>
350 resourceRunProcess(props.dispatch, props.uuid));
352 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
353 if (ownerUuid === getPublicUuid(uuidPrefix)) {
354 return renderStatus(ResourceStatus.PUBLIC);
356 return renderStatus(ResourceStatus.PRIVATE);
360 const renderStatus = (status: string) =>
361 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
363 export const ResourceWorkflowStatus = connect(
364 (state: RootState, props: { uuid: string }) => {
365 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
366 const uuidPrefix = getUuidPrefix(state);
368 ownerUuid: resource ? resource.ownerUuid : '',
371 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
373 export const ResourceLastModifiedDate = connect(
374 (state: RootState, props: { uuid: string }) => {
375 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
376 return { date: resource ? resource.modifiedAt : '' };
377 })((props: { date: string }) => renderDate(props.date));
379 export const ResourceTrashDate = connect(
380 (state: RootState, props: { uuid: string }) => {
381 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
382 return { date: resource ? resource.trashAt : '' };
383 })((props: { date: string }) => renderDate(props.date));
385 export const ResourceDeleteDate = connect(
386 (state: RootState, props: { uuid: string }) => {
387 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
388 return { date: resource ? resource.deleteAt : '' };
389 })((props: { date: string }) => renderDate(props.date));
391 export const renderFileSize = (fileSize?: number) =>
392 <Typography noWrap style={{ minWidth: '45px' }}>
393 {formatFileSize(fileSize)}
396 export const ResourceFileSize = connect(
397 (state: RootState, props: { uuid: string }) => {
398 const resource = getResourceData(props.uuid)(state.resourcesData);
399 return { fileSize: resource ? resource.fileSize : 0 };
400 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
402 const renderOwner = (owner: string) =>
403 <Typography noWrap color="primary" >
407 export const ResourceOwner = connect(
408 (state: RootState, props: { uuid: string }) => {
409 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
410 return { owner: resource ? resource.ownerUuid : '' };
411 })((props: { owner: string }) => renderOwner(props.owner));
413 const renderType = (type: string) =>
415 {resourceLabel(type)}
418 export const ResourceType = connect(
419 (state: RootState, props: { uuid: string }) => {
420 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
421 return { type: resource ? resource.kind : '' };
422 })((props: { type: string }) => renderType(props.type));
424 export const ProcessStatus = compose(
425 connect((state: RootState, props: { uuid: string }) => {
426 return { process: getProcess(props.uuid)(state.resources) };
428 withStyles({}, { withTheme: true }))
429 ((props: { process?: Process, theme: ArvadosTheme }) => {
430 const status = props.process ? getProcessStatus(props.process) : "-";
434 style={{ color: getProcessStatusColor(status, props.theme) }} >