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';
20 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
21 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
26 <Typography color="primary" style={{ width: '450px' }}>
31 <Typography variant="caption">
32 <FavoriteStar resourceUuid={item.uuid} />
37 export const ResourceName = connect(
38 (state: RootState, props: { uuid: string }) => {
39 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
40 return resource || { name: '', uuid: '', kind: '' };
43 export const renderIcon = (item: { kind: string }) => {
45 case ResourceKind.PROJECT:
46 return <ProjectIcon />;
47 case ResourceKind.COLLECTION:
48 return <CollectionIcon />;
49 case ResourceKind.PROCESS:
50 return <ProcessIcon />;
51 case ResourceKind.WORKFLOW:
52 return <WorkflowIcon />;
54 return <DefaultIcon />;
58 export const renderDate = (date?: string) => {
59 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
62 export const ResourceLastModifiedDate = connect(
63 (state: RootState, props: { uuid: string }) => {
64 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
65 return { date: resource ? resource.modifiedAt : '' };
66 })((props: { date: string }) => renderDate(props.date));
68 export const ResourceTrashDate = connect(
69 (state: RootState, props: { uuid: string }) => {
70 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
71 return { date: resource ? resource.trashAt : '' };
72 })((props: { date: string }) => renderDate(props.date));
74 export const ResourceDeleteDate = connect(
75 (state: RootState, props: { uuid: string }) => {
76 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
77 return { date: resource ? resource.deleteAt : '' };
78 })((props: { date: string }) => renderDate(props.date));
80 export const renderFileSize = (fileSize?: number) =>
81 <Typography noWrap style={{ minWidth: '45px' }}>
82 {formatFileSize(fileSize)}
85 export const ResourceFileSize = connect(
86 (state: RootState, props: { uuid: string }) => {
87 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
89 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
91 export const renderOwner = (owner: string) =>
92 <Typography noWrap color="primary" >
96 export const ResourceOwner = connect(
97 (state: RootState, props: { uuid: string }) => {
98 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
99 return { owner: resource ? resource.ownerUuid : '' };
100 })((props: { owner: string }) => renderOwner(props.owner));
102 export const renderType = (type: string) =>
104 {resourceLabel(type)}
107 export const ResourceType = connect(
108 (state: RootState, props: { uuid: string }) => {
109 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
110 return { type: resource ? resource.kind : '' };
111 })((props: { type: string }) => renderType(props.type));
113 export const ProcessStatus = compose(
114 connect((state: RootState, props: { uuid: string }) => {
115 return { process: getProcess(props.uuid)(state.resources) };
117 withStyles({}, { withTheme: true }))
118 ((props: { process?: Process, theme: ArvadosTheme }) => {
119 const status = props.process ? getProcessStatus(props.process) : "-";
123 style={{ color: getProcessStatusColor(status, props.theme) }} >