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, 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 { 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<GroupContentsResource>(props.uuid)(state.resources);
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<GroupContentsResource>(props.uuid)(state.resources);
62 return { date: resource ? resource.modifiedAt : '' };
63 })((props: { date: string }) => renderDate(props.date));
65 export const ResourceTrashDate = connect(
66 (state: RootState, props: { uuid: string }) => {
67 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
68 return { date: resource ? resource.trashAt : '' };
69 })((props: { date: string }) => renderDate(props.date));
71 export const ResourceDeleteDate = connect(
72 (state: RootState, props: { uuid: string }) => {
73 const resource = getResource<TrashableResource>(props.uuid)(state.resources);
74 return { date: resource ? resource.deleteAt : '' };
75 })((props: { date: string }) => renderDate(props.date));
77 export const renderFileSize = (fileSize?: number) =>
79 {formatFileSize(fileSize)}
82 export const ResourceFileSize = connect(
83 (state: RootState, props: { uuid: string }) => {
84 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
86 })((props: { fileSize?: number }) => renderFileSize(props.fileSize));
88 export const renderOwner = (owner: string) =>
89 <Typography noWrap color="primary" >
93 export const ResourceOwner = connect(
94 (state: RootState, props: { uuid: string }) => {
95 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
96 return { owner: resource ? resource.ownerUuid : '' };
97 })((props: { owner: string }) => renderOwner(props.owner));
99 export const renderType = (type: string) =>
101 {resourceLabel(type)}
104 export const ResourceType = connect(
105 (state: RootState, props: { uuid: string }) => {
106 const resource = getResource<GroupContentsResource>(props.uuid)(state.resources);
107 return { type: resource ? resource.kind : '' };
108 })((props: { type: string }) => renderType(props.type));
110 export const renderStatus = (item: { status?: string }) =>
111 <Typography noWrap align="center" >
115 export const ProcessStatus = connect(
116 (state: RootState, props: { uuid: string }) => {
117 const resource = getResource<ProcessResource>(props.uuid)(state.resources);
118 return { status: resource ? resource.state : '-' };
119 })((props: { status: string }) => renderType(props.status));