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';
21 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
22 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
27 <Typography color="primary" style={{ width: '450px' }}>
32 <Typography variant="caption">
33 <FavoriteStar resourceUuid={item.uuid} />
38 export const ResourceName = connect(
39 (state: RootState, props: { uuid: string }) => {
40 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
41 return resource || { name: '', uuid: '', kind: '' };
44 export const renderIcon = (item: { kind: string }) => {
46 case ResourceKind.PROJECT:
47 return <ProjectIcon />;
48 case ResourceKind.COLLECTION:
49 return <CollectionIcon />;
50 case ResourceKind.PROCESS:
51 return <ProcessIcon />;
52 case ResourceKind.WORKFLOW:
53 return <WorkflowIcon />;
55 return <DefaultIcon />;
59 export const renderWorkflowName = (item: { name: string; uuid: string, kind: string }) =>
60 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
65 <Typography color="primary" style={{ width: '100px' }}>
71 export const RosurceWorkflowName = connect(
72 (state: RootState, props: { uuid: string }) => {
73 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
74 return resource || { name: '', uuid: '', kind: '' };
75 })(renderWorkflowName);
77 export const renderDate = (date?: string) => {
78 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
81 export const renderWorkflowStatus = () => {
82 return <Typography noWrap style={{ width: '60px' }}>{"Public"}</Typography>;
85 export const ResourceWorkflowStatus = connect(
86 (state: RootState, props: { uuid: string }) => {
87 const resource = getResource<WorkflowResource>(props.uuid)(state.resources);
89 })((props: { status?: string }) => renderWorkflowStatus());
91 export const ResourceLastModifiedDate = connect(
92 (state: RootState, props: { uuid: string }) => {
93 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
94 return { date: resource ? resource.modifiedAt : '' };
95 })((props: { date: string }) => renderDate(props.date));
97 export const ResourceTrashDate = connect(
98 (state: RootState, props: { uuid: string }) => {
99 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
100 return { date: resource ? resource.trashAt : '' };
101 })((props: { date: string }) => renderDate(props.date));
103 export const ResourceDeleteDate = connect(
104 (state: RootState, props: { uuid: string }) => {
105 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
106 return { date: resource ? resource.deleteAt : '' };
107 })((props: { date: string }) => renderDate(props.date));
109 export const renderFileSize = (fileSize?: number) =>
110 <Typography noWrap style={{ minWidth: '45px' }}>
111 {formatFileSize(fileSize)}
114 export const ResourceFileSize = connect(
115 (state: RootState, props: { uuid: string }) => {
116 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
118 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
120 export const renderOwner = (owner: string) =>
121 <Typography noWrap color="primary" >
125 export const ResourceOwner = connect(
126 (state: RootState, props: { uuid: string }) => {
127 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
128 return { owner: resource ? resource.ownerUuid : '' };
129 })((props: { owner: string }) => renderOwner(props.owner));
131 export const renderType = (type: string) =>
133 {resourceLabel(type)}
136 export const ResourceType = connect(
137 (state: RootState, props: { uuid: string }) => {
138 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
139 return { type: resource ? resource.kind : '' };
140 })((props: { type: string }) => renderType(props.type));
142 export const ProcessStatus = compose(
143 connect((state: RootState, props: { uuid: string }) => {
144 return { process: getProcess(props.uuid)(state.resources) };
146 withStyles({}, { withTheme: true }))
147 ((props: { process?: Process, theme: ArvadosTheme }) => {
148 const status = props.process ? getProcessStatus(props.process) : "-";
152 style={{ color: getProcessStatusColor(status, props.theme) }} >