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, PublicFavoriteStar } 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 { extractUuidKind } from '~/models/resource';
31 const renderName = (item: { name: string; uuid: string, kind: string }) =>
32 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
34 {renderIcon(item.kind)}
37 <Typography color="primary" style={{ width: 'auto' }}>
42 <Typography variant="caption">
43 <FavoriteStar resourceUuid={item.uuid} />
44 <PublicFavoriteStar 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 = (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}>
77 {renderIcon(item.kind)}
80 <Typography color="primary" style={{ width: '100px' }}>
86 export const ResourceWorkflowName = 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: '' };
197 const renderCommonData = (data: string) =>
198 <Typography noWrap>{data}</Typography>;
200 const renderCommonDate = (date: string) =>
201 <Typography noWrap>{formatDate(date)}</Typography>;
203 export const CommonUuid = withResourceData('uuid', renderCommonData);
205 // Api Client Authorizations
206 export const TokenApiClientId = withResourceData('apiClientId', renderCommonData);
208 export const TokenApiToken = withResourceData('apiToken', renderCommonData);
210 export const TokenCreatedByIpAddress = withResourceData('createdByIpAddress', renderCommonDate);
212 export const TokenDefaultOwnerUuid = withResourceData('defaultOwnerUuid', renderCommonData);
214 export const TokenExpiresAt = withResourceData('expiresAt', renderCommonDate);
216 export const TokenLastUsedAt = withResourceData('lastUsedAt', renderCommonDate);
218 export const TokenLastUsedByIpAddress = withResourceData('lastUsedByIpAddress', renderCommonData);
220 export const TokenScopes = withResourceData('scopes', renderCommonData);
222 export const TokenUserId = withResourceData('userId', renderCommonData);
224 // Compute Node Resources
225 const renderNodeInfo = (data: string) => {
226 return <Typography>{JSON.stringify(data, null, 4)}</Typography>;
229 const clusterColors = [
237 export const ResourceCluster = (props: { uuid: string }) => {
238 const CLUSTER_ID_LENGTH = 5;
239 const pos = props.uuid.indexOf('-');
240 const clusterId = pos >= CLUSTER_ID_LENGTH ? props.uuid.substr(0, pos) : '';
241 const ci = pos >= CLUSTER_ID_LENGTH ? (props.uuid.charCodeAt(0) + props.uuid.charCodeAt(1)) % clusterColors.length : 0;
244 backgroundColor: clusterColors[ci][0],
245 color: clusterColors[ci][1],
252 export const ComputeNodeInfo = withResourceData('info', renderNodeInfo);
254 export const ComputeNodeDomain = withResourceData('domain', renderCommonData);
256 export const ComputeNodeFirstPingAt = withResourceData('firstPingAt', renderCommonDate);
258 export const ComputeNodeHostname = withResourceData('hostname', renderCommonData);
260 export const ComputeNodeIpAddress = withResourceData('ipAddress', renderCommonData);
262 export const ComputeNodeJobUuid = withResourceData('jobUuid', renderCommonData);
264 export const ComputeNodeLastPingAt = withResourceData('lastPingAt', renderCommonDate);
267 const renderLinkName = (item: { name: string }) =>
268 <Typography noWrap>{item.name || '(none)'}</Typography>;
270 export const ResourceLinkName = connect(
271 (state: RootState, props: { uuid: string }) => {
272 const resource = getResource<LinkResource>(props.uuid)(state.resources);
273 return resource || { name: '' };
276 const renderLinkClass = (item: { linkClass: string }) =>
277 <Typography noWrap>{item.linkClass}</Typography>;
279 export const ResourceLinkClass = connect(
280 (state: RootState, props: { uuid: string }) => {
281 const resource = getResource<LinkResource>(props.uuid)(state.resources);
282 return resource || { linkClass: '' };
285 const renderLinkTail = (dispatch: Dispatch, item: { uuid: string, tailUuid: string, tailKind: string }) => {
286 const currentLabel = resourceLabel(item.tailKind);
287 const isUnknow = currentLabel === "Unknown";
290 renderLink(dispatch, item.tailUuid, currentLabel)
292 <Typography noWrap color="default">
299 const renderLink = (dispatch: Dispatch, uuid: string, label: string) =>
300 <Typography noWrap color="primary" style={{ 'cursor': 'pointer' }} onClick={() => dispatch<any>(navigateTo(uuid))}>
304 export const ResourceLinkTail = connect(
305 (state: RootState, props: { uuid: string }) => {
306 const resource = getResource<LinkResource>(props.uuid)(state.resources);
308 item: resource || { uuid: '', tailUuid: '', tailKind: ResourceKind.NONE }
310 })((props: { item: any } & DispatchProp<any>) =>
311 renderLinkTail(props.dispatch, props.item));
313 const renderLinkHead = (dispatch: Dispatch, item: { uuid: string, headUuid: string, headKind: ResourceKind }) =>
314 renderLink(dispatch, item.headUuid, resourceLabel(item.headKind));
316 export const ResourceLinkHead = connect(
317 (state: RootState, props: { uuid: string }) => {
318 const resource = getResource<LinkResource>(props.uuid)(state.resources);
320 item: resource || { uuid: '', headUuid: '', headKind: ResourceKind.NONE }
322 })((props: { item: any } & DispatchProp<any>) =>
323 renderLinkHead(props.dispatch, props.item));
325 export const ResourceLinkUuid = connect(
326 (state: RootState, props: { uuid: string }) => {
327 const resource = getResource<LinkResource>(props.uuid)(state.resources);
328 return resource || { uuid: '' };
332 const resourceRunProcess = (dispatch: Dispatch, uuid: string) => {
336 <Tooltip title="Run process">
337 <IconButton onClick={() => dispatch<any>(openRunProcess(uuid))}>
345 export const ResourceRunProcess = connect(
346 (state: RootState, props: { uuid: string }) => {
347 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
349 uuid: resource ? resource.uuid : ''
351 })((props: { uuid: string } & DispatchProp<any>) =>
352 resourceRunProcess(props.dispatch, props.uuid));
354 const renderWorkflowStatus = (uuidPrefix: string, ownerUuid?: string) => {
355 if (ownerUuid === getPublicUuid(uuidPrefix)) {
356 return renderStatus(ResourceStatus.PUBLIC);
358 return renderStatus(ResourceStatus.PRIVATE);
362 const renderStatus = (status: string) =>
363 <Typography noWrap style={{ width: '60px' }}>{status}</Typography>;
365 export const ResourceWorkflowStatus = connect(
366 (state: RootState, props: { uuid: string }) => {
367 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
368 const uuidPrefix = getUuidPrefix(state);
370 ownerUuid: resource ? resource.ownerUuid : '',
373 })((props: { ownerUuid?: string, uuidPrefix: string }) => renderWorkflowStatus(props.uuidPrefix, props.ownerUuid));
375 export const ResourceLastModifiedDate = connect(
376 (state: RootState, props: { uuid: string }) => {
377 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
378 return { date: resource ? resource.modifiedAt : '' };
379 })((props: { date: string }) => renderDate(props.date));
381 export const ResourceTrashDate = connect(
382 (state: RootState, props: { uuid: string }) => {
383 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
384 return { date: resource ? resource.trashAt : '' };
385 })((props: { date: string }) => renderDate(props.date));
387 export const ResourceDeleteDate = connect(
388 (state: RootState, props: { uuid: string }) => {
389 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
390 return { date: resource ? resource.deleteAt : '' };
391 })((props: { date: string }) => renderDate(props.date));
393 export const renderFileSize = (fileSize?: number) =>
394 <Typography noWrap style={{ minWidth: '45px' }}>
395 {formatFileSize(fileSize)}
398 export const ResourceFileSize = connect(
399 (state: RootState, props: { uuid: string }) => {
400 const resource = getResourceData(props.uuid)(state.resourcesData);
401 return { fileSize: resource ? resource.fileSize : 0 };
402 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
404 const renderOwner = (owner: string) =>
405 <Typography noWrap color="primary" >
409 export const ResourceOwner = connect(
410 (state: RootState, props: { uuid: string }) => {
411 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
412 return { owner: resource ? resource.ownerUuid : '' };
413 })((props: { owner: string }) => renderOwner(props.owner));
415 const renderType = (type: string) =>
417 {resourceLabel(type)}
420 export const ResourceType = connect(
421 (state: RootState, props: { uuid: string }) => {
422 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
423 return { type: resource ? resource.kind : '' };
424 })((props: { type: string }) => renderType(props.type));
426 export const ProcessStatus = compose(
427 connect((state: RootState, props: { uuid: string }) => {
428 return { process: getProcess(props.uuid)(state.resources) };
430 withStyles({}, { withTheme: true }))
431 ((props: { process?: Process, theme: ArvadosTheme }) => {
432 const status = props.process ? getProcessStatus(props.process) : "-";
436 style={{ color: getProcessStatusColor(status, props.theme) }} >