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 } from '@material-ui/core';
7 import { FavoriteStar } from '../favorite-star/favorite-star';
8 import { ResourceKind } 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 { ProcessResource } from '~/models/process';
19 export const renderName = (item: { name: string; uuid: string, kind: string }) =>
20 <Grid container alignItems="center" wrap="nowrap" spacing={16}>
25 <Typography color="primary">
30 <Typography variant="caption">
31 <FavoriteStar resourceUuid={item.uuid} />
36 export const ResourceName = connect(
37 (state: RootState, props: { uuid: string }) => {
38 const resource = getResource(props.uuid)(state.resources) as GroupContentsResource | undefined;
39 return resource || { name: '', uuid: '', kind: '' };
42 export const renderIcon = (item: { kind: string }) => {
44 case ResourceKind.PROJECT:
45 return <ProjectIcon />;
46 case ResourceKind.COLLECTION:
47 return <CollectionIcon />;
48 case ResourceKind.PROCESS:
49 return <ProcessIcon />;
51 return <DefaultIcon />;
55 export const renderDate = (date: string) => {
56 return <Typography noWrap>{formatDate(date)}</Typography>;
59 export const ResourceLastModifiedDate = connect(
60 (state: RootState, props: { uuid: string }) => {
61 const resource = getResource(props.uuid)(state.resources) as GroupContentsResource | undefined;
62 return { date: resource ? resource.modifiedAt : '' };
63 })((props: { date: string }) => renderDate(props.date));
65 export const renderFileSize = (fileSize?: number) =>
67 {formatFileSize(fileSize)}
70 export const ResourceFileSize = connect(
71 (state: RootState, props: { uuid: string }) => {
72 const resource = getResource(props.uuid)(state.resources) as GroupContentsResource | undefined;
74 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
76 export const renderOwner = (owner: string) =>
77 <Typography noWrap color="primary" >
81 export const ResourceOwner = connect(
82 (state: RootState, props: { uuid: string }) => {
83 const resource = getResource(props.uuid)(state.resources) as GroupContentsResource | undefined;
84 return { owner: resource ? resource.ownerUuid : '' };
85 })((props: { owner: string }) => renderOwner(props.owner));
87 export const renderType = (type: string) =>
92 export const ResourceType = connect(
93 (state: RootState, props: { uuid: string }) => {
94 const resource = getResource(props.uuid)(state.resources) as GroupContentsResource | undefined;
95 return { type: resource ? resource.kind : '' };
96 })((props: { type: string }) => renderType(props.type));
98 export const renderStatus = (item: { status?: string }) =>
99 <Typography noWrap align="center" >
103 export const ProcessStatus = connect(
104 (state: RootState, props: { uuid: string }) => {
105 const resource = getResource(props.uuid)(state.resources) as ProcessResource | undefined;
106 return { status: resource ? resource.state : '-' };
107 })((props: { status: string }) => renderType(props.status));