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 } 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 />;
52 return <DefaultIcon />;
56 export const renderDate = (date?: string) => {
57 return <Typography noWrap style={{ minWidth: '100px' }}>{formatDate(date)}</Typography>;
60 export const ResourceLastModifiedDate = connect(
61 (state: RootState, props: { uuid: string }) => {
62 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
63 return { date: resource ? resource.modifiedAt : '' };
64 })((props: { date: string }) => renderDate(props.date));
66 export const ResourceTrashDate = connect(
67 (state: RootState, props: { uuid: string }) => {
68 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
69 return { date: resource ? resource.trashAt : '' };
70 })((props: { date: string }) => renderDate(props.date));
72 export const ResourceDeleteDate = connect(
73 (state: RootState, props: { uuid: string }) => {
74 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
75 return { date: resource ? resource.deleteAt : '' };
76 })((props: { date: string }) => renderDate(props.date));
78 export const renderFileSize = (fileSize?: number) =>
79 <Typography noWrap style={{ minWidth: '45px' }}>
80 {formatFileSize(fileSize)}
83 export const ResourceFileSize = connect(
84 (state: RootState, props: { uuid: string }) => {
85 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
87 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
89 export const renderOwner = (owner: string) =>
90 <Typography noWrap color="primary" >
94 export const ResourceOwner = connect(
95 (state: RootState, props: { uuid: string }) => {
96 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
97 return { owner: resource ? resource.ownerUuid : '' };
98 })((props: { owner: string }) => renderOwner(props.owner));
100 export const renderType = (type: string) =>
102 {resourceLabel(type)}
105 export const ResourceType = connect(
106 (state: RootState, props: { uuid: string }) => {
107 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
108 return { type: resource ? resource.kind : '' };
109 })((props: { type: string }) => renderType(props.type));
111 export const ProcessStatus = compose(
112 connect((state: RootState, props: { uuid: string }) => {
113 return { process: getProcess(props.uuid)(state.resources) };
115 withStyles({}, { withTheme: true }))
116 ((props: { process?: Process, theme: ArvadosTheme }) => {
117 const status = props.process ? getProcessStatus(props.process) : "-";
121 style={{ color: getProcessStatusColor(status, props.theme) }} >