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 } 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 } from '~/components/icon/icon';
10 import { formatDate, formatFileSize } from '~/common/formatters';
11 import { resourceLabel } from '~/common/labels';
12 import { connect } 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 } from 'redux';
19 import { WorkflowResource } from '~/models/workflow';
20 import { ResourceStatus } from '~/views/workflow-panel/workflow-panel';
22 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
23 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
28 <Typography color="primary" style={{ width: '450px' }}>
33 <Typography variant="caption">
34 <FavoriteStar resourceUuid={item.uuid} />
39 export const ResourceName = connect(
40 (state: RootState, props: { uuid: string }) => {
41 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
42 return resource || { name: '', uuid: '', kind: '' };
45 export const renderIcon = (item: { kind: string }) => {
47 case ResourceKind.PROJECT:
48 return <ProjectIcon />;
49 case ResourceKind.COLLECTION:
50 return <CollectionIcon />;
51 case ResourceKind.PROCESS:
52 return <ProcessIcon />;
53 case ResourceKind.WORKFLOW:
54 return <WorkflowIcon />;
56 return <DefaultIcon />;
60 export const renderWorkflowName = (item: { name: string; uuid: string, kind: string }) =>
61 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
66 <Typography color="primary" style={{ width: '100px' }}>
72 export const RosurceWorkflowName = connect(
73 (state: RootState, props: { uuid: string }) => {
74 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
75 return resource || { name: '', uuid: '', kind: '' };
76 })(renderWorkflowName);
78 export const renderDate = (date?: string) => {
79 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
82 export const renderWorkflowStatus = (ownerUuid?: string) => {
83 if (ownerUuid === 'qr1hi-j7d0g-2ax8o1pscovq2lg') {
84 return <Typography noWrap style={{ width: '60px' }}>{ResourceStatus.PUBLIC}</Typography>;
86 return <Typography noWrap style={{ width: '60px' }}>{ResourceStatus.PRIVATE}</Typography>;
90 export const ResourceWorkflowStatus = connect(
91 (state: RootState, props: { uuid: string }) => {
92 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
93 return { ownerUuid: resource ? resource.ownerUuid : '' };
94 })((props: { ownerUuid?: string }) => renderWorkflowStatus(props.ownerUuid));
96 export const ResourceLastModifiedDate = connect(
97 (state: RootState, props: { uuid: string }) => {
98 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
99 return { date: resource ? resource.modifiedAt : '' };
100 })((props: { date: string }) => renderDate(props.date));
102 export const ResourceTrashDate = connect(
103 (state: RootState, props: { uuid: string }) => {
104 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
105 return { date: resource ? resource.trashAt : '' };
106 })((props: { date: string }) => renderDate(props.date));
108 export const ResourceDeleteDate = connect(
109 (state: RootState, props: { uuid: string }) => {
110 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
111 return { date: resource ? resource.deleteAt : '' };
112 })((props: { date: string }) => renderDate(props.date));
114 export const renderFileSize = (fileSize?: number) =>
115 <Typography noWrap style={{ minWidth: '45px' }}>
116 {formatFileSize(fileSize)}
119 export const ResourceFileSize = connect(
120 (state: RootState, props: { uuid: string }) => {
121 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
123 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
125 export const renderOwner = (owner: string) =>
126 <Typography noWrap color="primary" >
130 export const ResourceOwner = connect(
131 (state: RootState, props: { uuid: string }) => {
132 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
133 return { owner: resource ? resource.ownerUuid : '' };
134 })((props: { owner: string }) => renderOwner(props.owner));
136 export const renderType = (type: string) =>
138 {resourceLabel(type)}
141 export const ResourceType = connect(
142 (state: RootState, props: { uuid: string }) => {
143 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
144 return { type: resource ? resource.kind : '' };
145 })((props: { type: string }) => renderType(props.type));
147 export const ProcessStatus = compose(
148 connect((state: RootState, props: { uuid: string }) => {
149 return { process: getProcess(props.uuid)(state.resources) };
151 withStyles({}, { withTheme: true }))
152 ((props: { process?: Process, theme: ArvadosTheme }) => {
153 const status = props.process ? getProcessStatus(props.process) : "-";
157 style={{ color: getProcessStatusColor(status, props.theme) }} >